Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"theme": "dark"
},
"engines": {
"vscode": "^1.22.0"
"vscode": "^1.24.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this for the new tasks API. What vscode compatability strategy do we follow?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest stable and insiders only for now

},
"license": "(MIT OR Apache-2.0)",
"repository": {
Expand Down
11 changes: 9 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
};

Expand Down Expand Up @@ -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() {
Expand Down
43 changes: 29 additions & 14 deletions src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -46,6 +33,7 @@ interface CargoTaskDefinition extends TaskDefinition {
label: string;
command: string;
args: Array<string>;
env?: { [key: string]: string };
}

interface TaskConfigItem {
Expand All @@ -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);

Expand Down Expand Up @@ -178,3 +167,29 @@ function createTaskConfigItem(): Array<TaskConfigItem> {

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);
}