Skip to content

Commit 9ebb2ac

Browse files
committed
Use launch.json in Debug Lens sessions.
Add the possibility to use existing configurations via Debug Lens
1 parent e914d62 commit 9ebb2ac

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

editors/code/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,11 @@
443443
"type": "object",
444444
"default": {},
445445
"description": "Optional settings passed to the debug engine. Example:\n{ \"lldb\": { \"terminal\":\"external\"} }"
446+
},
447+
"rust-analyzer.debug.useLaunchJson": {
448+
"description": "Whether to use existing configurations from launch.json.",
449+
"type": "boolean",
450+
"default": false
446451
}
447452
}
448453
},

editors/code/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export class Config {
117117
engineSettings: this.get<object>("debug.engineSettings"),
118118
openUpDebugPane: this.get<boolean>("debug.openUpDebugPane"),
119119
sourceFileMap: sourceFileMap,
120+
useLaunchJson: this.get<object>("debug.useLaunchJson"),
120121
};
121122
}
122123
}

editors/code/src/debug.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,27 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom
9595
}
9696

9797
export async function startDebugSession(ctx: Ctx, config: ra.Runnable): Promise<boolean> {
98-
const debugConfig = await getDebugConfiguration(ctx, config);
98+
let debugConfig: vscode.DebugConfiguration | undefined = undefined;
99+
let message = "";
100+
101+
if (ctx.config.debug.useLaunchJson) {
102+
const wsLaunchSection = vscode.workspace.getConfiguration("launch");
103+
const configurations = wsLaunchSection.get<any[]>("configurations") || [];
104+
105+
const index = configurations.findIndex(c => c.name === config.label);
106+
if (-1 !== index) {
107+
debugConfig = configurations[index];
108+
message = " (from launch.json)";
109+
debugOutput.clear();
110+
}
111+
}
112+
if (!debugConfig) {
113+
debugConfig = await getDebugConfiguration(ctx, config);
114+
}
115+
99116
if (!debugConfig) return false;
100117

101-
debugOutput.appendLine("Launching debug configuration:");
118+
debugOutput.appendLine(`Launching debug configuration${message}:`);
102119
debugOutput.appendLine(JSON.stringify(debugConfig, null, 2));
103120
return vscode.debug.startDebugging(undefined, debugConfig);
104121
}

0 commit comments

Comments
 (0)