Search in sources :

Example 61 with TextDocumentIdentifier

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();
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) IJavaProject(org.eclipse.jdt.core.IJavaProject) Position(org.eclipse.lsp4j.Position) Hover(org.eclipse.lsp4j.Hover) MarkedString(org.eclipse.lsp4j.MarkedString) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) IProject(org.eclipse.core.resources.IProject) IType(org.eclipse.jdt.core.IType) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 62 with TextDocumentIdentifier

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());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) DidCloseTextDocumentParams(org.eclipse.lsp4j.DidCloseTextDocumentParams) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) MarkedString(org.eclipse.lsp4j.MarkedString) URI(java.net.URI) Test(org.junit.Test)

Example 63 with TextDocumentIdentifier

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());
}
Also used : HoverParams(org.eclipse.lsp4j.HoverParams) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) Hover(org.eclipse.lsp4j.Hover) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) MarkedString(org.eclipse.lsp4j.MarkedString) URI(java.net.URI) Test(org.junit.Test)

Example 64 with TextDocumentIdentifier

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 ");
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ProjectUtils(org.eclipse.jdt.ls.core.internal.ProjectUtils) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) StringUtils(org.apache.commons.lang3.StringUtils) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) IPath(org.eclipse.core.runtime.IPath) Map(java.util.Map) After(org.junit.After) Location(org.eclipse.lsp4j.Location) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) URI(java.net.URI) DidCloseTextDocumentParams(org.eclipse.lsp4j.DidCloseTextDocumentParams) JDTUtils(org.eclipse.jdt.ls.core.internal.JDTUtils) MarkedString(org.eclipse.lsp4j.MarkedString) LocationLink(org.eclipse.lsp4j.LocationLink) DefinitionParams(org.eclipse.lsp4j.DefinitionParams) Objects(java.util.Objects) CompletionItem(org.eclipse.lsp4j.CompletionItem) List(java.util.List) ContentProviderManager(org.eclipse.jdt.ls.core.internal.managers.ContentProviderManager) DidOpenTextDocumentParams(org.eclipse.lsp4j.DidOpenTextDocumentParams) Assert.assertFalse(org.junit.Assert.assertFalse) JDTEnvironmentUtils(org.eclipse.jdt.ls.core.internal.JDTEnvironmentUtils) JsonRpcHelpers(org.eclipse.jdt.ls.core.internal.handlers.JsonRpcHelpers) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) CompletionParams(org.eclipse.lsp4j.CompletionParams) JavaModelException(org.eclipse.jdt.core.JavaModelException) SymbolKind(org.eclipse.lsp4j.SymbolKind) RunWith(org.junit.runner.RunWith) DocumentSymbolParams(org.eclipse.lsp4j.DocumentSymbolParams) HoverParams(org.eclipse.lsp4j.HoverParams) Hover(org.eclipse.lsp4j.Hover) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) TextDocumentItem(org.eclipse.lsp4j.TextDocumentItem) ProjectsManager(org.eclipse.jdt.ls.core.internal.managers.ProjectsManager) CompletionItemKind(org.eclipse.lsp4j.CompletionItemKind) Position(org.eclipse.lsp4j.Position) CompletionList(org.eclipse.lsp4j.CompletionList) ResourceUtils(org.eclipse.jdt.ls.core.internal.ResourceUtils) Before(org.junit.Before) TypeDefinitionParams(org.eclipse.lsp4j.TypeDefinitionParams) Job(org.eclipse.core.runtime.jobs.Job) Assert.assertNotNull(org.junit.Assert.assertNotNull) JavaCore(org.eclipse.jdt.core.JavaCore) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) CoreASTProvider(org.eclipse.jdt.core.manipulation.CoreASTProvider) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Collections(java.util.Collections) CompletionResolveHandler(org.eclipse.jdt.ls.core.internal.handlers.CompletionResolveHandler) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) Assert.assertEquals(org.junit.Assert.assertEquals) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompletionList(org.eclipse.lsp4j.CompletionList) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CompletionParams(org.eclipse.lsp4j.CompletionParams) Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) MarkedString(org.eclipse.lsp4j.MarkedString) URI(java.net.URI) Test(org.junit.Test)

Example 65 with TextDocumentIdentifier

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));
    }
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Command(org.eclipse.lsp4j.Command) CodeAction(org.eclipse.lsp4j.CodeAction) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Range(org.eclipse.lsp4j.Range) AbstractQuickFixTest(org.eclipse.jdt.ls.core.internal.correction.AbstractQuickFixTest) Test(org.junit.Test)

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