oracle / javavscode

Java platform support for Visual Studio Code for full featured Java development (edit-compile-debug & test cycle)
Apache License 2.0
231 stars 31 forks source link

Quick Fix actions are unable to edit `runConfig` options in global settings for non-workspace opened Java files #199

Closed sid-srini closed 3 months ago

sid-srini commented 4 months ago

Summary

When a Java file is opened directly in the VS Code editor, without opening a folder or a workspace file, then the Quick Fix actions, such as Enable Preview Feature, are unable to save the runConfig options in the global settings.

Steps to Reproduce

  1. Do not have VS Code open with a folder or workspace prior to the following steps.
    • Install the Oracle Java extension (I've tried with v. 22.0.1)
  2. Open a Java file containing only a main method directly in VS Code using the Open menu action or from Finder/Explorer.
    • Alternatively, create a New Java file and write a main method.
    • This would require the preview feature of Java 22 to be enabled.
  3. Accept to trust the file or folder request from VS Code, if prompted.
  4. Notice that after analysis by the Java extension, the editor shows:
    • a Problem that: implicitly declared classes are a preview feature and are disabled by default,
    • with a Quick Fix to Enable Preview Feature
    • Screenshot 2024-07-23 at 11 01 58 AM
    • Screenshot 2024-07-23 at 11 03 05 AM
  5. However, on selecting the Quick Fix action, nothing seems to happen.
    • None of the global extension runConfig settings are updated.

Impact

The Quick Fix actions which require modifying the runConfig global extension settings do not seem to run and validation of the Java application continues to fail.

Workaround

Manually edit the global settings with the required changes. Example: "jdk.runConfig.vmOptions": "--source 22 --enable-preview"

Fix Request

The runConfig global settings should get modified by the Quick Fix actions, such as, Enable Preview Feature even for non-workspace opened Java files. This will help in quickly trying out new preview features in single-file Java code without setting up a separate test folder or workspace, or, manually edit settings which only advanced users may do.

sid-srini commented 4 months ago

Additionally, even after using the Workaround given above i.e. manually adding the runConfig settings, the VS Code editor continues to show the same code Problem; although no other issues arise and neither are any Quick Fixes suggested.

This latter behaviour appears to be related to some of the changes done for resolving NetBeans issue #7382. This may be fixed in org.netbeans.modules.java.lsp.server.singlesourcefile.SingleFileOptionsQueryImpl of the netbeans project java.lsp.server, by associating a single source file with any available workspace which has no client workspace folders. NetBeans PR #7609