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");
}
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()));
}
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));
}
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));
}
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);
}
Aggregations