Code lens support for running tests

This commit is contained in:
Jeremy A. Kolb 2019-01-11 15:16:55 -05:00
parent 738c958a04
commit faf0037635
7 changed files with 198 additions and 87 deletions

View file

@ -4,6 +4,7 @@ import * as joinLines from './join_lines';
import * as matchingBrace from './matching_brace';
import * as onEnter from './on_enter';
import * as parentModule from './parent_module';
import * as runSingle from './run_single';
import * as runnables from './runnables';
import * as syntaxTree from './syntaxTree';
@ -13,6 +14,7 @@ export {
joinLines,
matchingBrace,
parentModule,
runSingle,
runnables,
syntaxTree,
onEnter

View file

@ -0,0 +1,63 @@
import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';
interface Runnable {
range: lc.Range;
label: string;
bin: string;
args: string[];
env: { [index: string]: string };
}
interface CargoTaskDefinition extends vscode.TaskDefinition {
type: 'cargo';
label: string;
command: string;
args: string[];
env?: { [key: string]: string };
}
function createTask(spec: Runnable): vscode.Task {
const TASK_SOURCE = 'Rust';
const definition: CargoTaskDefinition = {
type: 'cargo',
label: 'cargo',
command: spec.bin,
args: spec.args,
env: spec.env
};
const execOption: vscode.ShellExecutionOptions = {
cwd: '.',
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;
}
export async function handle(runnable: Runnable) {
const editor = vscode.window.activeTextEditor;
if (editor == null || editor.document.languageId !== 'rust') {
return;
}
const task = createTask(runnable);
task.group = vscode.TaskGroup.Build;
task.presentationOptions = {
reveal: vscode.TaskRevealKind.Always,
panel: vscode.TaskPanelKind.Dedicated,
};
return vscode.tasks.executeTask(task);
}

View file

@ -55,6 +55,9 @@ export function activate(context: vscode.ExtensionContext) {
);
overrideCommand('type', commands.onEnter.handle);
// Unlike the above this does not send requests to the language server
registerCommand('ra-lsp.run-single', commands.runSingle.handle);
// Notifications are events triggered by the language server
const allNotifications: Iterable<
[string, lc.GenericNotificationHandler]