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

Run Configuration section is unavailable in the Explorer panel for non-workspace opened Java files #196

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 Explorer panel does not show, nor does it give an option to display, the Run Configuration section.

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 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.
  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 Run main | Debug main action shortcut above the main method in the Java file.
    • This shortcut shows only when the extension setting for Editor: Enable Shortcuts is turned on.
  5. Check the Explorer panel for the Run Configuration section in order to add arguments, etc. for the application Run/Debug
    • It is not available Screenshot 2024-07-18 at 12 59 22 PM

Impact

It is not possible to supply custom arguments, VM options, environment variables etc. to the Java application that would be launched when using the Run main | Debug main editor hint actions.

Workaround

  1. Use the Run menu Add Configurations action to open the settings.json file and launch the application only via the Run menu.
    • Here add or edit a Java+: Launch Java Application configuration (ctrl+space shortcut on MacOS).
    • Add JSON key and values as needed:
      • args for arguments
      • vmArgs for VM options
      • env for environment variables
  2. Alternatively, Open the folder (or the multi-folder code-workspace file) containing the main Java file, before editing or attempting to run/debug the application or test it contains.

Fix Request

The Run Configuration section should be made available in the VSCode Explorer panel for non-workspace opened Java files too. This will help in quickly running single file Java code without setting up a separate test folder or workspace, or, perform manual JSON settings editing which only advanced users may do.