diff options
author | vsrs <[email protected]> | 2020-05-06 14:01:35 +0100 |
---|---|---|
committer | vsrs <[email protected]> | 2020-05-06 14:06:21 +0100 |
commit | c4ca6e29c25df209c2733ef24b8b4eca70ee93a4 (patch) | |
tree | de8df0d319a37d75f24b14340e6f0fe2ca65b52b | |
parent | 1116c9a0e9992d0dea8dac87de95c8a74c093cff (diff) |
Uniformed way to get Debug Lens target executable.
-rw-r--r-- | editors/code/src/commands/runnables.ts | 59 | ||||
-rw-r--r-- | editors/code/src/config.ts | 6 |
2 files changed, 37 insertions, 28 deletions
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index d77e8188c..7bb8727e7 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts | |||
@@ -64,29 +64,19 @@ export function runSingle(ctx: Ctx): Cmd { | |||
64 | }; | 64 | }; |
65 | } | 65 | } |
66 | 66 | ||
67 | function getLldbDebugConfig(config: ra.Runnable, sourceFileMap: Record<string, string>): vscode.DebugConfiguration { | 67 | function 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 |
78 | }; | 76 | }; |
79 | } | 77 | } |
80 | 78 | ||
81 | const debugOutput = vscode.window.createOutputChannel("Debug"); | 79 | function getCppvsDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>): vscode.DebugConfiguration { |
82 | |||
83 | async 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 { | 80 | return { |
91 | type: (os.platform() === "win32") ? "cppvsdbg" : 'cppdbg', | 81 | type: (os.platform() === "win32") ? "cppvsdbg" : 'cppdbg', |
92 | request: "launch", | 82 | request: "launch", |
@@ -98,36 +88,53 @@ async function getCppvsDebugConfig(config: ra.Runnable, sourceFileMap: Record<st | |||
98 | }; | 88 | }; |
99 | } | 89 | } |
100 | 90 | ||
91 | const debugOutput = vscode.window.createOutputChannel("Debug"); | ||
92 | |||
93 | async function getDebugExecutable(config: ra.Runnable): Promise<string> { | ||
94 | debugOutput.clear(); | ||
95 | |||
96 | const cargo = new Cargo(config.cwd || '.', debugOutput); | ||
97 | const executable = await cargo.executableFromArgs(config.args); | ||
98 | |||
99 | // if we are here, there were no compilation errors. | ||
100 | return executable; | ||
101 | } | ||
102 | |||
103 | type DebugConfigProvider = (config: ra.Runnable, executable: string, sourceFileMap?: Record<string, string>) => vscode.DebugConfiguration; | ||
104 | |||
101 | export function debugSingle(ctx: Ctx): Cmd { | 105 | export function debugSingle(ctx: Ctx): Cmd { |
102 | return async (config: ra.Runnable) => { | 106 | return async (config: ra.Runnable) => { |
103 | const editor = ctx.activeRustEditor; | 107 | const editor = ctx.activeRustEditor; |
104 | if (!editor) return; | 108 | if (!editor) return; |
105 | 109 | ||
106 | const lldbId = "vadimcn.vscode-lldb"; | 110 | const knownEngines: Record<string, DebugConfigProvider> = { |
107 | const cpptoolsId = "ms-vscode.cpptools"; | 111 | "vadimcn.vscode-lldb": getLldbDebugConfig, |
112 | "ms-vscode.cpptools": getCppvsDebugConfig | ||
113 | }; | ||
114 | const debugOptions = ctx.config.debug; | ||
108 | 115 | ||
109 | const debugEngineId = ctx.config.debug.engine; | ||
110 | let debugEngine = null; | 116 | let debugEngine = null; |
111 | if (debugEngineId === "auto") { | 117 | if (debugOptions.engine === "auto") { |
112 | debugEngine = vscode.extensions.getExtension(lldbId); | 118 | for (var engineId in knownEngines) { |
113 | if (!debugEngine) { | 119 | debugEngine = vscode.extensions.getExtension(engineId); |
114 | debugEngine = vscode.extensions.getExtension(cpptoolsId); | 120 | if (debugEngine) break; |
115 | } | 121 | } |
116 | } | 122 | } |
117 | else { | 123 | else { |
118 | debugEngine = vscode.extensions.getExtension(debugEngineId); | 124 | debugEngine = vscode.extensions.getExtension(debugOptions.engine); |
119 | } | 125 | } |
120 | 126 | ||
121 | if (!debugEngine) { | 127 | if (!debugEngine) { |
122 | vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${lldbId})` | 128 | vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)` |
123 | + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${cpptoolsId}) extension for debugging.`); | 129 | + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension for debugging.`); |
124 | return; | 130 | return; |
125 | } | 131 | } |
126 | 132 | ||
127 | const debugConfig = lldbId === debugEngine.id | 133 | const executable = await getDebugExecutable(config); |
128 | ? getLldbDebugConfig(config, ctx.config.debug.sourceFileMap) | 134 | const debugConfig = knownEngines[debugEngine.id](config, executable, debugOptions.sourceFileMap); |
129 | : await getCppvsDebugConfig(config, ctx.config.debug.sourceFileMap); | ||
130 | 135 | ||
136 | debugOutput.appendLine("Launching debug configuration:"); | ||
137 | debugOutput.appendLine(JSON.stringify(debugConfig, null, 2)); | ||
131 | return vscode.debug.startDebugging(undefined, debugConfig); | 138 | return vscode.debug.startDebugging(undefined, debugConfig); |
132 | }; | 139 | }; |
133 | } | 140 | } |
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 110e54180..8bceaaf72 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -108,10 +108,12 @@ export class Config { | |||
108 | } | 108 | } |
109 | 109 | ||
110 | get debug() { | 110 | get debug() { |
111 | // "/rustc/<id>" used by suggestions only. | ||
112 | const { ["/rustc/<id>"]: _, ...sourceFileMap } = this.get<Record<string, string>>("debug.sourceFileMap"); | ||
113 | |||
111 | return { | 114 | return { |
112 | engine: this.get<string>("debug.engine"), | 115 | engine: this.get<string>("debug.engine"), |
113 | sourceFileMap: this.get<Record<string, string>>("debug.sourceFileMap"), | 116 | sourceFileMap: sourceFileMap, |
114 | }; | 117 | }; |
115 | } | 118 | } |
116 | |||
117 | } | 119 | } |