aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/package.json19
-rw-r--r--editors/code/src/cargo.ts1
-rw-r--r--editors/code/src/commands/runnables.ts33
-rw-r--r--editors/code/src/config.ts9
4 files changed, 52 insertions, 10 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index b8aaa07d8..aa8065171 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -388,6 +388,25 @@
388 "description": "Enable Proc macro support, cargo.loadOutDirsFromCheck must be enabled.", 388 "description": "Enable Proc macro support, cargo.loadOutDirsFromCheck must be enabled.",
389 "type": "boolean", 389 "type": "boolean",
390 "default": false 390 "default": false
391 },
392 "rust-analyzer.debug.engine": {
393 "type": [
394 "null",
395 "string"
396 ],
397 "enum": [
398 "ms-vscode.cpptools",
399 "vadimcn.vscode-lldb"
400 ],
401 "default": null,
402 "description": "Preffered debug engine."
403 },
404 "rust-analyzer.debug.sourceFileMap" : {
405 "type":"object",
406 "description": "Optional source file mappings passed to the debug engine.",
407 "default": {
408 "<source-path>": "<target-path>"
409 }
391 } 410 }
392 } 411 }
393 }, 412 },
diff --git a/editors/code/src/cargo.ts b/editors/code/src/cargo.ts
index d119b6225..5999187f4 100644
--- a/editors/code/src/cargo.ts
+++ b/editors/code/src/cargo.ts
@@ -1,4 +1,3 @@
1import { window } from 'vscode';
2import * as cp from 'child_process'; 1import * as cp from 'child_process';
3import * as readline from 'readline'; 2import * as readline from 'readline';
4 3
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index 26db18156..befb8b366 100644
--- a/editors/code/src/commands/runnables.ts
+++ b/editors/code/src/commands/runnables.ts
@@ -63,7 +63,7 @@ export function runSingle(ctx: Ctx): Cmd {
63 }; 63 };
64} 64}
65 65
66function getLldbDebugConfig(config: ra.Runnable) : vscode.DebugConfiguration { 66function getLldbDebugConfig(config: ra.Runnable, sourceFileMap: Record<string, string>): vscode.DebugConfiguration {
67 return { 67 return {
68 type: "lldb", 68 type: "lldb",
69 request: "launch", 69 request: "launch",
@@ -72,11 +72,12 @@ function getLldbDebugConfig(config: ra.Runnable) : vscode.DebugConfiguration {
72 args: config.args, 72 args: config.args,
73 }, 73 },
74 args: config.extraArgs, 74 args: config.extraArgs,
75 cwd: config.cwd 75 cwd: config.cwd,
76 sourceMap: sourceFileMap
76 }; 77 };
77} 78}
78 79
79async function getCppvsDebugConfig(config: ra.Runnable) : Promise<vscode.DebugConfiguration> { 80async function getCppvsDebugConfig(config: ra.Runnable, sourceFileMap: Record<string, string>): Promise<vscode.DebugConfiguration> {
80 let cargo = new Cargo(config.cwd || '.'); 81 let cargo = new Cargo(config.cwd || '.');
81 let executable = await cargo.executableFromArgs(config.args, config.extraArgs); 82 let executable = await cargo.executableFromArgs(config.args, config.extraArgs);
82 83
@@ -87,6 +88,7 @@ async function getCppvsDebugConfig(config: ra.Runnable) : Promise<vscode.DebugCo
87 program: executable, 88 program: executable,
88 args: config.extraArgs, 89 args: config.extraArgs,
89 cwd: config.cwd, 90 cwd: config.cwd,
91 sourceFileMap: sourceFileMap,
90 }; 92 };
91} 93}
92 94
@@ -95,15 +97,30 @@ export function debugSingle(ctx: Ctx): Cmd {
95 const editor = ctx.activeRustEditor; 97 const editor = ctx.activeRustEditor;
96 if (!editor) return; 98 if (!editor) return;
97 99
98 const mscpp = vscode.extensions.getExtension("ms-vscode.cpptools"); 100 const lldbId = "vadimcn.vscode-lldb";
99 const lldb = vscode.extensions.getExtension("vadimcn.vscode-lldb"); 101 const cpptoolsId = "ms-vscode.cpptools";
102
103 let debugEngineId = ctx.config.debug.engine;
104 let debugEngine = null;
105 if (!debugEngineId) {
106 debugEngine = vscode.extensions.getExtension(lldbId);
107 if (!debugEngine) {
108 debugEngine = vscode.extensions.getExtension(cpptoolsId);
109 }
110 }
111 else {
112 debugEngine = vscode.extensions.getExtension(debugEngineId);
113 }
100 114
101 if (!(lldb || mscpp)) { 115 if (!debugEngine) {
102 vscode.window.showErrorMessage("Install `vadimcn.vscode-lldb` or `ms-vscode.cpptools` extension for debugging"); 116 vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${lldbId})`
117 + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${cpptoolsId}) extension for debugging.`);
103 return; 118 return;
104 } 119 }
105 120
106 const debugConfig = lldb ? getLldbDebugConfig(config) : await getCppvsDebugConfig(config); 121 const debugConfig = lldbId == debugEngine.id
122 ? getLldbDebugConfig(config, ctx.config.debug.sourceFileMap)
123 : await getCppvsDebugConfig(config, ctx.config.debug.sourceFileMap);
107 124
108 return vscode.debug.startDebugging(undefined, debugConfig); 125 return vscode.debug.startDebugging(undefined, debugConfig);
109 }; 126 };
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 3b2eec8ba..7764a2179 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -92,7 +92,6 @@ export class Config {
92 get askBeforeDownload() { return this.get<boolean>("updates.askBeforeDownload"); } 92 get askBeforeDownload() { return this.get<boolean>("updates.askBeforeDownload"); }
93 get traceExtension() { return this.get<boolean>("trace.extension"); } 93 get traceExtension() { return this.get<boolean>("trace.extension"); }
94 94
95
96 get inlayHints() { 95 get inlayHints() {
97 return { 96 return {
98 typeHints: this.get<boolean>("inlayHints.typeHints"), 97 typeHints: this.get<boolean>("inlayHints.typeHints"),
@@ -107,4 +106,12 @@ export class Config {
107 command: this.get<string>("checkOnSave.command"), 106 command: this.get<string>("checkOnSave.command"),
108 }; 107 };
109 } 108 }
109
110 get debug() {
111 return {
112 engine: this.get<null | string>("debug.engine"),
113 sourceFileMap: this.get<Record<string, string>>("debug.sourceFileMap"),
114 };
115 }
116
110} 117}