-
-
Notifications
You must be signed in to change notification settings - Fork 405
/
node.ts
55 lines (50 loc) · 1.84 KB
/
node.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
import { createConnection, createServer, loadTsdkByPath } from '@volar/language-server/node';
import { createParsedCommandLine, createVueLanguagePlugin, resolveVueCompilerOptions } from '@vue/language-core';
import { getHybridModeLanguageServicePlugins } from '@vue/language-service';
import * as namedPipeClient from '@vue/typescript-plugin/lib/client';
import { createHybridModeProject } from './lib/hybridModeProject';
import { initialize } from './lib/initialize';
import type { VueInitializationOptions } from './lib/types';
const connection = createConnection();
const server = createServer(connection);
connection.listen();
connection.onInitialize(params => {
const options: VueInitializationOptions = params.initializationOptions;
const { typescript: ts, diagnosticMessages } = loadTsdkByPath(options.typescript.tsdk, params.locale);
const hybridMode = options.vue?.hybridMode ?? true;
if (hybridMode) {
return server.initialize(
params,
createHybridModeProject(
({ asFileName, configFileName }) => {
const commandLine = configFileName
? createParsedCommandLine(ts, ts.sys, configFileName)
: {
vueOptions: resolveVueCompilerOptions({}),
options: ts.getDefaultCompilerOptions(),
};
commandLine.vueOptions.__test = params.initializationOptions.typescript.disableAutoImportCache;
return {
languagePlugins: [
createVueLanguagePlugin(
ts,
commandLine.options,
commandLine.vueOptions,
asFileName
),
],
setup({ project }) {
project.vue = { compilerOptions: commandLine.vueOptions };
},
};
}
),
getHybridModeLanguageServicePlugins(ts, namedPipeClient)
);
}
else {
return initialize(server, params, ts, diagnosticMessages);
}
});
connection.onInitialized(server.initialized);
connection.onShutdown(server.shutdown);