forked from nulang-org/nulang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
72 lines (61 loc) · 1.91 KB
/
Copy pathextension.js
File metadata and controls
72 lines (61 loc) · 1.91 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
// Nulang VS Code Extension — LSP Client
//
// Launches `nulang --lsp` as the language server and wires it to the
// VS Code Language Client API for diagnostics, goto-definition,
// references, hover, completion, and more.
//
// Install: copy this directory to ~/.vscode/extensions/nulang/
// or run: npx @vscode/vsce package && code --install-extension nulang-0.1.0.vsix
const vscode = require('vscode');
const path = require('path');
const { LanguageClient, TransportKind } = require('vscode-languageclient/node');
/** @type {LanguageClient} */
let client;
/**
* Resolve the `nulang` binary path.
*
* Checks NULANG_PATH env var first, then PATH, then falls back to
* `nulang` (hoping it's on the user's PATH).
*/
function resolveNulangPath() {
const envPath = process.env.NULANG_PATH;
if (envPath) return envPath;
return 'nulang';
}
async function activate(context) {
const serverPath = resolveNulangPath();
const serverOptions = {
command: serverPath,
args: ['--lsp'],
transport: TransportKind.stdio
};
const clientOptions = {
documentSelector: [{ scheme: 'file', language: 'nulang' }],
synchronize: {
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.nula')
}
};
client = new LanguageClient(
'nulang-lsp',
'Nulang Language Server',
serverOptions,
clientOptions
);
await client.start();
// Register restart command
context.subscriptions.push(
vscode.commands.registerCommand('nulang.restartServer', async () => {
if (client) {
await client.stop();
await client.start();
vscode.window.showInformationMessage('Nulang language server restarted');
}
})
);
}
async function deactivate() {
if (client) {
await client.stop();
}
}
module.exports = { activate, deactivate };