-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Rename refactoring #9636
Conversation
}); | ||
applyWorkspaceEditAction.applyWorkspaceEdit(edit); | ||
view.close(); | ||
refactoringActionDelegate.closeWizard(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It invokes onCancelButtonClicked();
I think view.close()
is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
view.close()
closes just Preview window, but also we need to close the other one (Rename or Move) window which was opened previously
final JavaLanguageExtensionServiceClient service) { | ||
eventBus.addHandler( | ||
EditorOpenedEvent.TYPE, | ||
new EditorOpenedEventHandler() { | ||
@Override | ||
public void onEditorOpened(EditorOpenedEvent event) { | ||
String uri = buildHelper.getUri(event.getFile()); | ||
if (uri.endsWith(POM_FILE)) { | ||
if (!uri.endsWith(POM_FILE)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive-by fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's right
if (!arg.isPresent()) { | ||
return; | ||
} | ||
File existedFile = arg.get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"existingFile"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
} | ||
PreviewNode node = nodes.get(selectedNode.getUri()); | ||
List<TextEdit> edits = new ArrayList<>(); | ||
if (node.getId().equals(selectedNode.getId())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure what we are doing here. Refactor so it's obvious or add comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored and added some comments
|
||
private RefactorInfo refactorInfo; | ||
private RefactoringSession session; | ||
private Map<String, PreviewNode> nodes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all nodes in this map? If not, this needs a different name. fileNodes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to fileNodes
this.refactoringActionDelegate = refactoringActionDelegate; | ||
nodes = new LinkedHashMap<>(); | ||
|
||
prepareNodes(workspaceEdit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I see it, prepareNodes just fills in the nodes map. why not do
nodes= prepareNodes(workspaceEdit);
If you make prepareNodes static, you can show that there are no side-effects in the method. Making stuff side-effect free simplifies understanding the code.
} | ||
undoChanges(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you clarify please?
If you're thinking about why I undo changes here. It is because before applying all TextEdit changes we need to have initial state of the content where linked mode was activated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that's what I was thinking of.
edit.setChanges(workspaceEdit.getChanges()); | ||
edit.setResourceChanges(new LinkedList<>()); | ||
for (ResourceChange resourceChange : workspaceEdit.getResourceChanges()) { | ||
edit.getResourceChanges().add(Either.forLeft(resourceChange)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity...I thought sending WorkspaceChange over the wire did not work? What has changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sending List<Either<ResourceChange, TextEdit>>
which is described in org.eclipse.lsp4j.WorkspaceEdit
doesn't work.
So here workspaceEdit
is an instance of custom object (org.eclipse.che.jdt.ls.extension.api.dto.CheWorkspaceEdit
) where I already have all actual changes and I take all changes from it and put them to the edit
(org.eclipse.lsp4j.WorkspaceEdit
) to sent it to class which applies org.eclipse.lsp4j.WorkspaceEdit
(org.eclipse.che.plugin.languageserver.ide.editor.quickassist.ApplyWorkspaceEditAction#ApplyWorkspaceEditAction
)
String newUri = change.getNewUri(); | ||
String current = change.getCurrent(); | ||
|
||
Path path = toPath(newUri).removeFirstSegments(1).makeAbsolute(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Transformation of file uri's to paths is usually done in WSMaster, so results from lsp servers contain either workspace paths of non-file URI's. See LanguageServiceUtils.removePrefixURI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GWT doesn't support java.net.* so we can't use LanguageServiceUtils.java
on the client. I've created utility class org.eclipse.che.api.languageserver.util.URIUtil
which transforms uri to path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not what I mean, I've tried to explain in chat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
.getResource(path) | ||
.then( | ||
resource -> { | ||
if (isNullOrEmpty(path.getFileExtension())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont' think this is a valid condition. It's perfectly valid to create files without extensions and folders with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but I don't see another way to recognize which type of resource is here. Is it a folder or is a file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to fix this in CheWorkspaceEdit (make CheResourceChange.java) and have a "resourceType" enum to be used on create.
resource | ||
.move(path) | ||
.then( | ||
arg -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arg is not a good name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed
6901019
to
518f5f6
Compare
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
What does this PR do?
Make it possible to do Rename operation by using jdt.ls.
The result of this PR is here: https://youtu.be/HkCKpGSP05o
Depends on
What issues does this PR fix or reference?
#8939