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