Search in sources :

Example 21 with TextDocumentIdentifier

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

the class AbstractLanguageServerTest method testCodeLens.

protected void testCodeLens(final Procedure1<? super AbstractLanguageServerTest.TestCodeLensConfiguration> configurator) {
    try {
        @Extension final AbstractLanguageServerTest.TestCodeLensConfiguration configuration = new AbstractLanguageServerTest.TestCodeLensConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String filePath = this.initializeContext(configuration).getUri();
        CodeLensParams _codeLensParams = new CodeLensParams();
        final Procedure1<CodeLensParams> _function = (CodeLensParams it) -> {
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(filePath);
            it.setTextDocument(_textDocumentIdentifier);
        };
        CodeLensParams _doubleArrow = ObjectExtensions.<CodeLensParams>operator_doubleArrow(_codeLensParams, _function);
        final CompletableFuture<List<? extends CodeLens>> codeLenses = this.languageServer.codeLens(_doubleArrow);
        final Function1<CodeLens, CodeLens> _function_1 = (CodeLens it) -> {
            try {
                return this.languageServer.resolveCodeLens(it).get();
            } catch (Throwable _e) {
                throw Exceptions.sneakyThrow(_e);
            }
        };
        final List<CodeLens> result = IterableExtensions.<CodeLens>toList(ListExtensions.map(codeLenses.get(), _function_1));
        if ((configuration.assertCodeLenses != null)) {
            configuration.assertCodeLenses.apply(result);
        } else {
            this.assertEquals(configuration.expectedCodeLensItems, this.toExpectation(result));
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Extension(org.eclipse.xtext.xbase.lib.Extension) CodeLens(org.eclipse.lsp4j.CodeLens) CodeLensParams(org.eclipse.lsp4j.CodeLensParams) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList)

Example 22 with TextDocumentIdentifier

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

the class RenameTest3 method testRenameAutoQuoteRef.

@Test
public void testRenameAutoQuoteRef() throws Exception {
    String model = "type Foo {\n" + "}\n" + "\n" + "type Bar extends Foo {\n" + "}\n" + "";
    String file = writeFile("foo/Foo.renametl", model);
    initialize();
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
    Position position = new Position(3, 18);
    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" + "    ^type [[3, 17] .. [3, 20]]\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 23 with TextDocumentIdentifier

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

the class RenameTest3 method testRenameQuoted.

@Test
public void testRenameQuoted() throws Exception {
    String model = "type ^type {\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("^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" + "";
    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 24 with TextDocumentIdentifier

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

the class PrepareRenameTest method testRenameFqn_invalid_error.

@Test
public void testRenameFqn_invalid_error() throws Exception {
    String model = "package foo.bar {\n" + "  type A {\n" + "    foo.bar.MyType bar\n" + "  }\n" + "  type MyType { }\n" + "}\n";
    String uri = writeFile("my-type-invalid.testlang", model);
    initialize();
    RenameParams params = new RenameParams(new TextDocumentIdentifier(uri), new Position(2, 5), "Does not matter");
    try {
        languageServer.rename(params).get();
        Assert.fail("Expected an expcetion when trying to rename document but got a valid workspace edit instead: �workspaceEdit�");
    } catch (Exception e) {
        Throwable rootCause = Throwables.getRootCause(e);
        Assert.assertTrue(rootCause instanceof ResponseErrorException);
        ResponseError error = ((ResponseErrorException) rootCause).getResponseError();
        Assert.assertTrue(error.getData().toString().contains("No element found at position"));
    }
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) ResponseErrorException(org.eclipse.lsp4j.jsonrpc.ResponseErrorException) ResponseError(org.eclipse.lsp4j.jsonrpc.messages.ResponseError) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) RenameParams(org.eclipse.lsp4j.RenameParams) ResponseErrorException(org.eclipse.lsp4j.jsonrpc.ResponseErrorException) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 25 with TextDocumentIdentifier

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

the class PrepareRenameTest method testPrepareRenameFqn_start_ok.

@Test
public void testPrepareRenameFqn_start_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, 12));
    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

TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)172 Test (org.junit.Test)113 Position (org.eclipse.lsp4j.Position)102 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)56 Range (org.eclipse.lsp4j.Range)47 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)37 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)35 URI (java.net.URI)34 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)33 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)32 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)32 List (java.util.List)26 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)25 Location (org.eclipse.lsp4j.Location)23 AbstractQuickFixTest (org.eclipse.jdt.ls.core.internal.correction.AbstractQuickFixTest)22 Command (org.eclipse.lsp4j.Command)22 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)20 FormattingOptions (org.eclipse.lsp4j.FormattingOptions)19 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)18 CodeAction (org.eclipse.lsp4j.CodeAction)18