-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
54 lines (46 loc) · 1.2 KB
/
extension.js
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
const vscode = require("vscode");
const chokidar = require("chokidar");
const ignored = /(^|[\/\\])\..|node_modules/;
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
const root = vscode.workspace.workspaceFolders[0].uri.toString();
const cwd = root.replace("file://", "");
const gitmd = require("./index")(cwd);
const onErr = (err) => {
const { type, message } = err;
vscode.window.showErrorMessage("GITMD ERROR: " + type + message);
};
gitmd.server().then(({ port, kill }) => {
const link = "http://localhost:" + port;
gitmd.worker(onErr);
setTimeout(() => {
vscode.commands.executeCommand("vscode.open", link);
}, 1000);
context.subscriptions.push({
dispose() {
kill()
}
});
});
const dispose = vscode.workspace.onDidSaveTextDocument(() => {
gitmd.worker(onErr);
});
const watcher = chokidar
.watch(cwd, { interval: 2000, ignored: ignored })
.on("all", () => {
gitmd.worker(onErr);
});
context.subscriptions.push(dispose);
context.subscriptions.push({
dispose() {
watcher.close();
}
});
}
function deactivate() {}
module.exports = {
activate,
deactivate,
};