Repository navigation
Expand file tree
/
Copy pathextension.js
More file actions
75 lines (58 loc) · 2.13 KB
/
Copy pathextension.js
File metadata and controls
75 lines (58 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const vscode = require("vscode");
const { spawn } = require("child_process");
function activate(context) {
const output = vscode.window.createOutputChannel("Lambda Discipline");
const runCurrentFile = vscode.commands.registerCommand(
"lbd.runCurrentFile",
() => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showErrorMessage("No active editor.");
return;
}
if (editor.document.languageId !== "lbd") {
vscode.window.showErrorMessage(
"The current file is not a Lambda Discipline file."
);
return;
}
const file = editor.document.fileName;
output.clear();
output.show(true);
const process = spawn("lbd", ["run", file], {
cwd: vscode.workspace.getWorkspaceFolder(
editor.document.uri
)?.uri.fsPath
});
process.stdout.on("data", data => {
output.append(data.toString());
});
process.stderr.on("data", data => {
output.append(data.toString());
});
process.on("error", error => {
if (error.code === "ENOENT") {
vscode.window.showErrorMessage(
"Lambda Discipline interpreter 'lbd' was not found. " +
"Make sure lbd is installed and available on PATH."
);
output.appendLine(
"Error: Lambda Discipline interpreter 'lbd' was not found."
);
return;
}
output.appendLine(`Error: ${error.message}`);
});
process.on("close", code => {
output.appendLine("");
output.appendLine(`Process exited with code ${code}.`);
});
}
);
context.subscriptions.push(runCurrentFile, output);
}
function deactivate() { }
module.exports = {
activate,
deactivate
};