Search in sources :

Example 46 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class ImplementationsHandlerTest method testEmpty.

@Test
public void testEmpty() {
    TextDocumentPositionParams param = new TextDocumentPositionParams();
    param.setPosition(new Position(1, 1));
    param.setTextDocument(new TextDocumentIdentifier("/foo/bar"));
    List<? extends Location> implementations = handler.findImplementations(param, monitor);
    assertNotNull(implementations);
    assertTrue("implementations are not empty", implementations.isEmpty());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

Example 47 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class ImplementationsHandlerTest method testMethodInvocationImplementation.

@Test
public void testMethodInvocationImplementation() {
    URI uri = project.getFile("src/org/sample/FooService.java").getRawLocationURI();
    String fileURI = ResourceUtils.fixURI(uri);
    TextDocumentPositionParams param = new TextDocumentPositionParams();
    // Position over foo.someMethod
    param.setPosition(new Position(6, 14));
    param.setTextDocument(new TextDocumentIdentifier(fileURI));
    List<? extends Location> implementations = handler.findImplementations(param, monitor);
    assertNotNull("findImplementations should not return null", implementations);
    assertEquals(implementations.toString(), 1, implementations.size());
    Location foo2 = implementations.get(0);
    assertTrue("Unexpected implementation : " + foo2.getUri(), foo2.getUri().contains("org/sample/Foo2.java"));
    // check range points to someMethod() position
    assertEquals(new Position(4, 16), foo2.getRange().getStart());
    assertEquals(new Position(4, 26), foo2.getRange().getEnd());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) URI(java.net.URI) Location(org.eclipse.lsp4j.Location) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

Example 48 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class NavigateToTypeDefinitionHandlerTest method testGetEmptyDefinition.

@Test
public void testGetEmptyDefinition() throws Exception {
    List<? extends Location> definitions = handler.typeDefinition(new TextDocumentPositionParams(new TextDocumentIdentifier("/foo/bar"), new Position(1, 1)), monitor);
    assertNull(definitions);
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

Example 49 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class NavigateToTypeDefinitionHandlerTest method testDisassembledSource.

@Test
public void testDisassembledSource() throws JavaModelException {
    String className = "javax.tools.Tool";
    int line = 6;
    int column = 57;
    String uri = ClassFileUtil.getURI(project, className);
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri);
    List<? extends Location> definitions = handler.typeDefinition(new TextDocumentPositionParams(identifier, new Position(line, column)), monitor);
    assertNotNull(definitions);
    assertEquals("No definition found for " + className, 1, definitions.size());
    assertNotNull(definitions.get(0).getUri());
    assertEquals(3, definitions.get(0).getRange().getStart().getLine());
    assertEquals(12, definitions.get(0).getRange().getStart().getCharacter());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

Example 50 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class NavigateToTypeDefinitionHandlerTest method testClass.

private void testClass(String className, int line, int column) throws JavaModelException {
    String uri = ClassFileUtil.getURI(project, className);
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri);
    List<? extends Location> definitions = handler.typeDefinition(new TextDocumentPositionParams(identifier, new Position(line, column)), monitor);
    assertNotNull(definitions);
    assertEquals("No definition found for " + className, 1, definitions.size());
    assertNotNull(definitions.get(0).getUri());
    assertTrue(definitions.get(0).getRange().getStart().getLine() >= 0);
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams)

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