From e903fd0d9726dc6343a26ddeb919099fb8e4979e Mon Sep 17 00:00:00 2001 From: Hannes De Valkeneer Date: Mon, 9 Mar 2020 22:06:45 +0100 Subject: feat: add debug code lens Refs #3539 --- editors/code/package.json | 3 +++ editors/code/src/commands/runnables.ts | 28 +++++++++++++++++++++++++++- editors/code/src/main.ts | 1 + editors/code/src/rust-analyzer-api.ts | 3 +-- 4 files changed, 32 insertions(+), 3 deletions(-) (limited to 'editors/code') diff --git a/editors/code/package.json b/editors/code/package.json index 1fe8e9f8a..744585721 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -51,6 +51,9 @@ "typescript-formatter": "^7.2.2", "vsce": "^1.74.0" }, + "extensionDependencies": [ + "vadimcn.vscode-lldb" + ], "activationEvents": [ "onLanguage:rust", "onCommand:rust-analyzer.analyzerStatus", diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 06b513466..faa92799c 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 ecf53cf77..e01c89cc7 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 bd6e3ada0..e09a203c9 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; + extraArgs: Vec; env: FxHashMap; cwd: Option; } export const runnables = request>("runnables"); - - export type InlayHint = InlayHint.TypeHint | InlayHint.ParamHint; export namespace InlayHint { -- cgit v1.2.3 From a034257e5ed5a3758e1ea2f72b3b905d1b2b320a Mon Sep 17 00:00:00 2001 From: Hannes De Valkeneer Date: Thu, 12 Mar 2020 21:00:40 +0100 Subject: fixup! feat: add debug code lens --- editors/code/src/commands/runnables.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'editors/code') diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index faa92799c..51cfb37d5 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -3,7 +3,6 @@ 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; @@ -84,7 +83,7 @@ export function debugSingle(ctx: Ctx): Cmd { args: config.extraArgs, cwd: config.cwd }; - return debug.startDebugging(undefined, debugConfig); + return vscode.debug.startDebugging(undefined, debugConfig); }; } -- cgit v1.2.3 From e9d025b618aaa1a5a06e60c17392a18f12471217 Mon Sep 17 00:00:00 2001 From: Hannes De Valkeneer Date: Thu, 12 Mar 2020 21:28:26 +0100 Subject: fixup! feat: add debug code lens avoid repetition of `--no-run` --- editors/code/src/commands/runnables.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'editors/code') diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 51cfb37d5..357155163 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -67,12 +67,6 @@ export function debugSingle(ctx: Ctx): Cmd { 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", @@ -83,6 +77,7 @@ export function debugSingle(ctx: Ctx): Cmd { args: config.extraArgs, cwd: config.cwd }; + return vscode.debug.startDebugging(undefined, debugConfig); }; } -- cgit v1.2.3 From 39c92b38726a4ca0e0e48198cbd5bdd82bbf2fb5 Mon Sep 17 00:00:00 2001 From: Hannes De Valkeneer Date: Thu, 12 Mar 2020 22:31:47 +0100 Subject: fixup! feat: add debug code lens autodetect vscode-lldb --- editors/code/package.json | 3 --- editors/code/src/client.ts | 1 + editors/code/src/config.ts | 1 + 3 files changed, 2 insertions(+), 3 deletions(-) (limited to 'editors/code') diff --git a/editors/code/package.json b/editors/code/package.json index 744585721..1fe8e9f8a 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -51,9 +51,6 @@ "typescript-formatter": "^7.2.2", "vsce": "^1.74.0" }, - "extensionDependencies": [ - "vadimcn.vscode-lldb" - ], "activationEvents": [ "onLanguage:rust", "onCommand:rust-analyzer.analyzerStatus", diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 6ce3b9235..99c9c5ae7 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -41,6 +41,7 @@ export async function createClient(config: Config, serverPath: string): Promise< withSysroot: config.withSysroot, cargoFeatures: config.cargoFeatures, rustfmtArgs: config.rustfmtArgs, + vscodeLldb: vscode.extensions.getExtension("vadimcn.vscode-lldb") != null, }, traceOutputChannel, middleware: { diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 3ade7e900..40f4c7a0d 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -156,6 +156,7 @@ export class Config { get featureFlags() { return this.cfg.get("featureFlags") as Record; } get additionalOutDirs() { return this.cfg.get("additionalOutDirs") as Record; } get rustfmtArgs() { return this.cfg.get("rustfmtArgs") as string[]; } + get vscodeLldb() { return this.cfg.get("vscodeLldb") as boolean; } get cargoWatchOptions(): CargoWatchOptions { return { -- cgit v1.2.3 From fa655912b540ece5920de8deb7856629850f5bdc Mon Sep 17 00:00:00 2001 From: hdevalke <2261239+hdevalke@users.noreply.github.com> Date: Thu, 12 Mar 2020 22:56:37 +0100 Subject: Update editors/code/src/config.ts Co-Authored-By: Veetaha --- editors/code/src/config.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'editors/code') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 40f4c7a0d..3ade7e900 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -156,7 +156,6 @@ export class Config { get featureFlags() { return this.cfg.get("featureFlags") as Record; } get additionalOutDirs() { return this.cfg.get("additionalOutDirs") as Record; } get rustfmtArgs() { return this.cfg.get("rustfmtArgs") as string[]; } - get vscodeLldb() { return this.cfg.get("vscodeLldb") as boolean; } get cargoWatchOptions(): CargoWatchOptions { return { -- cgit v1.2.3