mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
Configuration settings and source maps support
This commit is contained in:
parent
48d6e828f1
commit
042917e6e3
4 changed files with 52 additions and 10 deletions
|
@ -388,6 +388,25 @@
|
|||
"description": "Enable Proc macro support, cargo.loadOutDirsFromCheck must be enabled.",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"rust-analyzer.debug.engine": {
|
||||
"type": [
|
||||
"null",
|
||||
"string"
|
||||
],
|
||||
"enum": [
|
||||
"ms-vscode.cpptools",
|
||||
"vadimcn.vscode-lldb"
|
||||
],
|
||||
"default": null,
|
||||
"description": "Preffered debug engine."
|
||||
},
|
||||
"rust-analyzer.debug.sourceFileMap" : {
|
||||
"type":"object",
|
||||
"description": "Optional source file mappings passed to the debug engine.",
|
||||
"default": {
|
||||
"<source-path>": "<target-path>"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { window } from 'vscode';
|
||||
import * as cp from 'child_process';
|
||||
import * as readline from 'readline';
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ export function runSingle(ctx: Ctx): Cmd {
|
|||
};
|
||||
}
|
||||
|
||||
function getLldbDebugConfig(config: ra.Runnable) : vscode.DebugConfiguration {
|
||||
function getLldbDebugConfig(config: ra.Runnable, sourceFileMap: Record<string, string>): vscode.DebugConfiguration {
|
||||
return {
|
||||
type: "lldb",
|
||||
request: "launch",
|
||||
|
@ -72,11 +72,12 @@ function getLldbDebugConfig(config: ra.Runnable) : vscode.DebugConfiguration {
|
|||
args: config.args,
|
||||
},
|
||||
args: config.extraArgs,
|
||||
cwd: config.cwd
|
||||
cwd: config.cwd,
|
||||
sourceMap: sourceFileMap
|
||||
};
|
||||
}
|
||||
|
||||
async function getCppvsDebugConfig(config: ra.Runnable) : Promise<vscode.DebugConfiguration> {
|
||||
async function getCppvsDebugConfig(config: ra.Runnable, sourceFileMap: Record<string, string>): Promise<vscode.DebugConfiguration> {
|
||||
let cargo = new Cargo(config.cwd || '.');
|
||||
let executable = await cargo.executableFromArgs(config.args, config.extraArgs);
|
||||
|
||||
|
@ -87,6 +88,7 @@ async function getCppvsDebugConfig(config: ra.Runnable) : Promise<vscode.DebugCo
|
|||
program: executable,
|
||||
args: config.extraArgs,
|
||||
cwd: config.cwd,
|
||||
sourceFileMap: sourceFileMap,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -95,15 +97,30 @@ export function debugSingle(ctx: Ctx): Cmd {
|
|||
const editor = ctx.activeRustEditor;
|
||||
if (!editor) return;
|
||||
|
||||
const mscpp = vscode.extensions.getExtension("ms-vscode.cpptools");
|
||||
const lldb = vscode.extensions.getExtension("vadimcn.vscode-lldb");
|
||||
const lldbId = "vadimcn.vscode-lldb";
|
||||
const cpptoolsId = "ms-vscode.cpptools";
|
||||
|
||||
if (!(lldb || mscpp)) {
|
||||
vscode.window.showErrorMessage("Install `vadimcn.vscode-lldb` or `ms-vscode.cpptools` extension for debugging");
|
||||
let debugEngineId = ctx.config.debug.engine;
|
||||
let debugEngine = null;
|
||||
if (!debugEngineId) {
|
||||
debugEngine = vscode.extensions.getExtension(lldbId);
|
||||
if (!debugEngine) {
|
||||
debugEngine = vscode.extensions.getExtension(cpptoolsId);
|
||||
}
|
||||
}
|
||||
else {
|
||||
debugEngine = vscode.extensions.getExtension(debugEngineId);
|
||||
}
|
||||
|
||||
if (!debugEngine) {
|
||||
vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${lldbId})`
|
||||
+ ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${cpptoolsId}) extension for debugging.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const debugConfig = lldb ? getLldbDebugConfig(config) : await getCppvsDebugConfig(config);
|
||||
const debugConfig = lldbId == debugEngine.id
|
||||
? getLldbDebugConfig(config, ctx.config.debug.sourceFileMap)
|
||||
: await getCppvsDebugConfig(config, ctx.config.debug.sourceFileMap);
|
||||
|
||||
return vscode.debug.startDebugging(undefined, debugConfig);
|
||||
};
|
||||
|
|
|
@ -92,7 +92,6 @@ export class Config {
|
|||
get askBeforeDownload() { return this.get<boolean>("updates.askBeforeDownload"); }
|
||||
get traceExtension() { return this.get<boolean>("trace.extension"); }
|
||||
|
||||
|
||||
get inlayHints() {
|
||||
return {
|
||||
typeHints: this.get<boolean>("inlayHints.typeHints"),
|
||||
|
@ -107,4 +106,12 @@ export class Config {
|
|||
command: this.get<string>("checkOnSave.command"),
|
||||
};
|
||||
}
|
||||
|
||||
get debug() {
|
||||
return {
|
||||
engine: this.get<null | string>("debug.engine"),
|
||||
sourceFileMap: this.get<Record<string, string>>("debug.sourceFileMap"),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue