mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-11-27 15:01:22 +08:00
vscode: Minor refactors.
This commit is contained in:
parent
1cafee12e2
commit
ae791f1f51
|
@ -2,7 +2,7 @@
|
|||
"name": "elvish",
|
||||
"displayName": "Elvish",
|
||||
"description": "Elvish language support for Visual Studio Code",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"publisher": "elves",
|
||||
"license": "BSD-2-Clause",
|
||||
"icon": "icon.png",
|
||||
|
|
|
@ -5,7 +5,7 @@ import { LanguageClient } from 'vscode-languageclient/node';
|
|||
|
||||
let client: LanguageClient | undefined;
|
||||
|
||||
function activate(context: vscode.ExtensionContext) {
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
client = new LanguageClient(
|
||||
"elvish",
|
||||
"Elvish Language Server",
|
||||
|
@ -19,10 +19,8 @@ function activate(context: vscode.ExtensionContext) {
|
|||
updateTranscriptOutputForCodeAtCursor));
|
||||
}
|
||||
|
||||
function deactivate() {
|
||||
if (client) {
|
||||
return client.stop();
|
||||
}
|
||||
export function deactivate() {
|
||||
return client?.stop();
|
||||
}
|
||||
|
||||
interface UpdateInstruction {
|
||||
|
@ -37,14 +35,20 @@ async function updateTranscriptOutputForCodeAtCursor() {
|
|||
return;
|
||||
}
|
||||
const {dir, base} = path.parse(editor.document.uri.fsPath);
|
||||
// VS Code's line number is 0-based, but the ELVISH_TRANSCRIPT_RUN protocol
|
||||
// uses 1-based line numbers. This is also used in the UI, where the user
|
||||
// expects 1-based line numbers.
|
||||
const lineno = editor.selection.active.line + 1;
|
||||
|
||||
await vscode.window.withProgress({
|
||||
location: vscode.ProgressLocation.Notification,
|
||||
title: `Running ${base}:${lineno}...`
|
||||
}, async (progress, token) => {
|
||||
// Transcript tests uses what's on the disk, so we have to save the
|
||||
// document first.
|
||||
await editor.document.save();
|
||||
|
||||
// See godoc of pkg/eval/evaltest for the protocol.
|
||||
const {error, stdout} = await exec(
|
||||
"go test -run TestTranscripts",
|
||||
{
|
||||
|
@ -75,6 +79,7 @@ async function updateTranscriptOutputForCodeAtCursor() {
|
|||
});
|
||||
}
|
||||
|
||||
// Wraps child_process.exec to return a promise.
|
||||
function exec(cmd: string, options: child_process.ExecOptions):
|
||||
Promise<{error: child_process.ExecException|null, stdout: string, stderr: string}> {
|
||||
return new Promise((resolve) => {
|
||||
|
@ -83,8 +88,3 @@ function exec(cmd: string, options: child_process.ExecOptions):
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
activate,
|
||||
deactivate,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user