mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Add custom cargo runners
This commit is contained in:
parent
c544f9a137
commit
a43a9103bc
6 changed files with 72 additions and 55 deletions
|
@ -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 async function createTask(runnable: ra.Runnable, config: Config): Promise<vscode.Task> {
|
||||
if (runnable.kind !== "cargo") {
|
||||
// rust-analyzer supports only one kind, "cargo"
|
||||
// do not use tasks.TASK_TYPE here, these are completely different meanings.
|
||||
|
||||
export function createTask(runnable: ra.Runnable): vscode.Task {
|
||||
const TASK_SOURCE = 'Rust';
|
||||
|
||||
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 cargoTask = await tasks.buildCargoTask(definition, runnable.label, args, config.cargoRunner);
|
||||
cargoTask.presentationOptions.clear = true;
|
||||
|
||||
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;
|
||||
return cargoTask;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue