Search in sources :

Example 11 with PrepareRenameParams

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

the class RenamePositionTest method renameAndFail.

protected void renameAndFail(String model, Position position, String messageFragment) {
    String modelFile = writeFile("MyType.testlang", model);
    initialize();
    try {
        TextDocumentIdentifier identifier = new TextDocumentIdentifier(modelFile);
        Either<Range, PrepareRenameResult> prepareRenameResult = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get();
        Assert.assertNull("expected null result got " + prepareRenameResult + " instead", prepareRenameResult);
        RenameParams renameParams = new RenameParams(new TextDocumentIdentifier(modelFile), position, "Tescht");
        languageServer.rename(renameParams).get();
        Assert.fail("Rename should have failed");
    } catch (Exception exc) {
        Throwable rootCause = Throwables.getRootCause(exc);
        Assert.assertTrue(rootCause instanceof ResponseErrorException);
        ResponseError error = ((ResponseErrorException) rootCause).getResponseError();
        Assert.assertTrue(error.getData().toString().contains(messageFragment));
    }
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) ResponseErrorException(org.eclipse.lsp4j.jsonrpc.ResponseErrorException) ResponseError(org.eclipse.lsp4j.jsonrpc.messages.ResponseError) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) RenameParams(org.eclipse.lsp4j.RenameParams) PrepareRenameResult(org.eclipse.lsp4j.PrepareRenameResult) Range(org.eclipse.lsp4j.Range) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) ResponseErrorException(org.eclipse.lsp4j.jsonrpc.ResponseErrorException)

Example 12 with PrepareRenameParams

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

the class RenameTest3 method testRenameAutoQuote.

@Test
public void testRenameAutoQuote() throws Exception {
    String model = "type Foo {\n" + "}\n" + "";
    String file = writeFile("foo/Foo.renametl", model);
    initialize();
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
    Position position = new Position(0, 6);
    Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
    assertEquals("Foo", new Document(0, model).getSubstring(range));
    RenameParams params = new RenameParams(identifier, position, "type");
    WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
    String expectation = "changes :\n" + "documentChanges : \n" + "    Foo.renametl <1> : ^type [[0, 5] .. [0, 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 13 with PrepareRenameParams

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

the class RenameTest3 method testRenameQuotedRef.

@Test
public void testRenameQuotedRef() throws Exception {
    String model = "type ^type {\n" + "}\n" + "\n" + "type Bar extends ^type {\n" + "}\n" + "";
    String file = writeFile("foo/Foo.renametl", model);
    initialize();
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
    Position position = new Position(3, 19);
    Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
    assertEquals("^type", new Document(0, model).getSubstring(range));
    RenameParams params = new RenameParams(identifier, position, "Foo");
    WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
    String expectation = "changes :\n" + "documentChanges : \n" + "    Foo.renametl <1> : Foo [[0, 5] .. [0, 10]]\n" + "    Foo [[3, 17] .. [3, 22]]\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 14 with PrepareRenameParams

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

the class PrepareRenameTest method testPrepareRenameFqn_missing_file_exception.

@Test
public void testPrepareRenameFqn_missing_file_exception() throws Exception {
    String uri = uriExtensions.toUriString(new File("missing." + fileExtension).toURI().normalize());
    initialize();
    PrepareRenameParams params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 5));
    try {
        Assert.assertNull(languageServer.prepareRename(params).get());
        Assert.fail("Expected an error.");
    } catch (Exception e) {
        Assert.assertTrue(Throwables.getRootCause(e) instanceof FileNotFoundException);
    }
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) FileNotFoundException(java.io.FileNotFoundException) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) File(java.io.File) ResponseErrorException(org.eclipse.lsp4j.jsonrpc.ResponseErrorException) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 15 with PrepareRenameParams

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

the class PrepareRenameTest method testPrepareRenameFqn_in_ok.

@Test
public void testPrepareRenameFqn_in_ok() 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, 14));
    Range range = languageServer.prepareRename(params).get().getLeft();
    assertEquals("MyType", new Document(0, model).getSubstring(range));
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Range(org.eclipse.lsp4j.Range) Document(org.eclipse.xtext.ide.server.Document) Test(org.junit.Test)

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