From 155f0601421620086a256c9e313568d5bd7391e0 Mon Sep 17 00:00:00 2001 From: vsrs Date: Mon, 11 May 2020 16:06:57 +0300 Subject: "rust-analyzer.debug" command --- editors/code/src/commands/runnables.ts | 149 ++++++++++----------------------- editors/code/src/debug.ts | 95 +++++++++++++++++++++ editors/code/src/main.ts | 1 + 3 files changed, 139 insertions(+), 106 deletions(-) create mode 100644 editors/code/src/debug.ts (limited to 'editors/code/src') diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index ae328d2a4..c1b872bce 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -1,43 +1,46 @@ import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; import * as ra from '../rust-analyzer-api'; -import * as os from "os"; import { Ctx, Cmd } from '../ctx'; -import { Cargo } from '../cargo'; +import { startDebugSession } from '../debug'; + +async function selectRunnable(ctx: Ctx, prevRunnable: RunnableQuickPick | undefined): Promise { + const editor = ctx.activeRustEditor; + const client = ctx.client; + if (!editor || !client) return; + + const textDocument: lc.TextDocumentIdentifier = { + uri: editor.document.uri.toString(), + }; + + const runnables = await client.sendRequest(ra.runnables, { + textDocument, + position: client.code2ProtocolConverter.asPosition( + editor.selection.active, + ), + }); + const items: RunnableQuickPick[] = []; + if (prevRunnable) { + items.push(prevRunnable); + } + for (const r of runnables) { + if ( + prevRunnable && + JSON.stringify(prevRunnable.runnable) === JSON.stringify(r) + ) { + continue; + } + items.push(new RunnableQuickPick(r)); + } + return await vscode.window.showQuickPick(items); +} export function run(ctx: Ctx): Cmd { let prevRunnable: RunnableQuickPick | undefined; return async () => { - const editor = ctx.activeRustEditor; - const client = ctx.client; - if (!editor || !client) return; - - const textDocument: lc.TextDocumentIdentifier = { - uri: editor.document.uri.toString(), - }; - - const runnables = await client.sendRequest(ra.runnables, { - textDocument, - position: client.code2ProtocolConverter.asPosition( - editor.selection.active, - ), - }); - const items: RunnableQuickPick[] = []; - if (prevRunnable) { - items.push(prevRunnable); - } - for (const r of runnables) { - if ( - prevRunnable && - JSON.stringify(prevRunnable.runnable) === JSON.stringify(r) - ) { - continue; - } - items.push(new RunnableQuickPick(r)); - } - const item = await vscode.window.showQuickPick(items); + const item = await selectRunnable(ctx, prevRunnable); if (!item) return; item.detail = 'rerun'; @@ -64,88 +67,22 @@ export function runSingle(ctx: Ctx): Cmd { }; } -function getLldbDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record): vscode.DebugConfiguration { - return { - type: "lldb", - request: "launch", - name: config.label, - program: executable, - args: config.extraArgs, - cwd: config.cwd, - sourceMap: sourceFileMap, - sourceLanguages: ["rust"] - }; -} - -function getCppvsDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record): vscode.DebugConfiguration { - return { - type: (os.platform() === "win32") ? "cppvsdbg" : 'cppdbg', - request: "launch", - name: config.label, - program: executable, - args: config.extraArgs, - cwd: config.cwd, - sourceFileMap: sourceFileMap, - }; -} +export function debug(ctx: Ctx): Cmd { + let prevDebuggee: RunnableQuickPick | undefined; -const debugOutput = vscode.window.createOutputChannel("Debug"); - -async function getDebugExecutable(config: ra.Runnable): Promise { - const cargo = new Cargo(config.cwd || '.', debugOutput); - const executable = await cargo.executableFromArgs(config.args); + return async () => { + const item = await selectRunnable(ctx, prevDebuggee); + if (!item) return; - // if we are here, there were no compilation errors. - return executable; + item.detail = 'restart'; + prevDebuggee = item; + return await startDebugSession(ctx, item.runnable); + }; } -type DebugConfigProvider = (config: ra.Runnable, executable: string, sourceFileMap?: Record) => vscode.DebugConfiguration; - export function debugSingle(ctx: Ctx): Cmd { return async (config: ra.Runnable) => { - const editor = ctx.activeRustEditor; - if (!editor) return; - - const knownEngines: Record = { - "vadimcn.vscode-lldb": getLldbDebugConfig, - "ms-vscode.cpptools": getCppvsDebugConfig - }; - const debugOptions = ctx.config.debug; - - let debugEngine = null; - if (debugOptions.engine === "auto") { - for (var engineId in knownEngines) { - debugEngine = vscode.extensions.getExtension(engineId); - if (debugEngine) break; - } - } - else { - debugEngine = vscode.extensions.getExtension(debugOptions.engine); - } - - if (!debugEngine) { - vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)` - + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension for debugging.`); - return; - } - - debugOutput.clear(); - if (ctx.config.debug.openUpDebugPane) { - debugOutput.show(true); - } - - const executable = await getDebugExecutable(config); - const debugConfig = knownEngines[debugEngine.id](config, executable, debugOptions.sourceFileMap); - if (debugConfig.type in debugOptions.engineSettings) { - const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type]; - for (var key in settingsMap) { - debugConfig[key] = settingsMap[key]; - } - } - - debugOutput.appendLine("Launching debug configuration:"); - debugOutput.appendLine(JSON.stringify(debugConfig, null, 2)); - return vscode.debug.startDebugging(undefined, debugConfig); + await startDebugSession(ctx, config); }; } diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts new file mode 100644 index 000000000..4f4b88adf --- /dev/null +++ b/editors/code/src/debug.ts @@ -0,0 +1,95 @@ +import * as os from "os"; +import * as vscode from 'vscode'; +import * as ra from './rust-analyzer-api'; + +import { Cargo } from './cargo'; +import { Ctx } from "./ctx"; + +const debugOutput = vscode.window.createOutputChannel("Debug"); +type DebugConfigProvider = (config: ra.Runnable, executable: string, sourceFileMap?: Record) => vscode.DebugConfiguration; + +function getLldbDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record): vscode.DebugConfiguration { + return { + type: "lldb", + request: "launch", + name: config.label, + program: executable, + args: config.extraArgs, + cwd: config.cwd, + sourceMap: sourceFileMap, + sourceLanguages: ["rust"] + }; +} + +function getCppvsDebugConfig(config: ra.Runnable, executable: string, sourceFileMap?: Record): vscode.DebugConfiguration { + return { + type: (os.platform() === "win32") ? "cppvsdbg" : "cppdbg", + request: "launch", + name: config.label, + program: executable, + args: config.extraArgs, + cwd: config.cwd, + sourceFileMap: sourceFileMap, + }; +} + +async function getDebugExecutable(config: ra.Runnable): Promise { + const cargo = new Cargo(config.cwd || '.', debugOutput); + const executable = await cargo.executableFromArgs(config.args); + + // if we are here, there were no compilation errors. + return executable; +} + +export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Promise { + const editor = ctx.activeRustEditor; + if (!editor) return; + + const knownEngines: Record = { + "vadimcn.vscode-lldb": getLldbDebugConfig, + "ms-vscode.cpptools": getCppvsDebugConfig + }; + const debugOptions = ctx.config.debug; + + let debugEngine = null; + if (debugOptions.engine === "auto") { + for (var engineId in knownEngines) { + debugEngine = vscode.extensions.getExtension(engineId); + if (debugEngine) break; + } + } + else { + debugEngine = vscode.extensions.getExtension(debugOptions.engine); + } + + if (!debugEngine) { + vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)` + + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension for debugging.`); + return; + } + + debugOutput.clear(); + if (ctx.config.debug.openUpDebugPane) { + debugOutput.show(true); + } + + const executable = await getDebugExecutable(config); + const debugConfig = knownEngines[debugEngine.id](config, executable, debugOptions.sourceFileMap); + if (debugConfig.type in debugOptions.engineSettings) { + const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type]; + for (var key in settingsMap) { + debugConfig[key] = settingsMap[key]; + } + } + + return debugConfig; +} + +export async function startDebugSession(ctx: Ctx, config: ra.Runnable): Promise { + const debugConfig = await getDebugConfiguration(ctx, config); + if (!debugConfig) return false; + + debugOutput.appendLine("Launching debug configuration:"); + debugOutput.appendLine(JSON.stringify(debugConfig, null, 2)); + return vscode.debug.startDebugging(undefined, debugConfig); +} diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 9b020d001..5fdeebd68 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -77,6 +77,7 @@ export async function activate(context: vscode.ExtensionContext) { ctx.registerCommand('syntaxTree', commands.syntaxTree); ctx.registerCommand('expandMacro', commands.expandMacro); ctx.registerCommand('run', commands.run); + ctx.registerCommand('debug', commands.debug); defaultOnEnter.dispose(); ctx.registerCommand('onEnter', commands.onEnter); -- cgit v1.2.3 From fee0a9fa5a3dd84400108b33a1e8225dc364a9fa Mon Sep 17 00:00:00 2001 From: vsrs Date: Mon, 11 May 2020 18:00:15 +0300 Subject: "rust-analyzer.newDebugConfig" command --- editors/code/src/commands/runnables.ts | 30 +++++++++++++++++++++++++++++- editors/code/src/debug.ts | 3 +-- editors/code/src/main.ts | 1 + 3 files changed, 31 insertions(+), 3 deletions(-) (limited to 'editors/code/src') 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'; import * as ra from '../rust-analyzer-api'; import { Ctx, Cmd } from '../ctx'; -import { startDebugSession } from '../debug'; +import { startDebugSession, getDebugConfiguration } from '../debug'; async function selectRunnable(ctx: Ctx, prevRunnable: RunnableQuickPick | undefined): Promise { const editor = ctx.activeRustEditor; @@ -86,6 +86,34 @@ export function debugSingle(ctx: Ctx): Cmd { }; } +export function newDebugConfig(ctx: Ctx): Cmd { + return async () => { + const scope = ctx.activeRustEditor?.document.uri; + if (!scope) return; + + const item = await selectRunnable(ctx, undefined); + if (!item) return; + + const debugConfig = await getDebugConfiguration(ctx, item.runnable); + if (!debugConfig) return; + + const wsLaunchSection = vscode.workspace.getConfiguration("launch", scope); + const configurations = wsLaunchSection.get("configurations") || []; + + const index = configurations.findIndex(c => c.name === debugConfig.name); + if (index !== -1) { + const answer = await vscode.window.showErrorMessage(`Launch configuration '${debugConfig.name}' already exists!`, 'Cancel', 'Update'); + if (answer === "Cancel") return; + + configurations[index] = debugConfig; + } else { + configurations.push(debugConfig); + } + + await wsLaunchSection.update("configurations", configurations); + }; +} + class RunnableQuickPick implements vscode.QuickPickItem { public label: string; 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 debugEngine = vscode.extensions.getExtension(engineId); if (debugEngine) break; } - } - else { + } else { debugEngine = vscode.extensions.getExtension(debugOptions.engine); } 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) { ctx.registerCommand('expandMacro', commands.expandMacro); ctx.registerCommand('run', commands.run); ctx.registerCommand('debug', commands.debug); + ctx.registerCommand('newDebugConfig', commands.newDebugConfig); defaultOnEnter.dispose(); ctx.registerCommand('onEnter', commands.onEnter); -- cgit v1.2.3 From e914d622ec378fd9efb9b20801c925ade806ef60 Mon Sep 17 00:00:00 2001 From: vsrs Date: Mon, 11 May 2020 18:49:45 +0300 Subject: DebugConfiguration simplification. ${workspaceRoot} substitution in generated DebugConfiguration. --- editors/code/src/debug.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'editors/code/src') diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index 228a7ab75..cc5755611 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -1,5 +1,6 @@ import * as os from "os"; import * as vscode from 'vscode'; +import * as path from 'path'; import * as ra from './rust-analyzer-api'; import { Cargo } from './cargo'; @@ -72,8 +73,13 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom debugOutput.show(true); } + const wsFolder = path.normalize(vscode.workspace.workspaceFolders![0].uri.fsPath); // folder exists or RA is not active. + function simplifyPath(p: string): string { + return path.normalize(p).replace(wsFolder, '${workspaceRoot}'); + } + const executable = await getDebugExecutable(config); - const debugConfig = knownEngines[debugEngine.id](config, executable, debugOptions.sourceFileMap); + const debugConfig = knownEngines[debugEngine.id](config, simplifyPath(executable), debugOptions.sourceFileMap); if (debugConfig.type in debugOptions.engineSettings) { const settingsMap = (debugOptions.engineSettings as any)[debugConfig.type]; for (var key in settingsMap) { @@ -81,6 +87,10 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom } } + if (debugConfig.cwd) { + debugConfig.cwd = simplifyPath(debugConfig.cwd); + } + return debugConfig; } -- cgit v1.2.3 From 9ebb2acdca6c711cff7bfc84a410794739092dbe Mon Sep 17 00:00:00 2001 From: vsrs Date: Wed, 13 May 2020 15:51:15 +0300 Subject: Use launch.json in Debug Lens sessions. Add the possibility to use existing configurations via Debug Lens --- editors/code/src/config.ts | 1 + editors/code/src/debug.ts | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index be2e27aec..24002483d 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -117,6 +117,7 @@ export class Config { engineSettings: this.get("debug.engineSettings"), openUpDebugPane: this.get("debug.openUpDebugPane"), sourceFileMap: sourceFileMap, + useLaunchJson: this.get("debug.useLaunchJson"), }; } } diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index cc5755611..bbf3ff312 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -95,10 +95,27 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom } export async function startDebugSession(ctx: Ctx, config: ra.Runnable): Promise { - const debugConfig = await getDebugConfiguration(ctx, config); + let debugConfig: vscode.DebugConfiguration | undefined = undefined; + let message = ""; + + if (ctx.config.debug.useLaunchJson) { + const wsLaunchSection = vscode.workspace.getConfiguration("launch"); + const configurations = wsLaunchSection.get("configurations") || []; + + const index = configurations.findIndex(c => c.name === config.label); + if (-1 !== index) { + debugConfig = configurations[index]; + message = " (from launch.json)"; + debugOutput.clear(); + } + } + if (!debugConfig) { + debugConfig = await getDebugConfiguration(ctx, config); + } + if (!debugConfig) return false; - debugOutput.appendLine("Launching debug configuration:"); + debugOutput.appendLine(`Launching debug configuration${message}:`); debugOutput.appendLine(JSON.stringify(debugConfig, null, 2)); return vscode.debug.startDebugging(undefined, debugConfig); } -- cgit v1.2.3 From 3ffc26eaebb1f9491477e99d5187b048bd489cd6 Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 14 May 2020 11:12:10 +0300 Subject: Remove "rust-analyzer.debug.useLaunchJson" option --- editors/code/src/config.ts | 3 +-- editors/code/src/debug.ts | 21 +++++++++------------ 2 files changed, 10 insertions(+), 14 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 24002483d..1652827c3 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -116,8 +116,7 @@ export class Config { engine: this.get("debug.engine"), engineSettings: this.get("debug.engineSettings"), openUpDebugPane: this.get("debug.openUpDebugPane"), - sourceFileMap: sourceFileMap, - useLaunchJson: this.get("debug.useLaunchJson"), + sourceFileMap: sourceFileMap }; } } diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index bbf3ff312..b500fe029 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -98,18 +98,15 @@ export async function startDebugSession(ctx: Ctx, config: ra.Runnable): Promise< let debugConfig: vscode.DebugConfiguration | undefined = undefined; let message = ""; - if (ctx.config.debug.useLaunchJson) { - const wsLaunchSection = vscode.workspace.getConfiguration("launch"); - const configurations = wsLaunchSection.get("configurations") || []; - - const index = configurations.findIndex(c => c.name === config.label); - if (-1 !== index) { - debugConfig = configurations[index]; - message = " (from launch.json)"; - debugOutput.clear(); - } - } - if (!debugConfig) { + const wsLaunchSection = vscode.workspace.getConfiguration("launch"); + const configurations = wsLaunchSection.get("configurations") || []; + + const index = configurations.findIndex(c => c.name === config.label); + if (-1 !== index) { + debugConfig = configurations[index]; + message = " (from launch.json)"; + debugOutput.clear(); + } else { debugConfig = await getDebugConfiguration(ctx, config); } -- cgit v1.2.3 From be9b0609d55f9f49e4473b4ab2bc55583974fc2f Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 14 May 2020 13:22:52 +0300 Subject: Runnable quick pick with buttons --- editors/code/src/commands/runnables.ts | 82 +++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 21 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 5e88eeae0..b1d93fc34 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -5,7 +5,9 @@ import * as ra from '../rust-analyzer-api'; import { Ctx, Cmd } from '../ctx'; import { startDebugSession, getDebugConfiguration } from '../debug'; -async function selectRunnable(ctx: Ctx, prevRunnable: RunnableQuickPick | undefined): Promise { +const quickPickButtons = [{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configurtation." }]; + +async function selectRunnable(ctx: Ctx, prevRunnable?: RunnableQuickPick, showButtons: boolean = true): Promise { const editor = ctx.activeRustEditor; const client = ctx.client; if (!editor || !client) return; @@ -33,7 +35,41 @@ async function selectRunnable(ctx: Ctx, prevRunnable: RunnableQuickPick | undefi } items.push(new RunnableQuickPick(r)); } - return await vscode.window.showQuickPick(items); + + return await new Promise((resolve) => { + const disposables: vscode.Disposable[] = []; + const close = (result?: RunnableQuickPick) => { + resolve(result); + disposables.forEach(d => d.dispose()); + }; + + const quickPick = vscode.window.createQuickPick(); + quickPick.items = items; + quickPick.title = "Select Runnable"; + if (showButtons) { + quickPick.buttons = quickPickButtons; + } + disposables.push( + quickPick.onDidHide(() => close()), + quickPick.onDidAccept(() => close(quickPick.selectedItems[0])), + quickPick.onDidTriggerButton((_button) => { + (async () => await makeDebugConfig(ctx, quickPick.activeItems[0]))(); + close(); + }), + quickPick.onDidChangeActive((active) => { + if (showButtons && active.length > 0) { + if (active[0].label.startsWith('cargo')) { + // save button makes no sense for `cargo test` or `cargo check` + quickPick.buttons = []; + } else if (quickPick.buttons.length === 0) { + quickPick.buttons = quickPickButtons; + } + } + }), + quickPick + ); + quickPick.show(); + }); } export function run(ctx: Ctx): Cmd { @@ -86,31 +122,35 @@ export function debugSingle(ctx: Ctx): Cmd { }; } -export function newDebugConfig(ctx: Ctx): Cmd { - return async () => { - const scope = ctx.activeRustEditor?.document.uri; - if (!scope) return; +async function makeDebugConfig(ctx: Ctx, item: RunnableQuickPick): Promise { + const scope = ctx.activeRustEditor?.document.uri; + if (!scope) return; - const item = await selectRunnable(ctx, undefined); - if (!item) return; + const debugConfig = await getDebugConfiguration(ctx, item.runnable); + if (!debugConfig) return; - const debugConfig = await getDebugConfiguration(ctx, item.runnable); - if (!debugConfig) return; + const wsLaunchSection = vscode.workspace.getConfiguration("launch", scope); + const configurations = wsLaunchSection.get("configurations") || []; - const wsLaunchSection = vscode.workspace.getConfiguration("launch", scope); - const configurations = wsLaunchSection.get("configurations") || []; + const index = configurations.findIndex(c => c.name === debugConfig.name); + if (index !== -1) { + const answer = await vscode.window.showErrorMessage(`Launch configuration '${debugConfig.name}' already exists!`, 'Cancel', 'Update'); + if (answer === "Cancel") return; - const index = configurations.findIndex(c => c.name === debugConfig.name); - if (index !== -1) { - const answer = await vscode.window.showErrorMessage(`Launch configuration '${debugConfig.name}' already exists!`, 'Cancel', 'Update'); - if (answer === "Cancel") return; + configurations[index] = debugConfig; + } else { + configurations.push(debugConfig); + } - configurations[index] = debugConfig; - } else { - configurations.push(debugConfig); - } + await wsLaunchSection.update("configurations", configurations); +} + +export function newDebugConfig(ctx: Ctx): Cmd { + return async () => { + const item = await selectRunnable(ctx, undefined, false); + if (!item) return; - await wsLaunchSection.update("configurations", configurations); + await makeDebugConfig(ctx, item); }; } -- cgit v1.2.3 From a233346a2d08bde9869d86d14e67ca3290c10cb2 Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 14 May 2020 13:30:05 +0300 Subject: Fix "rust-analyzer.debug" for QuickPick binaries. --- editors/code/src/cargo.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'editors/code/src') diff --git a/editors/code/src/cargo.ts b/editors/code/src/cargo.ts index 2a2c2e0e1..ba286c0ab 100644 --- a/editors/code/src/cargo.ts +++ b/editors/code/src/cargo.ts @@ -48,6 +48,10 @@ export class Cargo { async executableFromArgs(args: readonly string[]): Promise { const cargoArgs = [...args, "--message-format=json"]; + if( cargoArgs[0] == "run" ) { + // a runnable from the quick pick. + cargoArgs[0] = "build"; + } const artifacts = await this.artifactsFromArgs(cargoArgs); -- cgit v1.2.3 From af7c50f8a2e6763d4d72d0fa0b33e62b12aaf1c7 Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 14 May 2020 13:48:02 +0300 Subject: Multiple binaries support for launch.json. --- editors/code/src/debug.ts | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'editors/code/src') diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index b500fe029..966019883 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -87,6 +87,11 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom } } + if (debugConfig.name === "run binary") { + // A workaround for multiple binaries. It would be better to get proper names on the LSP side. + debugConfig.name = `run binary [${path.basename(executable)}]`; + } + if (debugConfig.cwd) { debugConfig.cwd = simplifyPath(debugConfig.cwd); } -- cgit v1.2.3 From 5f6cdae18f415b9af3b3d24234ab2943efb30993 Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 14 May 2020 14:42:40 +0300 Subject: Mixed "bin" and "test" artifacts workaround. --- editors/code/src/cargo.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/cargo.ts b/editors/code/src/cargo.ts index ba286c0ab..4ff24ea7d 100644 --- a/editors/code/src/cargo.ts +++ b/editors/code/src/cargo.ts @@ -48,12 +48,17 @@ export class Cargo { async executableFromArgs(args: readonly string[]): Promise { const cargoArgs = [...args, "--message-format=json"]; - if( cargoArgs[0] == "run" ) { + if (cargoArgs[0] === "run") { // a runnable from the quick pick. cargoArgs[0] = "build"; } - const artifacts = await this.artifactsFromArgs(cargoArgs); + let artifacts = await this.artifactsFromArgs(cargoArgs); + if (cargoArgs[0] === "test") { + // for instance, `crates\rust-analyzer\tests\heavy_tests\main.rs` tests + // produce 2 artifacts: {"kind": "bin"} and {"kind": "test"} + artifacts = artifacts.filter(a => a.isTest); + } if (artifacts.length === 0) { throw new Error('No compilation artifacts'); -- cgit v1.2.3 From 20fdd14c62aa9c5327f1e6afc04f01a5af6763fb Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 14 May 2020 16:02:01 +0300 Subject: Multiple binaries support for launch.json. Generate unique names on the LSP side. --- editors/code/src/debug.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index 966019883..1f93a2b7e 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -88,8 +88,9 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom } if (debugConfig.name === "run binary") { - // A workaround for multiple binaries. It would be better to get proper names on the LSP side. - debugConfig.name = `run binary [${path.basename(executable)}]`; + // The LSP side: crates\rust-analyzer\src\main_loop\handlers.rs, + // fn to_lsp_runnable(...) with RunnableKind::Bin + debugConfig.name = `run binary '${path.basename(executable)}'`; } if (debugConfig.cwd) { -- cgit v1.2.3 From abef76bc87137203081faedd3c758796e8d6598d Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 14 May 2020 17:32:24 +0300 Subject: Fix runnable naming in the client side fallback. --- editors/code/src/debug.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src') diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index 1f93a2b7e..d3fe588e8 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -90,7 +90,7 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom if (debugConfig.name === "run binary") { // The LSP side: crates\rust-analyzer\src\main_loop\handlers.rs, // fn to_lsp_runnable(...) with RunnableKind::Bin - debugConfig.name = `run binary '${path.basename(executable)}'`; + debugConfig.name = `run ${path.basename(executable)}`; } if (debugConfig.cwd) { -- cgit v1.2.3 From a4ecaa70969067c1149711dbf1f40a8a95cb5b72 Mon Sep 17 00:00:00 2001 From: vsrs Date: Fri, 15 May 2020 15:31:09 +0300 Subject: Fix occasional test run during debug configuration --- editors/code/src/cargo.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'editors/code/src') diff --git a/editors/code/src/cargo.ts b/editors/code/src/cargo.ts index 4ff24ea7d..28c7de992 100644 --- a/editors/code/src/cargo.ts +++ b/editors/code/src/cargo.ts @@ -48,9 +48,13 @@ export class Cargo { async executableFromArgs(args: readonly string[]): Promise { const cargoArgs = [...args, "--message-format=json"]; + + // arguments for a runnable from the quick pick should be updated. + // see crates\rust-analyzer\src\main_loop\handlers.rs, handle_code_lens if (cargoArgs[0] === "run") { - // a runnable from the quick pick. cargoArgs[0] = "build"; + } else if (cargoArgs.indexOf("--no-run") === -1) { + cargoArgs.push("--no-run"); } let artifacts = await this.artifactsFromArgs(cargoArgs); -- cgit v1.2.3