-
Notifications
You must be signed in to change notification settings - Fork 403
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
Package name not recognized when opening standalone java files #1766
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, change looks good. It looks like this adjusts the root path correctly now prior to passing it to loading the invisible project.
...ipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporter.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Snjezana Peco <[email protected]>
while (!BaseInitHandler.isWorkspaceInitialized()) { | ||
try { | ||
Thread.sleep(100); | ||
} catch (InterruptedException e) { | ||
// ignore and keep waiting | ||
} | ||
} | ||
try { | ||
Job.getJobManager().join(SyntaxInitHandler.JAVA_LS_INITIALIZATION_JOBS, null); | ||
} catch (OperationCanceledException | InterruptedException e) { | ||
logException(e.getMessage(), e); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this support the usage of triggerFiles or is this some separate issue discovered ? I think we should avoid having requests from the client waiting on each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes VS Code calls BuildWorkspaceHandler.buildWorkspace(boolean, IProgressMonitor) before initializing a workspace.
@rgrunber you have try the following:
- clean the Java LS workspace
- create a vscode-java vsix with and without this code
- install the vsix
- unzip wrong-packagename
cd wrong-packagename
code .
https://github.com/snjeza/vscode-test/raw/master/java-0.79.3.vsix includes this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to build the jar and played for a while. Encountered some problems:
When I tried to clean the workspace and restart VS Code. (might be a different issue)
To repro this, you can first set the setting
to the project to open the debug port, and then attach Java Debugger to that project. Meanwhile, set a breakpoint at if (project == null || !project.isAccessible()) {
return ""; // Set breakpoint here
} And then keep doing clean and restart. You may hit the breakpoint after some tries. Since the package name is returned as an empty string, thus the result to infer the source directory is wrong because of the empty package name. It seems that when we clean the workspace, it will also remove the default project, which will make the code fall into the if block that returns an empty package name |
After some deep investigation, there are some more findings. The problem can be divided into the following small pieces. The declared package "mypackage" does not match the expected package ""The repro steps is what I mentioned above, I guess it's caused by removing the default project when clean the workspace storage. The file is not on source path after reload.This is caused by here:
The output path is set to empty string if it's not in the configuration body sent from the client side. But it's initial value is null at first. This difference will invoke Changing the default value to
About persist the triggerFilesSuppose a user has been set the source path setting before, and then he remove that entry in his In that case we originally think the user should be aware of that he can update the source path and the remove action indicates something as |
Related issue - #1010
@jdneo Could you reproduce the issue with https://github.com/snjeza/vscode-test/raw/master/java-0.79.3.vsix |
Ok so (1) has a separate bug if we wish to address it, which just leaves (2) and my complaint about having With the change by @snjeza (whether I use java-0.79.3.vsix or build the latest PR) , I still see the ".. package does not match expected package .." after a few clean/restarts. If I set the I also see this in the logs when the diagnostic is emitted :
For testing I was using a simple Java file with One thing I noticed, is if the error happens after a "Clean Java Language Server Workspace", then if I just "Reload Window", it will load things correctly without errors. Monitoring the contents of |
@rgrunber @jdneo Could you check https://github.com/snjeza/vscode-test/raw/master/java-0.79.4.vsix ? |
0.79.4 works well on my windows machine. Also share some findings from my side. Seems the root cause is that when we handle the try {
Job.getJobManager().join(InitHandler.JAVA_LS_INITIALIZATION_JOBS, null);
} catch (OperationCanceledException | InterruptedException e) {
logException(e.getMessage(), e);
} we use the above code to wait the initialize job finished. Unfortunately, it does not take effect for some reason. (I suspect it's because a new scheduled job is not set to Changing to // It is very interesting since it seems that this issue is there for a long time. 🤔 Anyway, I also upload a fix: #1767. @rgrunber @snjeza Feel free to take a look. And you can just close it if @snjeza has already done the job. |
@@ -68,6 +70,7 @@ | |||
private ListenerList<IPreferencesChangeListener> preferencesChangeListeners; | |||
private IEclipsePreferences eclipsePrefs; | |||
private static Map<String, Template> templates = new LinkedHashMap<>(); | |||
private static Collection<IPath> triggerFiles; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not persist the trigger files. They should be used only once. And only use them to calculate a default source path when initializing a new invisible project.
If the user modifies the source paths in a subsequent action, such as changing the workspace setting java.project.sourcePaths
, we should always follow the user's action to update the source paths.
This means that if the user sets sourcePaths to null, we should just clean up all the source paths. There is no need to fall back and use trigger files to calculate the source paths again. Since the user knows the settings to change the source paths, he/she can change them back if he/she wants.
IPath outputPath = InvisibleProjectImporter.getOutputPath(javaProject, newPreferences.getInvisibleProjectOutputPath(), true /*isUpdate*/); | ||
IClasspathEntry[] classpathEntries = InvisibleProjectImporter.resolveClassPathEntries(javaProject, sourcePaths, excludingPaths, outputPath); | ||
javaProject.setRawClasspath(classpathEntries, outputPath, new NullProgressMonitor()); | ||
InvisibleProjectImporter.updateSourcePaths(javaProject); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will always use the trigger files to update source paths, regardless of the sourcePaths preference. It's a breaking change.
Only if sourcePaths preference is explicitly changed, then need to update source paths. Otherwise, just update project output path directly via javaProject.setOutputLocation.
See @jdneo's PR https://github.com/eclipse/eclipse.jdt.ls/pull/1767/files
See #1767 |
Thanks, we can have a look there. FWIW, your change (java-0.79.4.vsix ) does seem to work for me now and from what I can tell, modifying java.project.sourcePaths is respected, but if there's a solution that avoid touching triggerFiles / waiting on LSP calls, we should go with that. |
Fixes #1764
Signed-off-by: Snjezana Peco [email protected]