From a43a9103bc9a8c1bf735d51c952bc3b9352a00c3 Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 18 Jun 2020 22:20:13 +0300 Subject: Add custom cargo runners --- editors/code/src/run.ts | 57 +++++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 40 deletions(-) (limited to 'editors/code/src/run.ts') diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts index bb060cfe1..7ecdeeeaf 100644 --- a/editors/code/src/run.ts +++ b/editors/code/src/run.ts @@ -1,10 +1,11 @@ import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; import * as ra from './lsp_ext'; -import * as toolchain from "./toolchain"; +import * as tasks from './tasks'; import { Ctx } from './ctx'; import { makeDebugConfig } from './debug'; +import { Config } from './config'; const quickPickButtons = [{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configurtation." }]; @@ -95,52 +96,28 @@ export class RunnableQuickPick implements vscode.QuickPickItem { } } -interface CargoTaskDefinition extends vscode.TaskDefinition { - type: 'cargo'; - label: string; - command: string; - args: string[]; - env?: { [key: string]: string }; -} - -export function createTask(runnable: ra.Runnable): vscode.Task { - const TASK_SOURCE = 'Rust'; +export async function createTask(runnable: ra.Runnable, config: Config): Promise { + if (runnable.kind !== "cargo") { + // rust-analyzer supports only one kind, "cargo" + // do not use tasks.TASK_TYPE here, these are completely different meanings. - let command; - switch (runnable.kind) { - case "cargo": command = toolchain.getPathForExecutable("cargo"); + throw `Unexpected runnable kind: ${runnable.kind}`; } + const args = [...runnable.args.cargoArgs]; // should be a copy! if (runnable.args.executableArgs.length > 0) { args.push('--', ...runnable.args.executableArgs); } - const definition: CargoTaskDefinition = { - type: 'cargo', - label: runnable.label, - command, - args, + const definition: tasks.CargoTaskDefinition = { + type: tasks.TASK_TYPE, + command: args[0], // run, test, etc... + args: args.slice(1), + cwd: runnable.args.workspaceRoot, env: Object.assign({}, process.env as { [key: string]: string }, { "RUST_BACKTRACE": "short" }), }; - const execOption: vscode.ShellExecutionOptions = { - cwd: runnable.args.workspaceRoot || '.', - env: definition.env, - }; - const exec = new vscode.ShellExecution( - definition.command, - definition.args, - execOption, - ); - - const f = vscode.workspace.workspaceFolders![0]; - const t = new vscode.Task( - definition, - f, - definition.label, - TASK_SOURCE, - exec, - ['$rustc'], - ); - t.presentationOptions.clear = true; - return t; + const cargoTask = await tasks.buildCargoTask(definition, runnable.label, args, config.cargoRunner); + cargoTask.presentationOptions.clear = true; + + return cargoTask; } -- cgit v1.2.3