-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextension.js
More file actions
109 lines (97 loc) · 3.06 KB
/
extension.js
File metadata and controls
109 lines (97 loc) · 3.06 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"use strict";
const vscode = require("vscode");
const languageclient = require("vscode-languageclient");
const { exec } = require("node:child_process");
let client;
function activate(context) {
try {
const serverOptions = {
command: "cargo",
args: [
"+stable",
"run",
"--release",
"--manifest-path",
context.extensionPath + "/Cargo.toml",
],
};
const clientOptions = {
documentSelector: [
{
scheme: "file",
language: "egglog",
},
],
};
client = new languageclient.LanguageClient(
"egglog",
serverOptions,
clientOptions
);
context.subscriptions.push(client.start());
} catch (e) {
vscode.window.showErrorMessage(
"egglog-language-server couldn't be started."
);
}
context.subscriptions.push(
vscode.commands.registerCommand("egglog.egglog_run", async function () {
const document = vscode.window.activeTextEditor.document;
document.save().then(() => {
const relativeFile = document.uri.fsPath;
let process_exec = new vscode.ProcessExecution("egglog", [
relativeFile
]);
const task = new vscode.Task({ type: "process" }, vscode.TaskScope.Workspace, "egglog", "egglog", process_exec);
// https://github.com/microsoft/vscode/issues/157756
task.definition.command = "egglog";
vscode.tasks.executeTask(task);
});
})
);
context.subscriptions.push(
vscode.commands.registerCommand("egglog.egglog_desugar", async function () {
const document = vscode.window.activeTextEditor.document;
document.save().then(() => {
const relativeFile = document.uri.fsPath;
let process_exec = new vscode.ProcessExecution("egglog", [
"--show", "desugared-egglog",
relativeFile
]);
const task = new vscode.Task({ type: "process" }, vscode.TaskScope.Workspace, "egglog-desugar", "egglog", process_exec);
task.definition.command = "egglog";
vscode.tasks.executeTask(task);
});
})
);
context.subscriptions.push(
vscode.commands.registerCommand(
"egglog.egglog_dot_preview",
async function () {
const document = vscode.window.activeTextEditor.document;
document.save().then(() => {
const relativeFile = document.uri.fsPath;
const command = `egglog --to-dot ${relativeFile}`;
exec(command).on("exit", (code) => {
if (code === 0) {
const dotFile = vscode.Uri.parse(
relativeFile.replace(/\.egg$/, "") + ".dot"
);
vscode.workspace.openTextDocument(dotFile).then((doc) => {
vscode.window.showTextDocument(doc, 1, false);
});
} else {
vscode.window.showErrorMessage(
`${command} exited with code ${code}`
);
}
});
});
}
)
);
}
function deactivate() {
if (client) return client.stop();
}
module.exports = { activate, deactivate };