aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/runnables.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands/runnables.ts')
-rw-r--r--editors/code/src/commands/runnables.ts74
1 files changed, 44 insertions, 30 deletions
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}