Search in sources :

Example 1 with NavigateToDefinitionHandler

use of org.eclipse.jdt.ls.core.internal.handlers.NavigateToDefinitionHandler in project eclipse.jdt.ls by eclipse.

the class SyntaxLanguageServer method definition.

@Override
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definition(DefinitionParams position) {
    logInfo(">> document/definition");
    NavigateToDefinitionHandler handler = new NavigateToDefinitionHandler(this.preferenceManager);
    return computeAsync((monitor) -> {
        waitForLifecycleJobs(monitor);
        List<? extends Location> locations = handler.definition(position, monitor);
        for (Location location : locations) {
            location.setUri(JDTUtils.replaceUriFragment(location.getUri(), SYNTAX_SERVER_ID));
        }
        return Either.forLeft(locations);
    });
}
Also used : NavigateToDefinitionHandler(org.eclipse.jdt.ls.core.internal.handlers.NavigateToDefinitionHandler) Location(org.eclipse.lsp4j.Location)

Example 2 with NavigateToDefinitionHandler

use of org.eclipse.jdt.ls.core.internal.handlers.NavigateToDefinitionHandler in project eclipse.jdt.ls by eclipse.

the class InvisibleProjectBuildSupportTest method testUpdateReferencedLibraries.

@Test
public void testUpdateReferencedLibraries() throws Exception {
    IProject project = copyAndImportFolder("singlefile/simple", "src/App.java");
    NavigateToDefinitionHandler handler = new NavigateToDefinitionHandler(preferenceManager);
    String uri = ClassFileUtil.getURI(project, "App");
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri);
    List<? extends Location> definitions = handler.definition(new TextDocumentPositionParams(identifier, new Position(0, 13)), monitor);
    // The original mylib.jar is an empty jar, so the GTD is not available
    assertEquals(0, definitions.size());
    // replace it which contains the class 'mylib.A'
    IPath projectRealPath = ProjectUtils.getProjectRealFolder(project);
    IPath newLibPath = projectRealPath.append("mylib.jar");
    IPath referencedLibraryPath = projectRealPath.append("lib/mylib.jar");
    FileUtils.copyFile(newLibPath.toFile(), referencedLibraryPath.toFile());
    List<String> include = Arrays.asList("lib/**/*.jar");
    ReferencedLibraries libraries = new ReferencedLibraries(new HashSet<>(include));
    UpdateClasspathJob.getInstance().updateClasspath(JavaCore.create(project), libraries);
    waitForBackgroundJobs();
    definitions = handler.definition(new TextDocumentPositionParams(identifier, new Position(0, 13)), monitor);
    assertEquals(1, definitions.size());
}
Also used : ReferencedLibraries(org.eclipse.jdt.ls.core.internal.preferences.Preferences.ReferencedLibraries) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) NavigateToDefinitionHandler(org.eclipse.jdt.ls.core.internal.handlers.NavigateToDefinitionHandler) IPath(org.eclipse.core.runtime.IPath) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test) HoverHandlerTest(org.eclipse.jdt.ls.core.internal.handlers.HoverHandlerTest)

Aggregations

NavigateToDefinitionHandler (org.eclipse.jdt.ls.core.internal.handlers.NavigateToDefinitionHandler)2 IProject (org.eclipse.core.resources.IProject)1 IPath (org.eclipse.core.runtime.IPath)1 HoverHandlerTest (org.eclipse.jdt.ls.core.internal.handlers.HoverHandlerTest)1 ReferencedLibraries (org.eclipse.jdt.ls.core.internal.preferences.Preferences.ReferencedLibraries)1 Location (org.eclipse.lsp4j.Location)1 Position (org.eclipse.lsp4j.Position)1 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)1 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)1 Test (org.junit.Test)1