/
nodeClientMain.ts
76 lines (72 loc) · 2.12 KB
/
nodeClientMain.ts
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
import * as vscode from 'vscode';
import * as lsp from 'vscode-languageclient/node';
import { activate as commonActivate, deactivate as commonDeactivate } from './common';
export function activate(context: vscode.ExtensionContext) {
return commonActivate(context, async (
id,
name,
documentSelector,
initOptions,
port,
) => {
const serverModule = vscode.Uri.joinPath(context.extensionUri, 'server');
const maxOldSpaceSize = vscode.workspace.getConfiguration('volar').get<number | null>('vueserver.maxOldSpaceSize');
const runOptions = { execArgv: <string[]>[] };
if (maxOldSpaceSize) {
runOptions.execArgv.push("--max-old-space-size=" + maxOldSpaceSize);
}
const debugOptions = { execArgv: ['--nolazy', '--inspect=' + port] };
const serverOptions: lsp.ServerOptions = {
run: {
module: serverModule.fsPath,
transport: lsp.TransportKind.ipc,
options: runOptions
},
debug: {
module: serverModule.fsPath,
transport: lsp.TransportKind.ipc,
options: debugOptions
},
};
const clientOptions: lsp.LanguageClientOptions = {
middleware: {
handleDiagnostics: (uri, diagnostics, next) => {
const document = vscode.workspace.textDocuments.find(d => d.uri.toString() === uri.toString());
if (document) {
let outdated = false;
for (const diagnostic of diagnostics) {
const data = (diagnostic as any).data;
if (typeof data === 'object' && 'version' in data) {
if (document.version !== data.version) {
outdated = true;
break;
}
}
}
if (outdated) {
return;
}
}
next(uri, diagnostics);
},
},
documentSelector,
initializationOptions: initOptions,
progressOnInitialization: true,
synchronize: {
fileEvents: vscode.workspace.createFileSystemWatcher('{**/*.vue,**/*.md,**/*.html,**/*.js,**/*.jsx,**/*.ts,**/*.tsx,**/*.json}')
}
};
const client = new lsp.LanguageClient(
id,
name,
serverOptions,
clientOptions,
);
await client.start();
return client;
}, 'node');
}
export function deactivate(): Thenable<any> | undefined {
return commonDeactivate();
}