-
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
Add rename compilation unit support. #864
Conversation
assertEquals(JDTUtils.toURI(cu), resourceChange.getCurrent()); | ||
Either<TextDocumentEdit, ResourceOperation> change = resourceChanges.get(2); | ||
RenameFile resourceChange = (RenameFile) change.getRight(); | ||
assertEquals(JDTUtils.toURI(cu), resourceChange.getOldUri()); | ||
assertEquals(JDTUtils.toURI(cu).replace("E", "Newname"), resourceChange.getNewUri()); |
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.
assertEquals(JDTUtils.toURI(cu).replace("E.java", "Newname.java"), resourceChange.getNewUri());
If the workspace name contains "E", the test will fail.
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.
@snjeza Add test cases for failure situation.
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 agree with @snjeza, the regexp in replace() call needs to be more specific
create.run(monitor); | ||
if (check.getStatus().getSeverity() >= RefactoringStatus.ERROR) { |
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.
if (check.getStatus().hasFatalError()) {
otherwise, a rename refactoring operation will fail if there is an invalid rename participant.
That's why the following four tests fail in Eclipse - testRenamePackage, testRenameType, testRenameOverrideMethodSimple and testRenameField.
The testRenameTypeWithResourceChanges test still fails in Eclipse, if the workspace name contains "E".
Could you try to run RenameHandlerTest in Eclipse using the workspace '${workspace_loc}/../junit-workspacE' name ?
@@ -262,7 +260,42 @@ public void testRenameTypeWhithResourceChanges() throws JavaModelException, BadL | |||
assertEquals(expected, TextEditUtil.apply(builder.toString(), testChanges)); | |||
} | |||
|
|||
@Test | |||
@Test(expected = ResponseErrorException.class) | |||
public void testRenameTypeWithrErrors() throws JavaModelException, BadLocationException { |
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.
testRenameTypeWithErrors()
Signed-off-by: Yaohai Zheng <[email protected]>
d5f386d
to
5142e40
Compare
@snjeza Updated the PR |
This now works much better! One problem I found though: if, from a file, you try to rename a package to something that already exists (effectively moving the type from one package to another), then the server complains the package already exists. I think it should just move the file to the new package if it already exists. Although this might go beyond the scope of the current PR. It's probably ok to handle that separately. |
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 testRenameTypeWithResourceChanges test still fails, if the workspace name contains "E".
Could you try the following:
cd eclipse.jdt.ls
cd ..
mv eclipse.jdt.ls Eclipse.jdt.ls
cd Eclipse.jdt.ls
mvn clean verify
You will get the following:
Failed tests:
RenameHandlerTest.testRenameTypeWithResourceChanges:243 expected:<.../home/snjeza/projects/[Newname]clipse.jdt.ls/org.ec...> but was:<.../home/snpe/projects/[E]clipse.jdt.ls/org.ec...>
ok so I was able to rename the package in |
context.setASTRoot(ast); | ||
ASTNode node = context.getCoveredNode(); | ||
// Rename package is not fully support yet. | ||
if (!(node instanceof PackageDeclaration) && !(node instanceof QualifiedName && node.getParent() instanceof PackageDeclaration)) { |
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.
when renaming package example;
, example
is found to be a SimpleName instead of a QualifiedName, so it goes through this condition
JavaLanguageServerPlugin.logException("Problem with compute occurrences for" + unit.getElementName() + " in prepareRename", e); | ||
} | ||
} | ||
throw new ResponseErrorException(new ResponseError(ResponseErrorCode.InvalidRequest, "Rename this element is not supported yet.", null)); |
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.
Renaming this element is not supported.
test this please |
JavaLanguageServerPlugin.logException("Problem with compute occurrences for" + unit.getElementName() + " in prepareRename", e); | ||
} | ||
} | ||
throw new ResponseErrorException(new ResponseError(ResponseErrorCode.InvalidRequest, "Rename this element is not supported.", null)); |
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.
s/Rename/Renaming
} | ||
|
||
} catch (CoreException e) { | ||
JavaLanguageServerPlugin.logException("Problem with compute occurrences for" + unit.getElementName() + " in prepareRename", e); |
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.
Problem computing occurrences for
InnovationContext context = new InnovationContext(unit, loc.getOffset(), loc.getLength()); | ||
context.setASTRoot(ast); | ||
ASTNode node = context.getCoveredNode(); | ||
// Rename package is not fully support yet. |
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.
Renaming package is not fully supported yet.
4cf9bb3
to
2a2712c
Compare
test this please |
@fbricon Updated the PR |
Signed-off-by: Fred Bricon <[email protected]>
@snjeza can you please check the last changes I pushed to this PR? |
if you try to rename Exception in
|
@snjeza please check the new fix |
new fix is incomplete. Renaming java.lang.Exception is still allowed. |
Signed-off-by: Fred Bricon <[email protected]>
new fix handles FQCN renames |
@fbricon For resource rename support, I'll enable it in two steps: Firstly support compilation unit for most scenarios. Would like to roll out this feature ASAP.
For rename package, it need LSP support from these two issue:
textDocument/(will/did)Rename
notifications microsoft/language-server-protocol#540