aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/code/package.json10
-rw-r--r--editors/code/src/commands/runnables.ts74
-rw-r--r--editors/code/src/config.ts8
3 files changed, 60 insertions, 32 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index 853fc513b..c6fc13519 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -423,6 +423,16 @@
423 "default": { 423 "default": {
424 "/rustc/<id>": "${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust" 424 "/rustc/<id>": "${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust"
425 } 425 }
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\"} }"
426 } 436 }
427 } 437 }
428 }, 438 },
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index 2ed150e25..ae328d2a4 100644
--- a/editors/code/src/commands/runnables.ts
+++ b/editors/code/src/commands/runnables.ts
@@ -64,29 +64,20 @@ export function runSingle(ctx: Ctx): Cmd {
64 }; 64 };
65} 65}
66 66
67function getLldbDebugConfig(config: ra.Runnable, sourceFileMap: Record<string, string>): vscode.DebugConfiguration { 67function getLldbDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration {
68 return { 68 return {
69 type: "lldb", 69 type: "lldb",
70 request: "launch", 70 request: "launch",
71 name: config.label, 71 name: config.label,
72 cargo: { 72 program: executable,
73 args: config.args,
74 },
75 args: config.extraArgs, 73 args: config.extraArgs,
76 cwd: config.cwd, 74 cwd: config.cwd,
77 sourceMap: sourceFileMap 75 sourceMap: sourceFileMap,
76 sourceLanguages: ["rust"]
78 }; 77 };
79} 78}
80 79
81const debugOutput = vscode.window.createOutputChannel("Debug"); 80function getCppvsDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration {
82
83async 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.
90 return { 81 return {
91 type: (os.platform() === "win32") ? "cppvsdbg" : 'cppdbg', 82 type: (os.platform() === "win32") ? "cppvsdbg" : 'cppdbg',
92 request: "launch", 83 request: "launch",
@@ -98,39 +89,62 @@ async function getCppvsDebugConfig(config: ra.Runnable, sourceFileMap: Record<st
98 }; 89 };
99} 90}
100 91
92const debugOutput = vscode.window.createOutputChannel("Debug");
93
94async 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
102type DebugConfigProvider = (config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>) => vscode.DebugConfiguration;
103
101export function debugSingle(ctx: Ctx): Cmd { 104export function debugSingle(ctx: Ctx): Cmd {
102 return async (config: ra.Runnable) => { 105 return async (config: ra.Runnable) => {
103 const editor = ctx.activeRustEditor; 106 const editor = ctx.activeRustEditor;
104 if (!editor) return; 107 if (!editor) return;
105 108
106 const lldbId = "vadimcn.vscode-lldb"; 109 const knownEngines: Record<string, DebugConfigProvider> = {
107 const cpptoolsId = "ms-vscode.cpptools"; 110 "vadimcn.vscode-lldb": getLldbDebugConfig,
111 "ms-vscode.cpptools": getCppvsDebugConfig
112 };
113 const debugOptions = ctx.config.debug;
108 114
109 const debugEngineId = ctx.config.debug.engine;
110 let debugEngine = null; 115 let debugEngine = null;
111 if (debugEngineId === "auto") { 116 if (debugOptions.engine === "auto") {
112 debugEngine = vscode.extensions.getExtension(lldbId); 117 for (var engineId in knownEngines) {
113 if (!debugEngine) { 118 debugEngine = vscode.extensions.getExtension(engineId);
114 debugEngine = vscode.extensions.getExtension(cpptoolsId); 119 if (debugEngine) break;
115 } 120 }
116 } 121 }
117 else { 122 else {
118 debugEngine = vscode.extensions.getExtension(debugEngineId); 123 debugEngine = vscode.extensions.getExtension(debugOptions.engine);
119 } 124 }
120 125
121 if (!debugEngine) { 126 if (!debugEngine) {
122 vscode.window.showErrorMessage( 127 vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)`
123 `Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${lldbId}) ` + 128 + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension for debugging.`);
124 `or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${cpptoolsId}) ` +
125 `extension for debugging.`
126 );
127 return; 129 return;
128 } 130 }
129 131
130 const debugConfig = lldbId === debugEngine.id 132 debugOutput.clear();
131 ? getLldbDebugConfig(config, ctx.config.debug.sourceFileMap) 133 if (ctx.config.debug.openUpDebugPane) {
132 : await getCppvsDebugConfig(config, ctx.config.debug.sourceFileMap); 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 }
133 145
146 debugOutput.appendLine("Launching debug configuration:");
147 debugOutput.appendLine(JSON.stringify(debugConfig, null, 2));
134 return vscode.debug.startDebugging(undefined, debugConfig); 148 return vscode.debug.startDebugging(undefined, debugConfig);
135 }; 149 };
136} 150}
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 46de922f3..be2e27aec 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -109,10 +109,14 @@ export class Config {
109 } 109 }
110 110
111 get debug() { 111 get debug() {
112 // "/rustc/<id>" used by suggestions only.
113 const { ["/rustc/<id>"]: _, ...sourceFileMap } = this.get<Record<string, string>>("debug.sourceFileMap");
114
112 return { 115 return {
113 engine: this.get<string>("debug.engine"), 116 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,
115 }; 120 };
116 } 121 }
117
118} 122}