javavscode icon indicating copy to clipboard operation
javavscode copied to clipboard

Add `Run main | Debug main` codelens for compact source files (update project structures for JEP 512?)

Open physcrowley opened this issue 2 months ago • 1 comments

This extension works better than others with the most recent JDKs, but it doesn't handle the new folder structures that are now possible with Compact Source Files being a standard Java feature as per JEP 512.

Context

I want to write a standalone hello world program, and other like it, according to JEP 512. I expect students to write many such files in the root folder (anonymous package) and to create many such files in my own demo folder.

void main() {
    IO.println("Hello world!");
}
void main() {
    var currentDir = new File(".");
    var filesList = new ArrayList<File>();
    for (File f : currentDir.listFiles()) {
        if (f.getName().endsWith(".md")) {
            filesList.add(f);
        }
    }
    IO.println(filesList);
}

Expected behaviour

  • [x] Autocompletion after typing IO. (and other classes)
  • [x] Implicit java.util and java.io module imports
  • [ ] View options to run or debug in the editor and on top of the void main() declaration

Issue with current behaviour

Instead of launch options, there is a warning on main saying main is never used.

Request

Recognise this new type of valid single-file, standalone program correctly:

  • No "never used" warning on instance main method in compact source files
  • Run and debug options appear as expected for compact source files in the root folder (anonymous package)
  • (If possible as a bonus side-effect) Command Palette > Java: New File from Template... --> Compact source file snippet available (void main() {})

Current workaround

I will simply have students run java [filename] in the integrated terminal as before.

If there is no change before ~March, I will probably go back to the "Java Extension Pack" once they release JavaSE-25 support <-- I would like to avoid this if possible: this extension is WAAAAAAY more appropriate for new programmers.

physcrowley avatar Sep 21 '25 13:09 physcrowley

Hi @physcrowley. Thank you for your feedback.

An upcoming major version of the extension will show the codelens for compact source files.

In the interim, either of the following workarounds maybe used to run compact source files:

  1. Use the --enable-preview flag in the run configuration VM options.
    • This will add the Run main | Debug main codelens for compact source files.
  2. Launch the programs using the Run and Debug panel button.

Thank you.

sid-srini avatar Sep 27 '25 09:09 sid-srini