Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract embedded javadoc images #1138

Merged
merged 1 commit into from
Sep 17, 2019

Conversation

NikolasKomonen
Copy link
Contributor

@NikolasKomonen NikolasKomonen commented Aug 1, 2019

The purpose of this PR is to enable javadoc hover to work with html tag images that are embedded inside a jar. This does not currently work because the language server receives a relative path to the jar that it does not know how to resolve.

This PR will extract the image into the jdtls plugin folder and replace the html img tag 'src' attribute with the new path.

Image extraction works, regular paths work too.

No tests.

Need to figure out how to get path of source jar.

Fixes redhat-developer/vscode-java#1007

@eclipse-ls-bot
Copy link

Can one of the admins verify this patch?

@fbricon
Copy link
Contributor

fbricon commented Aug 1, 2019

add to whitelist

@fbricon fbricon requested a review from snjeza August 1, 2019 21:07
@NikolasKomonen
Copy link
Contributor Author

@fbricon
@snjeza I was told you'd be able to help. I'm trying to get access to the jar files.

This is how I did it for the javadoc jar https://github.com/eclipse/eclipse.jdt.ls/pull/1138/files#diff-b3a48af05d56183bee79e67754caeb7aR136

Am I on the right track, and how would I do it for the source jar? Thanks.

@NikolasKomonen
Copy link
Contributor Author

NikolasKomonen commented Aug 1, 2019

@fbricon

add to whitelist

I removed it from the whitelist to allow for absolute local paths to work as well, but I realised that case won't happen. Will revert it.

Also still need to handle some URI/OS specific path things. You don't have to check those things yet.

@fbricon
Copy link
Contributor

fbricon commented Aug 1, 2019

@NikolasKomonen "add to whitelist" is a command to add you to Jenkins' whitelist, so that your PRs are automatically built ;-)

@snjeza
Copy link
Contributor

snjeza commented Aug 1, 2019

test this please

Copy link
Contributor

@snjeza snjeza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested https://github.com/reactor/reactor-core and get the following error:

[Error - 12:15:21 AM] Aug 2, 2019 12:15:21 AM Error computing hover
null
java.lang.NullPointerException
	at java.io.File.<init>(File.java:277)
	at java.util.jar.JarFile.<init>(JarFile.java:103)
	at org.eclipse.jdt.ls.core.internal.javadoc.JavaDocHTMLPathHandler.getValidatedHTMLSrcAttribute(JavaDocHTMLPathHandler.java:149)
	at org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2.handleContentElements(JavadocContentAccess2.java:1465)
	at org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2.handleContentElements(JavadocContentAccess2.java:1436)
	at org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2.elementToHTML(JavadocContentAccess2.java:1095)
	at org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2.toHTML(JavadocContentAccess2.java:934)
	at org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2.javadoc2HTML(JavadocContentAccess2.java:845)
	at org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2.getHTMLContentFromSource(JavadocContentAccess2.java:729)
	at org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2.getHTMLContent(JavadocContentAccess2.java:587)
	at org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2.getMarkdownContentReader(JavadocContentAccess2.java:2498)
	at org.eclipse.jdt.ls.core.internal.HoverInfoProvider.computeJavadoc(HoverInfoProvider.java:252)
	at org.eclipse.jdt.ls.core.internal.HoverInfoProvider.computeHover(HoverInfoProvider.java:133)
	at org.eclipse.jdt.ls.core.internal.handlers.HoverHandler.computeHover(HoverHandler.java:50)
	at org.eclipse.jdt.ls.core.internal.handlers.HoverHandler.hover(HoverHandler.java:39)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$6(JDTLanguageServer.java:514)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$41(JDTLanguageServer.java:909)
	at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:602)
	at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
	at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:443)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

@NikolasKomonen You can explore org.eclipse.jdt.ui.StandardJavaElementContentProvider

@NikolasKomonen
Copy link
Contributor Author

@fbricon

"add to whitelist" is a command to add you to Jenkins' whitelist

oh haha, guess theres more than one

@snjeza

Thanks for the info, I'll look into it.
Also this pr is not fully done yet but I will have tests in the actual PR

@NikolasKomonen NikolasKomonen force-pushed the javadocImageFix branch 2 times, most recently from d832f45 to b36522e Compare August 8, 2019 20:29
@snjeza
Copy link
Contributor

snjeza commented Aug 9, 2019

test failure in https://ci.eclipse.org/ls/job/jdt-ls-pr/1551/testReport/org.eclipse.jdt.ls.core.internal.javadoc/JavaDocImageExtractionTest/testImageExtraction/

@NikolasKomonen you can try the following:

diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/javadoc/JavaDocImageExtractionTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/javadoc/JavaDocImageExtractionTest.java
index 112275bc..735845b7 100644
--- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/javadoc/JavaDocImageExtractionTest.java
+++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/javadoc/JavaDocImageExtractionTest.java
@@ -20,11 +20,18 @@ import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.core.IClassFile;
 import org.eclipse.jdt.core.ICompilationUnit;
 import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.core.BinaryType;
 import org.eclipse.jdt.ls.core.internal.HoverInfoProvider;
 import org.eclipse.jdt.ls.core.internal.IConstants;
 import org.eclipse.jdt.ls.core.internal.JDTUtils;
+import org.eclipse.jdt.ls.core.internal.JobHelpers;
+import org.eclipse.jdt.ls.core.internal.SourceContentProvider;
 import org.eclipse.jdt.ls.core.internal.WorkspaceHelper;
 import org.eclipse.jdt.ls.core.internal.managers.AbstractMavenBasedTest;
 import org.eclipse.lsp4j.MarkedString;
