Skip to content

Commit f1fa9aa

Browse files
bors[bot]vsrs
andauthored
Merge #4366
4366: Unified debug lens r=matklad a=vsrs Right now every debug engine gets the debug executable and exports the errors on its own. This PR unifies the way all engines work. And adds an option to configure each engine separably. For example, this adds visualizers for both `CodeLLDB` and `C++ tools Windows debugger` ```json "rust-analyzer.debug.engineSettings": { "cppvsdbg": { "visualizerFile": "${workspaceRoot}/rdisk.natvis" }, "lldb": { "initCommands": [ "command script import ${workspaceRoot}/rdisk.vis.py" ] } } ``` Co-authored-by: vsrs <vit@conrlab.com> Co-authored-by: vsrs <62505555+vsrs@users.noreply.github.com>
2 parents d81e192 + 0ef17ef commit f1fa9aa

File tree

3 files changed

+60
-32
lines changed

3 files changed

+60
-32
lines changed

editors/code/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,16 @@
423423
"default": {
424424
"/rustc/<id>": "${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust"
425425
}
426+
},
427+
"rust-analyzer.debug.openDebugPane": {
428+
"description": "Whether to open up the Debug Pane on debugging start.",
429+
"type": "boolean",
430+
"default": false
431+
},
432+
"rust-analyzer.debug.engineSettings": {
433+
"type": "object",
434+
"default": {},
435+
"description": "Optional settings passed to the debug engine. Example:\n{ \"lldb\": { \"terminal\":\"external\"} }"
426436
}
427437
}
428438
},

editors/code/src/commands/runnables.ts

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,20 @@ export function runSingle(ctx: Ctx): Cmd {
6464
};
6565
}
6666

67-
function getLldbDebugConfig(config: ra.Runnable, sourceFileMap: Record<string, string>): vscode.DebugConfiguration {
67+
function getLldbDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration {
6868
return {
6969
type: "lldb",
7070
request: "launch",
7171
name: config.label,
72-
cargo: {
73-
args: config.args,
74-
},
72+
program: executable,
7573
args: config.extraArgs,
7674
cwd: config.cwd,
77-
sourceMap: sourceFileMap
75+
sourceMap: sourceFileMap,
76+
sourceLanguages: ["rust"]
7877
};
7978
}
8079

81-
const debugOutput = vscode.window.createOutputChannel("Debug");
82-
83-
async function getCppvsDebugConfig(config: ra.Runnable, sourceFileMap: Record<string, string>): Promise<vscode.DebugConfiguration> {
84-
debugOutput.clear();
85-
86-
const cargo = new Cargo(config.cwd || '.', debugOutput);
87-
const executable = await cargo.executableFromArgs(config.args);
88-
89-
// if we are here, there were no compilation errors.
80+
function getCppvsDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration {
9081
return {
9182
type: (os.platform() === "win32") ? "cppvsdbg" : 'cppdbg',
9283
request: "launch",
@@ -98,39 +89,62 @@ async function getCppvsDebugConfig(config: ra.Runnable, sourceFileMap: Record<st
9889
};
9990
}
10091

92+
const debugOutput = vscode.window.createOutputChannel("Debug");
93+
94+
async function getDebugExecutable(config: ra.Runnable): Promise<string> {
95+
const cargo = new Cargo(config.cwd || '.', debugOutput);
96+
const executable = await cargo.executableFromArgs(config.args);
97+
98+
// if we are here, there were no compilation errors.
99+
return executable;
100+
}
101+
102+
type DebugConfigProvider = (config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>) => vscode.DebugConfiguration;
103+
101104
export function debugSingle(ctx: Ctx): Cmd {
102105
return async (config: ra.Runnable) => {
103106
const editor = ctx.activeRustEditor;
104107
if (!editor) return;
105108

106-
const lldbId = "vadimcn.vscode-lldb";
107-
const cpptoolsId = "ms-vscode.cpptools";
109+
const knownEngines: Record<string, DebugConfigProvider> = {
110+
"vadimcn.vscode-lldb": getLldbDebugConfig,
111+
"ms-vscode.cpptools": getCppvsDebugConfig
112+
};
113+
const debugOptions = ctx.config.debug;
108114

109-
const debugEngineId = ctx.config.debug.engine;
110115
let debugEngine = null;
111-
if (debugEngineId === "auto") {
112-
debugEngine = vscode.extensions.getExtension(lldbId);
113-
if (!debugEngine) {
114-
debugEngine = vscode.extensions.getExtension(cpptoolsId);
116+
if (debugOptions.engine === "auto") {
117+
for (var engineId in knownEngines) {
118+
debugEngine = vscode.extensions.getExtension(engineId);
119+
if (debugEngine) break;
115120
}
116121
}
117122
else {
118-
debugEngine = vscode.extensions.getExtension(debugEngineId);
123+
debugEngine = vscode.extensions.getExtension(debugOptions.engine);
119124
}
120125

121126
if (!debugEngine) {
122-
vscode.window.showErrorMessage(
123-
`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${lldbId}) ` +
124-
`or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${cpptoolsId}) ` +
125-
`extension for debugging.`
126-
);
127+
vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)`
128+
+ ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension for debugging.`);
127129
return;
128130
}
129131

130-
const debugConfig = lldbId === debugEngine.id
131-
? getLldbDebugConfig(config, ctx.config.debug.sourceFileMap)
132-
: await getCppvsDebugConfig(config, ctx.config.debug.sourceFileMap);
132+
debugOutput.clear();
133+
if (ctx.config.debug.openUpDebugPane) {
134+
debugOutput.show(true);
135+
}
136+
137+
const executable = await getDebugExecutable(config);
138+
const debugConfig = knownEngines[debugEngine.id](config, executable, debugOptions.sourceFileMap);
139+
if (debugConfig.type in debugOptions.engineSettings) {
140+
const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type];
141+
for (var key in settingsMap) {
142+
debugConfig[key] = settingsMap[key];
143+
}
144+
}
133145

146+
debugOutput.appendLine("Launching debug configuration:");
147+
debugOutput.appendLine(JSON.stringify(debugConfig, null, 2));
134148
return vscode.debug.startDebugging(undefined, debugConfig);
135149
};
136150
}

editors/code/src/config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,14 @@ export class Config {
109109
}
110110

111111
get debug() {
112+
// "/rustc/<id>" used by suggestions only.
113+
const { ["/rustc/<id>"]: _, ...sourceFileMap } = this.get<Record<string, string>>("debug.sourceFileMap");
114+
112115
return {
113116
engine: this.get<string>("debug.engine"),
114-
sourceFileMap: this.get<Record<string, string>>("debug.sourceFileMap"),
117+
engineSettings: this.get<object>("debug.engineSettings"),
118+
openUpDebugPane: this.get<boolean>("debug.openUpDebugPane"),
119+
sourceFileMap: sourceFileMap,
115120
};
116121
}
117-
118122
}

0 commit comments

Comments
 (0)