Skip to content

Commit

Permalink
feature: Also run plain Java when noDebug from launch.json
Browse files Browse the repository at this point in the history
Previously, if user run code from code lenses they would get a java command running without DAP. However, if they wanted to add parameters and run via launch.json they would run it via DAP.

Now, even if running from configuration we will run with simple java command. One issue here is that we need to start debugger anyway of run via launch.json, but I worked around it by just running echo instead.
  • Loading branch information
tgodzik committed Jul 22, 2024
1 parent 29f92d3 commit 1e28ecf
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export interface DebugDiscoveryParams {
path: string;
path: string | undefined;
mainClass: string | undefined;
buildTarget: string | undefined;
runType: RunType;
args: string[] | undefined;
jvmOptions: string[] | undefined;
env: Map<string, string> | undefined;
envFile: string | undefined;
}

export enum RunType {
Expand Down
41 changes: 33 additions & 8 deletions packages/metals-vscode/src/debugger/scalaDebugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ class ScalaMainConfigProvider implements vscode.DebugConfigurationProvider {
const args: DebugDiscoveryParams = {
path: editor.document.uri.toString(true),
runType: RunType.RunOrTestFile,
buildTarget: undefined,
mainClass: undefined,
args: undefined,
jvmOptions: undefined,
env: undefined,
envFile: undefined,
};
await startDiscovery(debugConfiguration.noDebug, args);
return debugConfiguration;
Expand All @@ -186,15 +192,34 @@ class ScalaDebugServerFactory implements vscode.DebugAdapterDescriptorFactory {
session.configuration.testClass !== undefined ||
session.configuration.hostName !== undefined
) {
const debugSession = await vscode.commands.executeCommand<DebugSession>(
ServerCommands.DebugAdapterStart,
session.configuration
);

if (debugSession === undefined) {
return null;
if (session.configuration.noDebug) {
const args: DebugDiscoveryParams = {
path: undefined,
mainClass: session.configuration.mainClass,
buildTarget: session.configuration.buildTarget,
runType: RunType.Run,
args: session.configuration.args,
jvmOptions: session.configuration.jvmOptions,
env: session.configuration.env,
envFile: session.configuration.envFile,
};
await startDiscovery(session.configuration.noDebug, args);

// This is the only way not to have to run full fledged DAP server
return new vscode.DebugAdapterExecutable("echo", [
'"Running in the task window"',
]);
} else {
return debugServerFromUri(debugSession.uri);
const debugSession = await vscode.commands.executeCommand<DebugSession>(
ServerCommands.DebugAdapterStart,
session.configuration
);

if (debugSession === undefined) {
return null;
} else {
return debugServerFromUri(debugSession.uri);
}
}
}
return null;
Expand Down
12 changes: 12 additions & 0 deletions packages/metals-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,12 @@ function launchMetals(
const args: DebugDiscoveryParams = {
path: editor.document.uri.toString(true),
runType: RunType.RunOrTestFile,
buildTarget: undefined,
mainClass: undefined,
args: undefined,
jvmOptions: undefined,
env: undefined,
envFile: undefined,
};
scalaDebugger.startDiscovery(true, args).then((wasStarted) => {
if (!wasStarted) {
Expand All @@ -854,6 +860,12 @@ function launchMetals(
const args: DebugDiscoveryParams = {
path: editor.document.uri.toString(true),
runType: RunType.TestTarget,
buildTarget: undefined,
mainClass: undefined,
args: undefined,
jvmOptions: undefined,
env: undefined,
envFile: undefined,
};
scalaDebugger.startDiscovery(true, args).then((wasStarted) => {
if (!wasStarted) {
Expand Down

0 comments on commit 1e28ecf

Please sign in to comment.