eclipse.jdt.ls icon indicating copy to clipboard operation
eclipse.jdt.ls copied to clipboard

Set path for the invisible project

Open abed-roid opened this issue 4 years ago • 6 comments

Hello,

I didn't find any documentation related to how/when an invisible project is created, is there any way to know or set the path of the invisible project or maybe skip the invisible project and just stick to the original project?

  1. Add a new file to the original project, the invisible project is not updated unless 'textDocument/didOpen' request is sent for that particular file, there is some kind of caching that needs invalidation.
  2. Add a library to the 'lib' folder of the original project, the invisible project is not updated unless it's recreated again by the language server after I delete it.

Thank you.

abed-roid avatar May 31 '21 14:05 abed-roid

Workaround for this is to delete the folder **/.metadata/.plugins/org.eclipse.core.resources, the .classpath updates, and the invisible project is recreated automatically at the language server next launch.

Not an ideal solution though.

abed-roid avatar May 31 '21 18:05 abed-roid

You can run Java: Clean the Java language server workspace and click Restart and delete. See Clean the workspace directory

snjeza avatar May 31 '21 18:05 snjeza

I am not using Visual Studio Code :), trying to integrate Java Language Server with an IDE.

The communication with the Java Language Server is done through a client socket using Language Server Protocol requests.

abed-roid avatar May 31 '21 18:05 abed-roid

I believe the general rule is if a project is not recognized as a Gradle, Maven, or an Eclipse project, then it will be imported as an "Invisible" project. This is essentially an Eclipse project with the underlying metadata hidden from users. This uses some basic assumptions about the location of source paths / libraries to produce a project that can be supported by the language support. We do have https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/plugin.xml#L111-L130 that allows extending supported projects.

Regarding the actions (add file, add library) that don't seem to update the project : Have you tried modifying java.project.sourcePaths, java.project.referencedLibraries and sending a didChangeConfiguration(..) with the new values ? See https://github.com/redhat-developer/vscode-java#supported-vs-code-settings . They're listed on vscode-java but the properties are supported in the language server.

I don't think we have any commands on the language server side that would clean out the workspace storage folder as requested by a client.

rgrunber avatar Jun 01 '21 15:06 rgrunber

The hover now shows documentation after attaching the library sources to the .classpath of the original project, by inserting sourcepath into the classpathentry of the target library:

<classpathentry kind="lib" path="lib/gson-2.8.6.jar" sourcepath="lib/gson-2.8.6-sources.jar"/>

Requesting workspace/didChangeWorkspaceFolders on the project directory was key for the server to reload the .classpath file and recognize the changes accordingly.

I made several tests on changing configuration with workspace/didChangeConfiguration, java.project.sourcePaths, and java.project.referencedLibraries, and turned out that it has no effect. Though, I've received log messages from the server acknowledging the configuration changes.

abed-roid avatar Jun 02 '21 00:06 abed-roid

Although this may work, I don't think this is the right approach. Generally the .classpath file should only be modified by the language server itself using calls from the client side. There's no guarantee any changes made directly to .classpath would persist.

If it helps at all, I took a simple project and added java.project.referencedLibraries = [ "lib/gson-2.8.6.jar" ] and looked at what the client/server interaction. I've trimmed out some unnecessary things but this is what I saw : https://pastebin.com/PpNTuuLG

rgrunber avatar Jun 10 '21 03:06 rgrunber