Add test commands

This commit is contained in:
Kolja Lampe
2019-12-04 19:55:48 +01:00
parent 22838b669c
commit c00cc0c450
3 changed files with 48 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ import * as path from "path";
import {
CancellationToken,
CodeLens,
commands,
ExtensionContext,
Location,
OutputChannel,
@@ -37,6 +38,7 @@ export interface IClientSettings {
}
const clients: Map<string, LanguageClient> = new Map();
let elmCommandsRegistered: boolean = false;
let sortedWorkspaceFolders: string[] | undefined;
@@ -148,8 +150,12 @@ export async function activate(context: ExtensionContext) {
client.start();
clients.set(folder.uri.toString(), client);
}
if (elmCommandsRegistered) {
registerElmCommand("elmLS.runTests", context);
registerElmCommand("elmLS.runTestsCurrentFile", context);
elmCommandsRegistered = true;
}
}
Workspace.onDidOpenTextDocument(didOpenTextDocument);
Workspace.textDocuments.forEach(didOpenTextDocument);
Workspace.onDidChangeWorkspaceFolders(event => {
@@ -166,6 +172,36 @@ export async function activate(context: ExtensionContext) {
packageDisposables.forEach(d => context.subscriptions.push(d));
}
async function registerElmCommand(command: string, context: ExtensionContext) {
const editorCmd = commands.registerTextEditorCommand(
command,
(editor, edit) => {
const cmd = {
arguments: [
{
file: editor.document.uri.toString(),
pos: editor.selections[0].active,
},
],
command,
};
// Get the current file and workspace folder.
const uri = editor.document.uri;
const folder = Workspace.getWorkspaceFolder(uri);
// If there is a client registered for this workspace, use that client.
if (folder !== undefined && clients.has(folder.uri.toString())) {
const client = clients.get(folder.uri.toString());
if (client !== undefined) {
client.sendRequest("workspace/executeCommand", cmd).then(_ => {
return true;
});
}
}
},
);
context.subscriptions.push(editorCmd);
}
export function deactivate(): Thenable<void> | undefined {
const promises: Array<Thenable<void>> = [];
for (const client of clients.values()) {

View File

@@ -78,6 +78,16 @@
"command": "elm.browsePackage",
"title": "Browse Package",
"category": "Elm"
},
{
"command": "elmLS.runTestsCurrentFile",
"title": "Run tests for this file",
"category": "Elm"
},
{
"command": "elmLS.runTests",
"title": "Run all tests",
"category": "Elm"
}
],
"configuration": {

2
server

Submodule server updated: f511b81850...6ce009b897