-
Notifications
You must be signed in to change notification settings - Fork 408
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 refactoring when renaming or moving files #1445
Support refactoring when renaming or moving files #1445
Conversation
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/FileEventHandler.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/FileEventHandler.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/FileEventHandler.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/FileEventHandler.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/FileEventHandler.java
Outdated
Show resolved
Hide resolved
@@ -163,7 +163,7 @@ public void testMoveFile() throws JavaModelException, BadLocationException { | |||
assertNotNull(refactorEdit); | |||
assertNotNull(refactorEdit.edit); | |||
List<Either<TextDocumentEdit, ResourceOperation>> changes = refactorEdit.edit.getDocumentChanges(); | |||
assertEquals(4, changes.size()); | |||
assertEquals(3, changes.size()); |
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.
why would this change?
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.
The move refactoring code generates some empty textEdit operation, for example, insert empty string at the same location. I refined the ChangeUtils utility to filter out such empty operations. That's why you see the changes list is shorter.
test this please |
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/FileEventHandler.java
Outdated
Show resolved
Hide resolved
e4252d7
to
faa7b9d
Compare
faa7b9d
to
6a42fb3
Compare
test this please |
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/FileEventHandler.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/FileEventHandler.java
Outdated
Show resolved
Hide resolved
6a42fb3
to
3e8c692
Compare
Just a few things I've noticed from trying this out :
I also see the following error in the output :
|
This is by design. Clicking discard button just mean skipping the refactoring changes. It won't stop the file move operation.
The preview just shows what we give to it. Do you mean the refactoring job returns some unnecessary changes in the workspace edit? Or just about the displayed diff label for the change?
We just use the client's file API Last one about the documentSymbol exception, looks like the client sends an extra document symbol request while the file is moving. There is race condition, where the disk file has been moved when dealing with the document symbol for the old file uri. Since the documentSymbol for old uri is no meaning during move, this failure won't affect any UI experience. There could three possible solutions to fix this:
|
Ok, then the majority of the points are fine as long as it's expected, or not harmful. It looks like needing to save all the files is the same even prior to this change so should be ok for now.
After trying a current release, it seems the behaviour of the diff label is the same so maybe this can be addressed separately. But yes, the labels seem long. I thought they would have just show the text being changed, but I seem to also be getting 'public class Main', in the demo above, though it remains unchanged. |
Look at your sample again, actually it updates two references in Main.java. One is the import reference for Util, another is the class reference from getTest() body. It seems we merge these two changes into one long text change in the final WorkspaceEdit. That's why you see a long diff label After debugging jdt.ls code, looks like the original JDT refactoring utilities return a MultiTextEdit to update the references in Main.java, which contains two child replace edits for import update and getText() body update. But when we use the TextEditConverter helper to convert the eclipse TextEdit to lsp WorkspaceEdit, that MultiTextEdit is converted to one change finally. Since this is the converter quality issue of the helper method TextEditConverter, i'd suggest to improve it with a separate issue. |
With the latest commit, the "File Not Found" exception above is suppressed. @rgrunber Could you take a look again to see whether there is any more improvement to fix before we merge it? |
Signed-off-by: Jinbo Wang <[email protected]>
Signed-off-by: Jinbo Wang <[email protected]>
d5d79f6
to
be0fd0a
Compare
The latest commit has adopted the lsp4j interfaces to handle But there is an issue eclipse-lsp4j/lsp4j#522 in lsp4j to block the adoption of My thought is that we keep using client-side API |
Signed-off-by: Jinbo Wang [email protected]