Search in sources :

Example 6 with PrepareRenameParams

use of org.eclipse.lsp4j.PrepareRenameParams in project xtext-core by eclipse.

the class PrepareRenameTest method testPrepareRenameFqn_end_null.

@Test
public void testPrepareRenameFqn_end_null() throws Exception {
    String model = "package foo.bar {\n" + "  type A {\n" + "    foo.bar.MyType bar\n" + "  }\n" + "  type MyType { }\n" + "}\n";
    initialize();
    String uri = writeFile("my-type-valid.testlang", model);
    PrepareRenameParams params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 18));
    Assert.assertNull(languageServer.prepareRename(params).get());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Test(org.junit.Test)

Example 7 with PrepareRenameParams

use of org.eclipse.lsp4j.PrepareRenameParams in project xtext-core by eclipse.

the class PrepareRenameTest method testPrepareRenameFqn_before_nok.

@Test
public void testPrepareRenameFqn_before_nok() throws Exception {
    String model = "package foo.bar {\n" + "  type A {\n" + "    foo.bar.MyType bar\n" + "  }\n" + "  type MyType { }\n" + "}\n";
    initializeWithPrepareSupport();
    String uri = writeFile("my-type-valid.testlang", model);
    PrepareRenameParams params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 11));
    Assert.assertNull(languageServer.prepareRename(params).get());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Test(org.junit.Test)

Example 8 with PrepareRenameParams

use of org.eclipse.lsp4j.PrepareRenameParams in project xtext-core by eclipse.

the class RenameTest2 method testRenameContainer.

@Test
public void testRenameContainer() throws Exception {
    String model = "package foo\n" + "\n" + "element Foo {\n" + " element Bar {\n" + " }\n" + " ref foo.Foo.Bar\n" + " ref Foo.Bar\n" + " ref Bar\n" + "}\n";
    String file = writeFile("foo/Foo.fileawaretestlanguage", model);
    initialize();
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
    Position position = new Position(2, 9);
    Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
    assertEquals("Foo", new Document(0, model).getSubstring(range));
    RenameParams params = new RenameParams(identifier, position, "Baz");
    WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
    String expectation = "changes :\n" + "documentChanges : \n" + "    Foo.fileawaretestlanguage <1> : Baz [[2, 8] .. [2, 11]]\n" + "    Bar [[5, 5] .. [5, 16]]\n" + "    Bar [[6, 5] .. [6, 12]]\n";
    assertEquals(expectation.toString(), toExpectation(workspaceEdit));
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) RenameParams(org.eclipse.lsp4j.RenameParams) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Range(org.eclipse.lsp4j.Range) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Document(org.eclipse.xtext.ide.server.Document) Test(org.junit.Test) AbstractLanguageServerTest(org.eclipse.xtext.testing.AbstractLanguageServerTest)

Example 9 with PrepareRenameParams

use of org.eclipse.lsp4j.PrepareRenameParams in project xtext-core by eclipse.

the class RenameTest2 method testRenameSelfRef.

@Test
public void testRenameSelfRef() throws Exception {
    String model = "package foo\n" + "\n" + "element Foo {\n" + " ref Foo\n" + "}\n";
    String file = writeFile("foo/Foo.fileawaretestlanguage", model);
    initialize();
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
    Position position = new Position(2, 9);
    Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
    assertEquals("Foo", new Document(0, model).getSubstring(range));
    RenameParams params = new RenameParams(identifier, position, "Bar");
    WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
    String expectation = "changes :\n" + "documentChanges : \n" + "    Foo.fileawaretestlanguage <1> : Bar [[2, 8] .. [2, 11]]\n" + "    Bar [[3, 5] .. [3, 8]]\n";
    assertEquals(expectation.toString(), toExpectation(workspaceEdit));
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) RenameParams(org.eclipse.lsp4j.RenameParams) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Range(org.eclipse.lsp4j.Range) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Document(org.eclipse.xtext.ide.server.Document) Test(org.junit.Test) AbstractLanguageServerTest(org.eclipse.xtext.testing.AbstractLanguageServerTest)

Example 10 with PrepareRenameParams

use of org.eclipse.lsp4j.PrepareRenameParams in project xtext-core by eclipse.

the class RenamePositionTest method renameWithSuccess.

protected void renameWithSuccess(String model, Position position) throws Exception {
    String modelFile = writeFile("MyType.testlang", model);
    initialize((InitializeParams params) -> {
        ClientCapabilities clientCapabilities = new ClientCapabilities();
        TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
        textDocumentClientCapabilities.setRename(new RenameCapabilities(true, false));
        clientCapabilities.setTextDocument(textDocumentClientCapabilities);
        params.setCapabilities(clientCapabilities);
    });
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(modelFile);
    Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
    Assert.assertNotNull(range);
    assertEquals(new Document(Integer.valueOf(0), model).getSubstring(range), "Test");
    RenameParams params = new RenameParams(identifier, position, "Tescht");
    WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
    String expectation = "changes :\n" + "	MyType.testlang : Tescht [[0, 5] .. [0, 9]]\n" + "documentChanges : \n";
    assertEquals(expectation.toString(), toExpectation(workspaceEdit));
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) RenameCapabilities(org.eclipse.lsp4j.RenameCapabilities) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) RenameParams(org.eclipse.lsp4j.RenameParams) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) InitializeParams(org.eclipse.lsp4j.InitializeParams) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) Range(org.eclipse.lsp4j.Range) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Document(org.eclipse.xtext.ide.server.Document)

Aggregations

PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)17 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)16 Position (org.eclipse.lsp4j.Position)14 Test (org.junit.Test)13 Range (org.eclipse.lsp4j.Range)12 Document (org.eclipse.xtext.ide.server.Document)12 RenameParams (org.eclipse.lsp4j.RenameParams)8 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)8 AbstractLanguageServerTest (org.eclipse.xtext.testing.AbstractLanguageServerTest)6 FileNotFoundException (java.io.FileNotFoundException)3 File (java.io.File)2 ExecutionException (java.util.concurrent.ExecutionException)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 PrepareRenameResult (org.eclipse.lsp4j.PrepareRenameResult)2 ResponseErrorException (org.eclipse.lsp4j.jsonrpc.ResponseErrorException)2 RenameContext (org.eclipse.xtext.ide.refactoring.RenameContext)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 CancelIndicator (org.eclipse.xtext.util.CancelIndicator)2 EObject (org.eclipse.emf.ecore.EObject)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1