diff --git a/package.json b/package.json index ce8ac8e9..92041d74 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "theme": "dark" }, "engines": { - "vscode": "^1.22.0" + "vscode": "^1.24.0" }, "license": "(MIT OR Apache-2.0)", "repository": { diff --git a/src/extension.ts b/src/extension.ts index 2d532e28..99a05c54 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -13,7 +13,7 @@ import { runRlsViaRustup, rustupUpdate } from './rustup'; import { startSpinner, stopSpinner } from './spinner'; import { RLSConfiguration } from './configuration'; -import { activateTaskProvider } from './tasks'; +import { activateTaskProvider, runCommand } from './tasks'; import * as child_process from 'child_process'; import * as fs from 'fs'; @@ -170,7 +170,10 @@ class ClientWorkspace { synchronize: { configurationSection: 'rust' }, // Controls when to focus the channel rather than when to reveal it in the drop-down list revealOutputChannelOn: this.config.revealOutputChannelOn, - initializationOptions: { omitInitBuild: true }, + initializationOptions: { + omitInitBuild: true, + cmdRun: true, + }, workspaceFolder: this.folder, }; @@ -236,6 +239,10 @@ class ClientWorkspace { return this.start(context); }); context.subscriptions.push(restartServer); + + context.subscriptions.push( + commands.registerCommand('rls.run', (cmd) => runCommand(this.folder, cmd)) + ); } async progressCounter() { diff --git a/src/tasks.ts b/src/tasks.ts index 101264e9..e6666969 100644 --- a/src/tasks.ts +++ b/src/tasks.ts @@ -8,20 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -import { - Disposable, - TaskProvider, - Task, - TaskDefinition, - TaskGroup, - TaskPanelKind, - TaskPresentationOptions, - TaskRevealKind, - ShellExecution, - ShellExecutionOptions, - workspace, - WorkspaceFolder, -} from 'vscode'; +import { Disposable, ShellExecution, ShellExecutionOptions, Task, TaskDefinition, TaskGroup, TaskPanelKind, TaskPresentationOptions, TaskProvider, TaskRevealKind, WorkspaceFolder, workspace, tasks } from 'vscode'; export function activateTaskProvider(target: WorkspaceFolder): Disposable { const provider: TaskProvider = { @@ -46,6 +33,7 @@ interface CargoTaskDefinition extends TaskDefinition { label: string; command: string; args: Array; + env?: { [key: string]: string }; } interface TaskConfigItem { @@ -72,6 +60,7 @@ function createTask({ definition, group, presentationOptions, problemMatcher }: const execCmd = `${definition.command} ${definition.args.join(' ')}`; const execOption: ShellExecutionOptions = { cwd: target.uri.path, + env: definition.env, }; const exec = new ShellExecution(execCmd, execOption); @@ -178,3 +167,29 @@ function createTaskConfigItem(): Array { return taskList; } + +export interface Cmd { + binary: string; + args: string[]; + env: { [key: string]: string }; +} + +export function runCommand(folder: WorkspaceFolder, cmd: Cmd) { + const config: TaskConfigItem = { + definition: { + label: 'run Cargo command', + type: 'shell', + command: cmd.binary, + args: cmd.args, + env: cmd.env, + }, + problemMatcher: ['$rustc'], + group: TaskGroup.Build, + presentationOptions: { + reveal: TaskRevealKind.Always, + panel: TaskPanelKind.New, + }, + }; + const task = createTask(config, folder); + tasks.executeTask(task); +}