Search in sources :

Example 41 with TextDocumentIdentifier

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

the class RenameHandlerTest method getRenameEdit.

private WorkspaceEdit getRenameEdit(ICompilationUnit cu, Position pos, String newName) {
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(JDTUtils.toURI(cu));
    RenameParams params = new RenameParams(identifier, pos, newName);
    return handler.rename(params, monitor);
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) RenameParams(org.eclipse.lsp4j.RenameParams)

Example 42 with TextDocumentIdentifier

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

the class ReferencesHandlerTest method testIncludeAccessors.

@Test
public void testIncludeAccessors() {
    boolean includeAccessors = preferenceManager.getPreferences().isIncludeAccessors();
    try {
        URI uri = project.getFile("src/org/ref/Apple.java").getRawLocationURI();
        String fileURI = ResourceUtils.fixURI(uri);
        ReferenceParams param = new ReferenceParams();
        param.setPosition(new Position(3, 18));
        param.setContext(new ReferenceContext(true));
        param.setTextDocument(new TextDocumentIdentifier(fileURI));
        preferenceManager.getPreferences().setIncludeAccessors(false);
        List<Location> references = handler.findReferences(param, monitor);
        assertNotNull("findReferences should not return null", references);
        assertEquals(3, references.size());
        preferenceManager.getPreferences().setIncludeAccessors(true);
        references = handler.findReferences(param, monitor);
        assertNotNull("findReferences should not return null", references);
        assertEquals(5, references.size());
        Location l = references.get(0);
        String refereeUri = ResourceUtils.fixURI(project.getFile("src/org/ref/Apple.java").getRawLocationURI());
        assertEquals(refereeUri, l.getUri());
        l = references.get(4);
        refereeUri = ResourceUtils.fixURI(project.getFile("src/org/ref/Test.java").getRawLocationURI());
        assertEquals(refereeUri, l.getUri());
    } finally {
        preferenceManager.getPreferences().setIncludeAccessors(includeAccessors);
    }
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) ReferenceParams(org.eclipse.lsp4j.ReferenceParams) Position(org.eclipse.lsp4j.Position) ReferenceContext(org.eclipse.lsp4j.ReferenceContext) URI(java.net.URI) Location(org.eclipse.lsp4j.Location) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 43 with TextDocumentIdentifier

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

the class SelectionRangeHandlerTest method getSelectionRange.

private SelectionRange getSelectionRange(String className, Position position) throws CoreException {
    SelectionRangeParams params = new SelectionRangeParams();
    params.setPositions(Lists.newArrayList(position));
    params.setTextDocument(new TextDocumentIdentifier(ClassFileUtil.getURI(project, className)));
    return new SelectionRangeHandler().selectionRange(params, monitor).get(0);
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) SelectionRangeParams(org.eclipse.lsp4j.SelectionRangeParams)

Example 44 with TextDocumentIdentifier

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

the class NavigateToDefinitionHandlerTest method testNoClassContentSupport.

@Test
public void testNoClassContentSupport() throws Exception {
    when(preferenceManager.isClientSupportsClassFileContent()).thenReturn(true);
    String uri = ClassFileUtil.getURI(project, "org.apache.commons.lang3.StringUtils");
    when(preferenceManager.isClientSupportsClassFileContent()).thenReturn(false);
    List<? extends Location> definitions = handler.definition(new TextDocumentPositionParams(new TextDocumentIdentifier(uri), new Position(20, 26)), monitor);
    assertNotNull(definitions);
    assertEquals(0, definitions.size());
}
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 45 with TextDocumentIdentifier

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

the class NavigateToDefinitionHandlerTest method testMethodInAnonymousClass.

// https://github.com/eclipse/eclipse.jdt.ls/issues/1813
@Test
public void testMethodInAnonymousClass() throws Exception {
    String className = "org.sample.App";
    int line = 12;
    int column = 28;
    importProjects("eclipse/hello");
    IProject hello = WorkspaceHelper.getProject("hello");
    String uri = ClassFileUtil.getURI(hello, className);
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri);
    List<? extends Location> definitions = handler.definition(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(18, definitions.get(0).getRange().getStart().getCharacter());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

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