about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorHannes De Valkeneer <hannes@de-valkeneer.be>2020-03-09 22:06:45 +0100
committerHannes De Valkeneer <hannes@de-valkeneer.be>2020-03-11 22:26:47 +0100
commite903fd0d9726dc6343a26ddeb919099fb8e4979e (patch)
tree23c2de00603542c434cc8e413c7d7cc425869cd2 /editors/code/src
parent05b4fc6d79060fc3120f92b01119e3a851c37829 (diff)
downloadrust-e903fd0d9726dc6343a26ddeb919099fb8e4979e.tar.gz
rust-e903fd0d9726dc6343a26ddeb919099fb8e4979e.zip
feat: add debug code lens
Refs #3539
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/commands/runnables.ts28
-rw-r--r--editors/code/src/main.ts1
-rw-r--r--editors/code/src/rust-analyzer-api.ts3
3 files changed, 29 insertions, 3 deletions
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index 06b51346686..faa92799c10 100644
--- a/editors/code/src/commands/runnables.ts
+++ b/editors/code/src/commands/runnables.ts
@@ -3,6 +3,7 @@ import * as lc from 'vscode-languageclient';
 import * as ra from '../rust-analyzer-api';
 
 import { Ctx, Cmd } from '../ctx';
+import { debug } from 'vscode';
 
 export function run(ctx: Ctx): Cmd {
     let prevRunnable: RunnableQuickPick | undefined;
@@ -62,6 +63,31 @@ export function runSingle(ctx: Ctx): Cmd {
     };
 }
 
+export function debugSingle(ctx: Ctx): Cmd {
+    return async (config: ra.Runnable) => {
+        const editor = ctx.activeRustEditor;
+        if (!editor) return;
+
+        if (config.args[0] === 'run') {
+            config.args[0] = 'build';
+        } else {
+            config.args.push('--no-run');
+        }
+
+        const debugConfig = {
+            type: "lldb",
+            request: "launch",
+            name: config.label,
+            cargo: {
+                args: config.args,
+            },
+            args: config.extraArgs,
+            cwd: config.cwd
+        };
+        return debug.startDebugging(undefined, debugConfig);
+    };
+}
+
 class RunnableQuickPick implements vscode.QuickPickItem {
     public label: string;
     public description?: string | undefined;
@@ -87,7 +113,7 @@ function createTask(spec: ra.Runnable): vscode.Task {
         type: 'cargo',
         label: spec.label,
         command: spec.bin,
-        args: spec.args,
+        args: spec.extraArgs ? [...spec.args, '--', ...spec.extraArgs] : spec.args,
         env: spec.env,
     };
 
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index ecf53cf775f..e01c89cc7c7 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -83,6 +83,7 @@ export async function activate(context: vscode.ExtensionContext) {
 
     // Internal commands which are invoked by the server.
     ctx.registerCommand('runSingle', commands.runSingle);
+    ctx.registerCommand('debugSingle', commands.debugSingle);
     ctx.registerCommand('showReferences', commands.showReferences);
     ctx.registerCommand('applySourceChange', commands.applySourceChange);
     ctx.registerCommand('selectAndApplySourceChange', commands.selectAndApplySourceChange);
diff --git a/editors/code/src/rust-analyzer-api.ts b/editors/code/src/rust-analyzer-api.ts
index bd6e3ada083..e09a203c9fa 100644
--- a/editors/code/src/rust-analyzer-api.ts
+++ b/editors/code/src/rust-analyzer-api.ts
@@ -80,13 +80,12 @@ export interface Runnable {
     label: string;
     bin: string;
     args: Vec<string>;
+    extraArgs: Vec<string>;
     env: FxHashMap<string, string>;
     cwd: Option<string>;
 }
 export const runnables = request<RunnablesParams, Vec<Runnable>>("runnables");
 
-
-
 export type InlayHint = InlayHint.TypeHint | InlayHint.ParamHint;
 
 export namespace InlayHint {