mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
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>
This commit is contained in:
commit
f1fa9aa4c4
3 changed files with 60 additions and 32 deletions
|
@ -423,6 +423,16 @@
|
||||||
"default": {
|
"default": {
|
||||||
"/rustc/<id>": "${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust"
|
"/rustc/<id>": "${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"rust-analyzer.debug.openDebugPane": {
|
||||||
|
"description": "Whether to open up the Debug Pane on debugging start.",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
|
"rust-analyzer.debug.engineSettings": {
|
||||||
|
"type": "object",
|
||||||
|
"default": {},
|
||||||
|
"description": "Optional settings passed to the debug engine. Example:\n{ \"lldb\": { \"terminal\":\"external\"} }"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -64,29 +64,20 @@ export function runSingle(ctx: Ctx): Cmd {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLldbDebugConfig(config: ra.Runnable, sourceFileMap: Record<string, string>): vscode.DebugConfiguration {
|
function getLldbDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration {
|
||||||
return {
|
return {
|
||||||
type: "lldb",
|
type: "lldb",
|
||||||
request: "launch",
|
request: "launch",
|
||||||
name: config.label,
|
name: config.label,
|
||||||
cargo: {
|
program: executable,
|
||||||
args: config.args,
|
|
||||||
},
|
|
||||||
args: config.extraArgs,
|
args: config.extraArgs,
|
||||||
cwd: config.cwd,
|
cwd: config.cwd,
|
||||||
sourceMap: sourceFileMap
|
sourceMap: sourceFileMap,
|
||||||
|
sourceLanguages: ["rust"]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const debugOutput = vscode.window.createOutputChannel("Debug");
|
function getCppvsDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration {
|
||||||
|
|
||||||
async function getCppvsDebugConfig(config: ra.Runnable, sourceFileMap: Record<string, string>): Promise<vscode.DebugConfiguration> {
|
|
||||||
debugOutput.clear();
|
|
||||||
|
|
||||||
const cargo = new Cargo(config.cwd || '.', debugOutput);
|
|
||||||
const executable = await cargo.executableFromArgs(config.args);
|
|
||||||
|
|
||||||
// if we are here, there were no compilation errors.
|
|
||||||
return {
|
return {
|
||||||
type: (os.platform() === "win32") ? "cppvsdbg" : 'cppdbg',
|
type: (os.platform() === "win32") ? "cppvsdbg" : 'cppdbg',
|
||||||
request: "launch",
|
request: "launch",
|
||||||
|
@ -98,39 +89,62 @@ async function getCppvsDebugConfig(config: ra.Runnable, sourceFileMap: Record<st
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const debugOutput = vscode.window.createOutputChannel("Debug");
|
||||||
|
|
||||||
|
async function getDebugExecutable(config: ra.Runnable): Promise<string> {
|
||||||
|
const cargo = new Cargo(config.cwd || '.', debugOutput);
|
||||||
|
const executable = await cargo.executableFromArgs(config.args);
|
||||||
|
|
||||||
|
// if we are here, there were no compilation errors.
|
||||||
|
return executable;
|
||||||
|
}
|
||||||
|
|
||||||
|
type DebugConfigProvider = (config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>) => vscode.DebugConfiguration;
|
||||||
|
|
||||||
export function debugSingle(ctx: Ctx): Cmd {
|
export function debugSingle(ctx: Ctx): Cmd {
|
||||||
return async (config: ra.Runnable) => {
|
return async (config: ra.Runnable) => {
|
||||||
const editor = ctx.activeRustEditor;
|
const editor = ctx.activeRustEditor;
|
||||||
if (!editor) return;
|
if (!editor) return;
|
||||||
|
|
||||||
const lldbId = "vadimcn.vscode-lldb";
|
const knownEngines: Record<string, DebugConfigProvider> = {
|
||||||
const cpptoolsId = "ms-vscode.cpptools";
|
"vadimcn.vscode-lldb": getLldbDebugConfig,
|
||||||
|
"ms-vscode.cpptools": getCppvsDebugConfig
|
||||||
|
};
|
||||||
|
const debugOptions = ctx.config.debug;
|
||||||
|
|
||||||
const debugEngineId = ctx.config.debug.engine;
|
|
||||||
let debugEngine = null;
|
let debugEngine = null;
|
||||||
if (debugEngineId === "auto") {
|
if (debugOptions.engine === "auto") {
|
||||||
debugEngine = vscode.extensions.getExtension(lldbId);
|
for (var engineId in knownEngines) {
|
||||||
if (!debugEngine) {
|
debugEngine = vscode.extensions.getExtension(engineId);
|
||||||
debugEngine = vscode.extensions.getExtension(cpptoolsId);
|
if (debugEngine) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
debugEngine = vscode.extensions.getExtension(debugEngineId);
|
debugEngine = vscode.extensions.getExtension(debugOptions.engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!debugEngine) {
|
if (!debugEngine) {
|
||||||
vscode.window.showErrorMessage(
|
vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)`
|
||||||
`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${lldbId}) ` +
|
+ ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension for debugging.`);
|
||||||
`or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${cpptoolsId}) ` +
|
|
||||||
`extension for debugging.`
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const debugConfig = lldbId === debugEngine.id
|
debugOutput.clear();
|
||||||
? getLldbDebugConfig(config, ctx.config.debug.sourceFileMap)
|
if (ctx.config.debug.openUpDebugPane) {
|
||||||
: await getCppvsDebugConfig(config, ctx.config.debug.sourceFileMap);
|
debugOutput.show(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
const executable = await getDebugExecutable(config);
|
||||||
|
const debugConfig = knownEngines[debugEngine.id](config, executable, debugOptions.sourceFileMap);
|
||||||
|
if (debugConfig.type in debugOptions.engineSettings) {
|
||||||
|
const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type];
|
||||||
|
for (var key in settingsMap) {
|
||||||
|
debugConfig[key] = settingsMap[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debugOutput.appendLine("Launching debug configuration:");
|
||||||
|
debugOutput.appendLine(JSON.stringify(debugConfig, null, 2));
|
||||||
return vscode.debug.startDebugging(undefined, debugConfig);
|
return vscode.debug.startDebugging(undefined, debugConfig);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,10 +109,14 @@ export class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
get debug() {
|
get debug() {
|
||||||
|
// "/rustc/<id>" used by suggestions only.
|
||||||
|
const { ["/rustc/<id>"]: _, ...sourceFileMap } = this.get<Record<string, string>>("debug.sourceFileMap");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
engine: this.get<string>("debug.engine"),
|
engine: this.get<string>("debug.engine"),
|
||||||
sourceFileMap: this.get<Record<string, string>>("debug.sourceFileMap"),
|
engineSettings: this.get<object>("debug.engineSettings"),
|
||||||
|
openUpDebugPane: this.get<boolean>("debug.openUpDebugPane"),
|
||||||
|
sourceFileMap: sourceFileMap,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue