diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java index 1c58bf6bd5f8..866a0825a464 100644 --- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java @@ -1555,7 +1555,6 @@ public boolean cancel(boolean mayInterruptIfRunning) { refactoring[0] = new RenameRefactoring(Lookups.fixed(lookupContent.toArray(new Object[0]))); refactoring[0].getContext().add(JavaRefactoringUtils.getClasspathInfoFor(cc.getFileObject())); refactoring[0].setNewName(params.getNewName()); - refactoring[0].setSearchInComments(true); //TODO? } }, true); if (cancel.get()) return ; diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java index e0dec202c4f9..be50b041d3d9 100644 --- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java +++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java @@ -3798,6 +3798,13 @@ public void testRenameDocumentChangesCapabilitiesRenameOp() throws Exception { Set actual = edit.getDocumentChanges().stream().map(this::toString).collect(Collectors.toSet()); Set expected = new HashSet<>(Arrays.asList("Test2.java:[0:27-0:31=>TestNew, 1:4-1:8=>TestNew, 2:11-2:15=>TestNew]", "Test.java:[0:13-0:17=>TestNew]", "Test.java=>TestNew.java")); assertEquals(expected, actual); + }, + cf -> { + WorkspaceEdit edit = cf.get(); + assertTrue(edit.getChanges().isEmpty()); + Set actual = edit.getDocumentChanges().stream().map(this::toString).collect(Collectors.toSet()); + Set expected = new HashSet<>(Arrays.asList("Test3.java:[3:14-3:22=>arg, 6:36-6:44=>arg, 7:27-7:35=>arg]")); + assertEquals(expected, actual); }); } @@ -3822,12 +3829,20 @@ public void testRenameDocumentChangesCapabilitiesNoRenameOp() throws Exception { Set actual = edit.getDocumentChanges().stream().map(this::toString).collect(Collectors.toSet()); Set expected = new HashSet<>(Arrays.asList("Test2.java:[0:27-0:31=>TestNew, 1:4-1:8=>TestNew, 2:11-2:15=>TestNew]", "Test.java:[0:13-0:17=>TestNew]", "Test.java=>TestNew.java")); assertEquals(expected, actual); + }, + cf -> { + WorkspaceEdit edit = cf.get(); + assertTrue(edit.getChanges().isEmpty()); + Set actual = edit.getDocumentChanges().stream().map(this::toString).collect(Collectors.toSet()); + Set expected = new HashSet<>(Arrays.asList("Test3.java:[3:14-3:22=>arg, 6:36-6:44=>arg, 7:27-7:35=>arg]")); + assertEquals(expected, actual); }); } private void doTestRename(Consumer settings, Validator> validateFieldRename, - Validator> validateClassRename) throws Exception { + Validator> validateClassRename, + Validator> validateArgumentRename) throws Exception { File src = new File(getWorkDir(), "Test.java"); src.getParentFile().mkdirs(); try (Writer w = new FileWriter(new File(src.getParentFile(), ".test-project"))) {} @@ -3846,6 +3861,20 @@ private void doTestRename(Consumer settings, try (Writer w = new FileWriter(src2)) { w.write(code2); } + File src3 = new File(getWorkDir(), "Test3.java"); + String code3 = "public class Test3 {\n" + + " /**\n" + + " * They had an argument\n" + + " * @param argument\n" + + " *\n" + + " */\n" + + " public static void greet(String argument){\n" + + " System.out.println(argument);\n" + + " }\n" + + "}"; + try (Writer w = new FileWriter(src3)) { + w.write(code3); + } List[] diags = new List[1]; CountDownLatch indexingComplete = new CountDownLatch(1); Launcher serverLauncher = createClientLauncherWithLogging(new LspClient() { @@ -3903,6 +3932,14 @@ public void logMessage(MessageParams arg0) { validateClassRename.validate(server.getTextDocumentService().rename(params)); } + server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(toURI(src3), "java", 0, code3))); + { + RenameParams params = new RenameParams(new TextDocumentIdentifier(src3.toURI().toString()), + new Position(6, 37), + "arg"); + + validateArgumentRename.validate(server.getTextDocumentService().rename(params)); + } } public void testMoveClass() throws Exception {