use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.
the class HoverHandlerTest method testInvalidJavadoc.
@Test
public void testInvalidJavadoc() throws Exception {
importProjects("maven/aspose");
IProject project = null;
ICompilationUnit unit = null;
try {
project = ResourcesPlugin.getWorkspace().getRoot().getProject("aspose");
IJavaProject javaProject = JavaCore.create(project);
IType type = javaProject.findType("org.sample.TestJavadoc");
unit = type.getCompilationUnit();
unit.becomeWorkingCopy(null);
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
TextDocumentPositionParams position = new TextDocumentPositionParams(textDocument, new Position(8, 24));
Hover hover = handler.hover(position, monitor);
assertNotNull(hover);
assertNotNull(hover.getContents());
assertEquals(1, hover.getContents().getLeft().size());
assertEquals("com.aspose.words.Document.Document(String fileName) throws Exception", hover.getContents().getLeft().get(0).getRight().getValue());
} finally {
if (unit != null) {
unit.discardWorkingCopy();
}
}
}
use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.
the class SyntaxServerTest method testDidClose.
@Test
public void testDidClose() throws Exception {
URI fileURI = openFile("maven/salut4", "src/main/java/java/TestSyntaxError.java");
Job.getJobManager().join(SyntaxDocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, monitor);
String fileUri = ResourceUtils.fixURI(fileURI);
TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri);
server.didClose(new DidCloseTextDocumentParams(identifier));
Job.getJobManager().join(SyntaxDocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, monitor);
List<PublishDiagnosticsParams> diagnosticReports = getClientRequests("publishDiagnostics");
assertEquals(2, diagnosticReports.size());
PublishDiagnosticsParams params = diagnosticReports.get(1);
assertEquals(fileUri, params.getUri());
assertNotNull(params.getDiagnostics());
assertTrue(params.getDiagnostics().isEmpty());
}
use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.
the class SyntaxServerTest method testHoverUnresolvedType.
@Test
public void testHoverUnresolvedType() throws Exception {
URI fileURI = openFile("maven/salut4", "src/main/java/java/Foo.java");
String fileUri = ResourceUtils.fixURI(fileURI);
TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri);
HoverParams params = new HoverParams(identifier, new Position(7, 30));
Hover result = server.hover(params).join();
assertNotNull(result);
assertNotNull(result.getContents());
assertTrue(result.getContents().isLeft());
List<Either<String, MarkedString>> list = result.getContents().getLeft();
assertNotNull(list);
assertEquals(2, list.size());
assertTrue(list.get(1).isLeft());
assertEquals("This is interface IFoo.", list.get(1).getLeft());
}
use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.
the class SyntaxServerTest method testResolveCompletion.
@Test
public void testResolveCompletion() throws Exception {
URI fileURI = openFile("maven/salut4", "src/main/java/java/Completion.java");
ICompilationUnit cu = JDTUtils.resolveCompilationUnit(fileURI);
assertNotNull(cu);
cu.getBuffer().setContents("package java;\n\n" + "public class Completion {\n" + " public static void main(String[] args) {\n" + " fo\n" + " System.out.println(\"Hello World!\");\n" + " }\n\n" + " /**\n" + " * This method has Javadoc\n" + " */\n" + " public static void foo(String bar) {\n" + " }\n" + " /**\n" + " * Another Javadoc\n" + " */\n" + " public static void foo() {\n" + " }\n" + "}\n");
cu.makeConsistent(null);
int[] loc = findLocation(cu, "\t\tfo");
String fileUri = ResourceUtils.fixURI(fileURI);
TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri);
CompletionParams params = new CompletionParams(identifier, new Position(loc[0], loc[1]));
CompletionList list = server.completion(params).join().getRight();
assertNotNull(list);
CompletionItem ci = list.getItems().stream().filter(item -> item.getLabel().startsWith("foo(String bar) : void")).findFirst().orElse(null);
assertNotNull(ci);
CompletionItem resolvedItem = server.resolveCompletionItem(ci).join();
assertNotNull(resolvedItem);
assertNotNull(resolvedItem.getDocumentation());
assertNotNull(resolvedItem.getDocumentation().getLeft());
String javadoc = resolvedItem.getDocumentation().getLeft();
assertEquals(javadoc, " This method has Javadoc ");
ci = list.getItems().stream().filter(item -> item.getLabel().startsWith("foo() : void")).findFirst().orElse(null);
assertNotNull(ci);
resolvedItem = server.resolveCompletionItem(ci).join();
assertNotNull(resolvedItem);
assertNotNull(resolvedItem.getDocumentation());
assertNotNull(resolvedItem.getDocumentation().getLeft());
javadoc = resolvedItem.getDocumentation().getLeft();
assertEquals(javadoc, " Another Javadoc ");
}
use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.
the class CodeActionHandlerTest method testCodeAction_organizeImportsSourceActionOnly.
@Test
public void testCodeAction_organizeImportsSourceActionOnly() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "import java.util.List;\n" + "public class Foo {\n" + " void foo() {\n" + " String bar = \"astring\";" + " }\n" + "}\n");
CodeActionParams params = new CodeActionParams();
params.setTextDocument(new TextDocumentIdentifier(JDTUtils.toURI(unit)));
final Range range = CodeActionUtil.getRange(unit, "bar");
params.setRange(range);
CodeActionContext context = new CodeActionContext(Arrays.asList(getDiagnostic(Integer.toString(IProblem.LocalVariableIsNeverUsed), range)), Collections.singletonList(CodeActionKind.SourceOrganizeImports));
params.setContext(context);
List<Either<Command, CodeAction>> codeActions = getCodeActions(params);
Assert.assertNotNull(codeActions);
Assert.assertFalse("No organize imports actions were found", codeActions.isEmpty());
for (Either<Command, CodeAction> codeAction : codeActions) {
Assert.assertTrue("Unexpected kind:" + codeAction.getRight().getKind(), codeAction.getRight().getKind().startsWith(CodeActionKind.SourceOrganizeImports));
}
}
Aggregations