apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.62k stars 840 forks source link

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

Closed sid-srini closed 1 month ago

sid-srini commented 1 month ago

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

  1. 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 null workDirectory, the options for the workspace are not made available to single-source files which are outside any workspace folders.
  2. 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
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE attributes PUBLIC "-//NetBeans//DTD DefaultAttributes 1.0//EN" "http://www.netbeans.org/dtds/attributes-1_0.dtd">
      <attributes version="1.0">
      <fileobject name="|path|to|single|file">
          <attr name="single_file_vm_options" stringvalue="--enable-preview --source 23"/>
      </fileobject>
      <fileobject name="|path|to|single|file|Test.java">
          <attr name="single_file_vm_options" stringvalue="--enable-preview --source 23"/>
      </fileobject>
      </attributes>
  3. 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.

Fix

  1. Fixed SingleFileOptionsQueryImpl.optionsFor():
    • to: associate a single-source file's parent with a workspace having no client workspace folders,
    • when: it has no associated workspace folder.
  2. Updated the associated unit tests in SingleFileOptionsQueryImplTest.
sid-srini commented 1 month ago

Labels requested: Java LSP VS Code Extension