vscode-java-debug icon indicating copy to clipboard operation
vscode-java-debug copied to clipboard

Allow 3rd-party extensions to contribute in-memory launch config

Open fbricon opened this issue 2 years ago • 4 comments
trafficstars

Currently, vscode-java-debug searches the .vscode/launch.json file for a launch config matching the classname+project name.

https://github.com/microsoft/vscode-java-debug/blob/415ae57296c10e9ffd2204ab66e22cb9d929259c/src/extension.ts#L450-L459

If none is found, a default config is built in memory:

https://github.com/microsoft/vscode-java-debug/blob/415ae57296c10e9ffd2204ab66e22cb9d929259c/src/extension.ts#L427-L433

I'd like the JBang extension to provide a custom in-memory config, where we can dynamically set the add-opens args for instance, to be able to keep in synch' with the JBang directives in the java file, rather than having to create/update .vscode/launch.json at some point.

Would be nice if vscode-java-debug allowed 3rd-party extension to contribue launch config participants, that, if they match, would then provide a custom in-memory config, if none was found on disk.

See the video at the 4'37" mark and https://twitter.com/fbricon/status/1698735665259626996 for context

cc @maxandersen

fbricon avatar Sep 04 '23 16:09 fbricon

Just like what the editor "Run Java"/"Debug Java" button does, you can construct the config in memory and then use vscode.debug.startDebugging(...) API to invoke Java debugger.

https://github.com/microsoft/vscode-java-debug/blob/415ae57296c10e9ffd2204ab66e22cb9d929259c/src/extension.ts#L425-L439

testforstephen avatar Sep 06 '23 12:09 testforstephen

I already have a "Run JBang" codelens, what I want is to make sure everything works with the "standard" Run button

fbricon avatar Sep 06 '23 13:09 fbricon

Then you can use the vscode.debug.registerDebugConfigurationProvider("java", new JavaDebugConfigurationProvider()) API to register a debug configuration provider for the java id. This will enable you to implement the resolveDebugConfiguration(...) or resolveDebugConfigurationWithSubstitutedVariables(...) method, which can change the launch configuration dynamically. When VS Code launches a java debug session, it will invoke all the registered java debug configuration providers sequentially to resolve the launch configuration. However, the order of invocation may depend on the activation order of the extensions. To ensure that the Java debugger configuration provider is called first, you can register your configuration provider after the Java debugger is activated.

https://github.com/microsoft/vscode-java-debug/blob/415ae57296c10e9ffd2204ab66e22cb9d929259c/src/configurationProvider.ts#L72-L85

testforstephen avatar Sep 06 '23 13:09 testforstephen

mm I'll have to look into it. Thanks

fbricon avatar Sep 06 '23 13:09 fbricon