Search in sources :

Example 51 with Position

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

the class RenamePositionTest method testRenameAtBrace.

@Test
public void testRenameAtBrace() {
    String model = "type Test{}";
    renameAndFail(model, new Position(0, model.indexOf("}")), "No element found at position");
}
Also used : Position(org.eclipse.lsp4j.Position) Test(org.junit.Test) AbstractLanguageServerTest(org.eclipse.xtext.testing.AbstractLanguageServerTest)

Example 52 with Position

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

the class RenamePositionTest method testRenameNameAtEndOfFile.

@Test
public void testRenameNameAtEndOfFile() throws Exception {
    String model = "type Test";
    renameWithSuccess(model, new Position(0, model.length()));
}
Also used : Position(org.eclipse.lsp4j.Position) Test(org.junit.Test) AbstractLanguageServerTest(org.eclipse.xtext.testing.AbstractLanguageServerTest)

Example 53 with Position

use of org.eclipse.lsp4j.Position 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 54 with Position

use of org.eclipse.lsp4j.Position 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 55 with Position

use of org.eclipse.lsp4j.Position 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)

Aggregations

Position (org.eclipse.lsp4j.Position)240 Test (org.junit.Test)149 Range (org.eclipse.lsp4j.Range)103 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)95 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)73 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)70 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)50 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)36 Location (org.eclipse.lsp4j.Location)34 List (java.util.List)29 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)29 URI (java.net.URI)27 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)23 ArrayList (java.util.ArrayList)21 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)18 TextEdit (org.eclipse.lsp4j.TextEdit)15 CompletionList (org.eclipse.lsp4j.CompletionList)14 Document (org.eclipse.xtext.ide.server.Document)14 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)13 Command (org.eclipse.lsp4j.Command)12