aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/code/package.json5
-rw-r--r--editors/code/src/commands/runnables.ts30
-rw-r--r--editors/code/src/debug.ts3
-rw-r--r--editors/code/src/main.ts1
4 files changed, 36 insertions, 3 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index 2f90d3baf..ec325ad3f 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -126,6 +126,11 @@
126 "category": "Rust Analyzer" 126 "category": "Rust Analyzer"
127 }, 127 },
128 { 128 {
129 "command": "rust-analyzer.newDebugConfig",
130 "title": "Generate launch configuration",
131 "category": "Rust Analyzer"
132 },
133 {
129 "command": "rust-analyzer.analyzerStatus", 134 "command": "rust-analyzer.analyzerStatus",
130 "title": "Status", 135 "title": "Status",
131 "category": "Rust Analyzer" 136 "category": "Rust Analyzer"
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index c1b872bce..5e88eeae0 100644
--- a/editors/code/src/commands/runnables.ts
+++ b/editors/code/src/commands/runnables.ts
@@ -3,7 +3,7 @@ import * as lc from 'vscode-languageclient';
3import * as ra from '../rust-analyzer-api'; 3import * as ra from '../rust-analyzer-api';
4 4
5import { Ctx, Cmd } from '../ctx'; 5import { Ctx, Cmd } from '../ctx';
6import { startDebugSession } from '../debug'; 6import { startDebugSession, getDebugConfiguration } from '../debug';
7 7
8async function selectRunnable(ctx: Ctx, prevRunnable: RunnableQuickPick | undefined): Promise<RunnableQuickPick | undefined> { 8async function selectRunnable(ctx: Ctx, prevRunnable: RunnableQuickPick | undefined): Promise<RunnableQuickPick | undefined> {
9 const editor = ctx.activeRustEditor; 9 const editor = ctx.activeRustEditor;
@@ -86,6 +86,34 @@ export function debugSingle(ctx: Ctx): Cmd {
86 }; 86 };
87} 87}
88 88
89export function newDebugConfig(ctx: Ctx): Cmd {
90 return async () => {
91 const scope = ctx.activeRustEditor?.document.uri;
92 if (!scope) return;
93
94 const item = await selectRunnable(ctx, undefined);
95 if (!item) return;
96
97 const debugConfig = await getDebugConfiguration(ctx, item.runnable);
98 if (!debugConfig) return;
99
100 const wsLaunchSection = vscode.workspace.getConfiguration("launch", scope);
101 const configurations = wsLaunchSection.get<any[]>("configurations") || [];
102
103 const index = configurations.findIndex(c => c.name === debugConfig.name);
104 if (index !== -1) {
105 const answer = await vscode.window.showErrorMessage(`Launch configuration '${debugConfig.name}' already exists!`, 'Cancel', 'Update');
106 if (answer === "Cancel") return;
107
108 configurations[index] = debugConfig;
109 } else {
110 configurations.push(debugConfig);
111 }
112
113 await wsLaunchSection.update("configurations", configurations);
114 };
115}
116
89class RunnableQuickPick implements vscode.QuickPickItem { 117class RunnableQuickPick implements vscode.QuickPickItem {
90 public label: string; 118 public label: string;
91 public description?: string | undefined; 119 public description?: string | undefined;
diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts
index 4f4b88adf..228a7ab75 100644
--- a/editors/code/src/debug.ts
+++ b/editors/code/src/debug.ts
@@ -57,8 +57,7 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom
57 debugEngine = vscode.extensions.getExtension(engineId); 57 debugEngine = vscode.extensions.getExtension(engineId);
58 if (debugEngine) break; 58 if (debugEngine) break;
59 } 59 }
60 } 60 } else {
61 else {
62 debugEngine = vscode.extensions.getExtension(debugOptions.engine); 61 debugEngine = vscode.extensions.getExtension(debugOptions.engine);
63 } 62 }
64 63
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 5fdeebd68..c015460b8 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -78,6 +78,7 @@ export async function activate(context: vscode.ExtensionContext) {
78 ctx.registerCommand('expandMacro', commands.expandMacro); 78 ctx.registerCommand('expandMacro', commands.expandMacro);
79 ctx.registerCommand('run', commands.run); 79 ctx.registerCommand('run', commands.run);
80 ctx.registerCommand('debug', commands.debug); 80 ctx.registerCommand('debug', commands.debug);
81 ctx.registerCommand('newDebugConfig', commands.newDebugConfig);
81 82
82 defaultOnEnter.dispose(); 83 defaultOnEnter.dispose();
83 ctx.registerCommand('onEnter', commands.onEnter); 84 ctx.registerCommand('onEnter', commands.onEnter);