diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-30 18:03:26 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-30 18:03:26 +0100 |
commit | 972afffded3957c3891116a9a81ac9b049e28ad4 (patch) | |
tree | c6809cff47196d8ba9a1317f56856201b856dd23 /editors/code/src/commands | |
parent | fec1e7c8e10e1c592642fac0c497cd57bd3f003c (diff) | |
parent | 06b7175650c0c2570a66126b64696ed177e0d1fa (diff) |
Merge #4222
4222: Introduce C/C++ for Visual Studio Code extension as an alternative debug engine for Debug Code lens. r=matklad a=vsrs
At the moment Debug Code Lens can use only one debug engine: lldb via [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) extension.
This PR adds support of the debug engine from the [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension, as well as the configuration option. If both extensions are installed, `CodeLLDB` will be used by default.
Another new option `rust-analyzer.debug.sourceFileMap` allows, for example, to step into Rust std library during debugging. Works only with `MS C++ tools`.
On Windows:
```json
"rust-analyzer.debug.sourceFileMap": {
"/rustc/4fb7144ed159f94491249e86d5bbd033b5d60550": "${env:USERPROFILE}/.rustup/toolchains/stable-x86_64-pc-windows-msvc/lib/rustlib/src/rust"
}
```
On Linux:
```json
"rust-analyzer.debug.sourceFileMap": {
"/rustc/4fb7144ed159f94491249e86d5bbd033b5d60550": "~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust"
}
```
Co-authored-by: vsrs <[email protected]>
Diffstat (limited to 'editors/code/src/commands')
-rw-r--r-- | editors/code/src/commands/runnables.ts | 70 |
1 files changed, 58 insertions, 12 deletions
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 2635a1440..d77e8188c 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts | |||
@@ -1,8 +1,10 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | import * as ra from '../rust-analyzer-api'; | 3 | import * as ra from '../rust-analyzer-api'; |
4 | import * as os from "os"; | ||
4 | 5 | ||
5 | import { Ctx, Cmd } from '../ctx'; | 6 | import { Ctx, Cmd } from '../ctx'; |
7 | import { Cargo } from '../cargo'; | ||
6 | 8 | ||
7 | export function run(ctx: Ctx): Cmd { | 9 | export function run(ctx: Ctx): Cmd { |
8 | let prevRunnable: RunnableQuickPick | undefined; | 10 | let prevRunnable: RunnableQuickPick | undefined; |
@@ -62,25 +64,69 @@ export function runSingle(ctx: Ctx): Cmd { | |||
62 | }; | 64 | }; |
63 | } | 65 | } |
64 | 66 | ||
67 | function getLldbDebugConfig(config: ra.Runnable, sourceFileMap: Record<string, string>): vscode.DebugConfiguration { | ||
68 | return { | ||
69 | type: "lldb", | ||
70 | request: "launch", | ||
71 | name: config.label, | ||
72 | cargo: { | ||
73 | args: config.args, | ||
74 | }, | ||
75 | args: config.extraArgs, | ||
76 | cwd: config.cwd, | ||
77 | sourceMap: sourceFileMap | ||
78 | }; | ||
79 | } | ||
80 | |||
81 | const debugOutput = vscode.window.createOutputChannel("Debug"); | ||
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 { | ||
91 | type: (os.platform() === "win32") ? "cppvsdbg" : 'cppdbg', | ||
92 | request: "launch", | ||
93 | name: config.label, | ||
94 | program: executable, | ||
95 | args: config.extraArgs, | ||
96 | cwd: config.cwd, | ||
97 | sourceFileMap: sourceFileMap, | ||
98 | }; | ||
99 | } | ||
100 | |||
65 | export function debugSingle(ctx: Ctx): Cmd { | 101 | export function debugSingle(ctx: Ctx): Cmd { |
66 | return async (config: ra.Runnable) => { | 102 | return async (config: ra.Runnable) => { |
67 | const editor = ctx.activeRustEditor; | 103 | const editor = ctx.activeRustEditor; |
68 | if (!editor) return; | 104 | if (!editor) return; |
69 | if (!vscode.extensions.getExtension("vadimcn.vscode-lldb")) { | 105 | |
70 | vscode.window.showErrorMessage("Install `vadimcn.vscode-lldb` extension for debugging"); | 106 | const lldbId = "vadimcn.vscode-lldb"; |
107 | const cpptoolsId = "ms-vscode.cpptools"; | ||
108 | |||
109 | const debugEngineId = ctx.config.debug.engine; | ||
110 | let debugEngine = null; | ||
111 | if (debugEngineId === "auto") { | ||
112 | debugEngine = vscode.extensions.getExtension(lldbId); | ||
113 | if (!debugEngine) { | ||
114 | debugEngine = vscode.extensions.getExtension(cpptoolsId); | ||
115 | } | ||
116 | } | ||
117 | else { | ||
118 | debugEngine = vscode.extensions.getExtension(debugEngineId); | ||
119 | } | ||
120 | |||
121 | if (!debugEngine) { | ||
122 | vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${lldbId})` | ||
123 | + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${cpptoolsId}) extension for debugging.`); | ||
71 | return; | 124 | return; |
72 | } | 125 | } |
73 | 126 | ||
74 | const debugConfig = { | 127 | const debugConfig = lldbId === debugEngine.id |
75 | type: "lldb", | 128 | ? getLldbDebugConfig(config, ctx.config.debug.sourceFileMap) |
76 | request: "launch", | 129 | : await getCppvsDebugConfig(config, ctx.config.debug.sourceFileMap); |
77 | name: config.label, | ||
78 | cargo: { | ||
79 | args: config.args, | ||
80 | }, | ||
81 | args: config.extraArgs, | ||
82 | cwd: config.cwd | ||
83 | }; | ||
84 | 130 | ||
85 | return vscode.debug.startDebugging(undefined, debugConfig); | 131 | return vscode.debug.startDebugging(undefined, debugConfig); |
86 | }; | 132 | }; |