-
-
Notifications
You must be signed in to change notification settings - Fork 364
/
nodeClientMain.ts
84 lines (75 loc) · 2.48 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
77
78
79
80
81
82
83
84
import { ServerMode } from '@volar/vue-language-server';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as vscode from 'vscode';
import * as lsp from 'vscode-languageclient/node';
import { activate as commonActivate, deactivate as commonDeactivate, getDocumentSelector } from './common';
import { middleware } from './middleware';
export function activate(context: vscode.ExtensionContext) {
const cancellationPipeName = path.join(os.tmpdir(), `vscode-${context.extension.id}-cancellation-pipe.tmp`);
const langs = getDocumentSelector(ServerMode.Semantic);
let cancellationPipeUpdateKey: string | undefined;
vscode.workspace.onDidChangeTextDocument((e) => {
let key = e.document.uri.toString() + '|' + e.document.version;
if (cancellationPipeUpdateKey === undefined) {
cancellationPipeUpdateKey = key;
return;
}
if (langs.includes(e.document.languageId) && cancellationPipeUpdateKey !== key) {
cancellationPipeUpdateKey = key;
fs.writeFileSync(cancellationPipeName, '');
}
});
return commonActivate(context, async (
id,
name,
langs,
initOptions,
fillInitializeParams,
port,
) => {
initOptions.cancellationPipeName = cancellationPipeName;
class _LanguageClient extends lsp.LanguageClient {
fillInitializeParams(params: lsp.InitializeParams) {
fillInitializeParams(params);
}
}
const serverModule = vscode.Uri.joinPath(context.extensionUri, 'server.js');
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,
documentSelector: langs.map<lsp.DocumentFilter>(lang => ({ language: lang })),
initializationOptions: initOptions,
progressOnInitialization: true,
};
const client = new _LanguageClient(
id,
name,
serverOptions,
clientOptions,
);
await client.start();
return client;
});
}
export function deactivate(): Thenable<any> | undefined {
return commonDeactivate();
}