Search in sources :

Example 31 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier 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 32 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier 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 33 with TextDocumentIdentifier

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

the class ServerTest method testMissingInitialize.

@Test
public void testMissingInitialize() throws Exception {
    try {
        DefinitionParams definitionParams = new DefinitionParams();
        definitionParams.setTextDocument(new TextDocumentIdentifier("file:/home/test/workspace/mydoc.testlang"));
        languageServer.definition(definitionParams).get();
        Assert.fail("Expected a ResponseErrorException");
    } catch (ExecutionException exception) {
        Assert.assertEquals(ResponseErrorCode.serverNotInitialized.getValue(), ((ResponseErrorException) exception.getCause()).getResponseError().getCode());
    }
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) ExecutionException(java.util.concurrent.ExecutionException) DefinitionParams(org.eclipse.lsp4j.DefinitionParams) Test(org.junit.Test)

Example 34 with TextDocumentIdentifier

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

the class UnknownProjectConfigTest method checkCompletion.

protected void checkCompletion(String uri) throws Exception {
    CompletableFuture<Either<List<CompletionItem>, CompletionList>> completionItems = languageServer.completion(new CompletionParams(new TextDocumentIdentifier(uri), new Position(0, 10)));
    Either<List<CompletionItem>, CompletionList> result = completionItems.get();
    List<CompletionItem> items = null;
    if (result.isLeft()) {
        items = result.getLeft();
    } else {
        items = result.getRight().getItems();
    }
    String actualCompletionItems = Strings.toUnixLineSeparator(toExpectation(items));
    String expectedCompletionItems = "Foo (TypeDeclaration) -> Foo [[0, 10] .. [0, 10]]\n" + "boolean -> boolean [[0, 10] .. [0, 10]]\n" + "int -> int [[0, 10] .. [0, 10]]\n" + "op -> op [[0, 10] .. [0, 10]]\n" + "string -> string [[0, 10] .. [0, 10]]\n" + "void -> void [[0, 10] .. [0, 10]]\n" + "} -> } [[0, 10] .. [0, 10]]\n" + "{ -> { [[0, 9] .. [0, 10]]\n" + "   + } [[0, 11] .. [0, 11]]\n";
    assertEquals(expectedCompletionItems, actualCompletionItems);
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CompletionParams(org.eclipse.lsp4j.CompletionParams) CompletionItem(org.eclipse.lsp4j.CompletionItem) Position(org.eclipse.lsp4j.Position) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList)

Example 35 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class TypeHierarchyCommandTest method testSubTypeHierarchy.

@Test
public void testSubTypeHierarchy() throws Exception {
    IProgressMonitor monitor = new NullProgressMonitor();
    TypeHierarchyParams params = new TypeHierarchyParams();
    String uriString = fJProject.getFile("src/main/java/org/sample/CallHierarchy.java").getLocationURI().toString();
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString);
    Position position = new Position(2, 43);
    params.setTextDocument(identifier);
    params.setResolve(2);
    params.setDirection(TypeHierarchyDirection.Children);
    params.setPosition(position);
    TypeHierarchyItem item = fCommand.typeHierarchy(params, monitor);
    assertNotNull(item);
    assertEquals(item.getName(), "Builder");
    assertNull(item.getParents());
    assertEquals(item.getChildren().size(), 9);
    for (TypeHierarchyItem child : item.getChildren()) {
        List<TypeHierarchyItem> subChild = child.getChildren();
        assertNotNull(subChild);
        if (subChild.size() == 1) {
            assertEquals(subChild.get(0).getName(), "ReflectionToStringBuilder");
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TypeHierarchyParams(org.eclipse.lsp4j.TypeHierarchyParams) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TypeHierarchyItem(org.eclipse.lsp4j.TypeHierarchyItem) Test(org.junit.Test) AbstractInvisibleProjectBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest)

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