Java LSP server: Associate a single source file with an available workspace with no client workspace folders in order to obtain the configured options #7609
Java LSP server: Associate a single source file with an available workspace with no client workspace folders in order to obtain the configured options
Issue
When a single-source file is opened in a workspace with no workspace folders, the global workspace options need to be made available to the operations done on that file.
In #7382, SingleFileOptionsQueryImpl introduced search for a single source file's parent in open workspaces' folders.
However, when setConfiguration() is invoked with nullworkDirectory, the options for the workspace are not made available to single-source files which are outside any workspace folders.
The netbeans IDE works around this by inserting 2 entries in the attributes.xml, one for the file and subsequently another one for its parent.
Example ~/Library/Application\ Support/NetBeans/dev/var/attributes.xml
However, the Java VS Code extension cannot achieve the same since the Java LSP server cannot apply this.
Effect
Errors such as those resolved by vmOptions such as --enable-preview or a --source <version> continue to be flagged even when the single-source file can be run successfully.
Example Test.java:
public static void main(String... args) {
System.out.println("Hello");
}
This can be reproduced in the IDE as well if the artificial entry added for the file's parent is removed from the attributes.xml as below:
Java LSP server: Associate a single source file with an available workspace with no client workspace folders in order to obtain the configured options
Issue
SingleFileOptionsQueryImpl
introduced search for a single source file's parent in open workspaces' folders.setConfiguration()
is invoked withnull
workDirectory
, the options for the workspace are not made available to single-source files which are outside any workspace folders.Effect
Errors such as those resolved by vmOptions such as
--enable-preview
or a--source <version>
continue to be flagged even when the single-source file can be run successfully.Fix
SingleFileOptionsQueryImpl.optionsFor()
:SingleFileOptionsQueryImplTest
.