@@ -56,6 +63,14 @@ public class JavaDocImageExtractionTest extends AbstractMavenBasedTest {
        public void setup() throws Exception {
                importProjects("maven/javadoctest");
                project = WorkspaceHelper.getProject("javadoctest");
+               IJavaProject javaProject = JavaCore.create(project);
+               IType type = javaProject.findType("reactor.core.publisher.Mono");
+               IClassFile classFile = ((BinaryType) type).getClassFile();
+               String source = new SourceContentProvider().getSource(classFile, new NullProgressMonitor());
+               if (source == null) {
+                       JobHelpers.waitForDownloadSourcesJobs(JobHelpers.MAX_TIME_MILLIS);
+                       source = new SourceContentProvider().getSource(classFile, new NullProgressMonitor());
+               }
        }
 
        @Test

See https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupportTest.java#L162

@snjeza
Copy link
Contributor

snjeza commented Aug 9, 2019

@NikolasKomonen you should also test the source package fragments:

git clone git@github.com:reactor/reactor-core.git
cd reactor-core
code .
# open Mono.java
# hover over Mono.error(Throwable error)

You will get an exception.

@NikolasKomonen NikolasKomonen force-pushed the javadocImageFix branch 5 times, most recently from 08cf8ce to 7d6b2ab Compare August 14, 2019 19:21
@NikolasKomonen NikolasKomonen marked this pull request as ready for review August 14, 2019 19:44
@NikolasKomonen
Copy link
Contributor Author

@snjeza I've fixed the issues with this PR. Would you be able to check this when you have time?

@NikolasKomonen NikolasKomonen force-pushed the javadocImageFix branch 2 times, most recently from 96ce7d3 to 28786ae Compare August 22, 2019 15:45
@NikolasKomonen
Copy link
Contributor Author

@fbricon Updated and tested on Windows as well.

@fbricon
Copy link
Contributor

fbricon commented Sep 9, 2019

Still doesn't work, testing io.projectreactor:reactor-core:3.2.10.RELEASE or the latest one. It seems the parsing is thrown off by a leading <p> before the <img` tag.
Screen Shot 2019-09-09 at 5 07 30 PM

@fbricon
Copy link
Contributor

fbricon commented Sep 10, 2019

still doesn't work on my mac. It used to work, in your previous patches. Might be some change in the way javadoc is computed/sent to the new code, which breaks it

@fbricon
Copy link
Contributor

fbricon commented Sep 11, 2019

doesn't work on my linux box either. Tested with a bunch of reactor-core versions.
@snjeza does it work for you?

@snjeza
Copy link
Contributor

snjeza commented Sep 11, 2019

@snjeza does it work for you?

No, it doesn't.

@fbricon
Copy link
Contributor

fbricon commented Sep 11, 2019

@NikolasKomonen so it works when hovering over Mono.error for instance, but not when hovering over Mono. As I've shown on the previous image, this is caused by the javadoc elements being split differently. eg. If the node under consideration starts with <img, it works, else if you have <p><img, it doesn't.

@snjeza
Copy link
Contributor

snjeza commented Sep 12, 2019

I have faced the following issue:

Not allowed to load local resource: file:///home/snjeza/runtime-JDT-LS/.metadata/.plugins/org.eclipse.jdt.ls.core/extracted-jar-images/reactor-core-3.2.11.RELEASE/mono.svg

See microsoft/vscode#45260 (comment)
"Disable: Allow all content and script execution. Not Recommended" doesn't help.

@NikolasKomonen
Copy link
Contributor Author

NikolasKomonen commented Sep 16, 2019

@snjeza I'm not able to re-create your issue. Was it always happening or did it appear randomly?

Also, are you running the most recent (August) Vscode version?

@snjeza
Copy link
Contributor

snjeza commented Sep 16, 2019

I'm not able to re-create your issue. Was it always happening or did it appear randomly?

testmd

@NikolasKomonen
Copy link
Contributor Author

NikolasKomonen commented Sep 16, 2019

@snjeza Ok I see the issue and can recreate it, but are you having the same issue with loading the image on hover? It could be that the permissions are different for language server hovers compared to using the mardown preview feature.

@fbricon
Copy link
Contributor

fbricon commented Sep 16, 2019

I have faced the following issue:

Not allowed to load local resource: file:///home/snjeza/runtime-JDT-LS/.metadata/.plugins/org.eclipse.jdt.ls.core/extracted-jar-images/reactor-core-3.2.11.RELEASE/mono.svg

I can't reproduce that, I'm using the latest VS Code insiders.

I still see the problem of the missing image when hovering on Mono though

@fbricon
Copy link
Contributor

fbricon commented Sep 16, 2019

oh but I can reproduce it in regular vscode.

@snjeza
Copy link
Contributor

snjeza commented Sep 16, 2019

Ok I see the issue and can recreate it, but are you having the same issue with loading the image on hover?

Yes, I am.

It works now.

@snjeza
Copy link
Contributor

snjeza commented Sep 16, 2019

I can't reproduce that, I'm using the latest VS Code insiders.

testmd2

This PR solves the issue when the image linked in the javadoc points to a location inside the jar.

Fixes eclipse-jdtls#1007

Signed-off-by: Nikolas Komonen <nikolaskomonen@gmail.com>
@fbricon fbricon merged commit 247107d into eclipse-jdtls:master Sep 17, 2019
@fbricon
Copy link
Contributor

fbricon commented Sep 17, 2019

Thanks @NikolasKomonen !

@fbricon fbricon changed the title Working on javadoc image fix Extract embedded javadoc images Sep 17, 2019
@fbricon fbricon added the bug label Sep 17, 2019
@fbricon fbricon added this to the Mid September 2019 milestone Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken images in javadoc when images are included in source JAR
4 participants