mirror of
https://github.com/jlengrand/elm-language-client-vscode.git
synced 2026-03-10 08:11:17 +00:00
Add test commands
This commit is contained in:
@@ -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()) {
|
||||
|
||||
10
package.json
10
package.json
@@ -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
2
server
Submodule server updated: f511b81850...6ce009b897
Reference in New Issue
Block a user