Search in sources :

Example 1 with HoverHandler

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

the class InvisibleProjectBuildSupportTest method testDynamicSourceLookups.

@Test
public void testDynamicSourceLookups() throws Exception {
    IProject project = copyAndImportFolder("singlefile/downloadSources", "UsingRemark.java");
    // place remark artifact in lib folder
    File remarkFile = DependencyUtil.getArtifact("com.kotcrab.remark", "remark", "1.2.0", null);
    IPath projectRealPath = ProjectUtils.getProjectRealFolder(project);
    IPath remarkCopy = projectRealPath.append("lib/remark.jar");
    FileUtils.copyFile(remarkFile, remarkCopy.toFile());
    // update classpath
    List<String> include = Arrays.asList("lib/**/*.jar");
    ReferencedLibraries libraries = new ReferencedLibraries(new HashSet<>(include));
    UpdateClasspathJob.getInstance().updateClasspath(JavaCore.create(project), libraries);
    waitForBackgroundJobs();
    List<IMarker> errors = ResourceUtils.getErrorMarkers(project);
    assertEquals("Unexpected errors " + ResourceUtils.toString(errors), 0, errors.size());
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry remark = JavaProjectHelper.findJarEntry(javaProject, "remark.jar");
    assertNotNull(remark);
    // construct hover request
    URI standalone = new File(projectRealPath.toFile(), "UsingRemark.java").toURI();
    String payload = HoverHandlerTest.createHoverRequest(standalone, 2, 3);
    TextDocumentPositionParams position = getParams(payload);
    // perform hover
    HoverHandler handler = new HoverHandler(preferenceManager);
    Hover hover = handler.hover(position, monitor);
    if (hover.getContents().getLeft().size() < 2) {
        JobHelpers.waitForDownloadSourcesJobs(60000);
        waitForBackgroundJobs();
        hover = handler.hover(position, monitor);
    }
    // verify library has source attachment
    remark = JavaProjectHelper.findJarEntry(javaProject, "remark.jar");
    assertNotNull(remark.getSourceAttachmentPath());
    assertNotNull(hover);
    String javadoc = hover.getContents().getLeft().get(1).getLeft();
    assertTrue("Unexpected Javadoc:" + javadoc, javadoc.contains("The class that manages converting HTML to Markdown"));
    // add another artifact to lib folder
    File jsoupFile = DependencyUtil.getArtifact("org.jsoup", "jsoup", "1.9.2", null);
    IPath jsoupCopy = projectRealPath.append("lib/jsoup.jar");
    FileUtils.copyFile(jsoupFile, jsoupCopy.toFile());
    // update classpath
    UpdateClasspathJob.getInstance().updateClasspath(JavaCore.create(project), libraries);
    waitForBackgroundJobs();
    // perform hover
    hover = handler.hover(position, monitor);
    if (hover.getContents().getLeft().size() < 2) {
        JobHelpers.waitForDownloadSourcesJobs(60000);
        waitForBackgroundJobs();
        hover = handler.hover(position, monitor);
    }
    // verify original library source attachment persists
    assertNotNull(remark.getSourceAttachmentPath());
    assertNotNull(hover);
    javadoc = hover.getContents().getLeft().get(1).getLeft();
    assertTrue("Unexpected Javadoc:" + javadoc, javadoc.contains("The class that manages converting HTML to Markdown"));
}
Also used : ReferencedLibraries(org.eclipse.jdt.ls.core.internal.preferences.Preferences.ReferencedLibraries) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) URI(java.net.URI) HoverHandler(org.eclipse.jdt.ls.core.internal.handlers.HoverHandler) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) Hover(org.eclipse.lsp4j.Hover) IMarker(org.eclipse.core.resources.IMarker) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) File(java.io.File) Test(org.junit.Test) HoverHandlerTest(org.eclipse.jdt.ls.core.internal.handlers.HoverHandlerTest)

Example 2 with HoverHandler

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

the class SyntaxLanguageServer method hover.

@Override
public CompletableFuture<Hover> hover(HoverParams position) {
    logInfo(">> document/hover");
    HoverHandler handler = new HoverHandler(this.preferenceManager);
    return computeAsync((monitor) -> handler.hover(position, monitor));
}
Also used : HoverHandler(org.eclipse.jdt.ls.core.internal.handlers.HoverHandler)

Aggregations

HoverHandler (org.eclipse.jdt.ls.core.internal.handlers.HoverHandler)2 File (java.io.File)1 URI (java.net.URI)1 IMarker (org.eclipse.core.resources.IMarker)1 IProject (org.eclipse.core.resources.IProject)1 IPath (org.eclipse.core.runtime.IPath)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 HoverHandlerTest (org.eclipse.jdt.ls.core.internal.handlers.HoverHandlerTest)1 ReferencedLibraries (org.eclipse.jdt.ls.core.internal.preferences.Preferences.ReferencedLibraries)1 Hover (org.eclipse.lsp4j.Hover)1 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)1 Test (org.junit.Test)1