-
-
Notifications
You must be signed in to change notification settings - Fork 418
/
index.ts
54 lines (48 loc) · 1.75 KB
/
index.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
import { createLanguageServicePlugin } from '@volar/typescript/lib/quickstart/createLanguageServicePlugin';
import * as vue from '@vue/language-core';
import type * as ts from 'typescript';
import { proxyLanguageServiceForVue } from './lib/common';
import { startNamedPipeServer } from './lib/server';
const windowsPathReg = /\\/g;
const vueCompilerOptions = new WeakMap<ts.server.Project, vue.VueCompilerOptions>();
const plugin = createLanguageServicePlugin(
(ts, info) => {
const vueOptions = getVueCompilerOptions();
const languagePlugin = vue.createVueLanguagePlugin<string>(
ts,
info.languageServiceHost.getCompilationSettings(),
vueOptions,
id => id
);
vueCompilerOptions.set(info.project, vueOptions);
return {
languagePlugins: [languagePlugin],
setup: language => {
info.languageService = proxyLanguageServiceForVue(ts, language, info.languageService, vueOptions, fileName => fileName);
if (
info.project.projectKind === ts.server.ProjectKind.Configured
|| info.project.projectKind === ts.server.ProjectKind.Inferred
) {
startNamedPipeServer(ts, info, language, info.project.projectKind);
}
// #3963
const timer = setInterval(() => {
if (info.project['program']) {
clearInterval(timer);
info.project['program'].__vue__ = { language };
}
}, 50);
}
};
function getVueCompilerOptions() {
if (info.project.projectKind === ts.server.ProjectKind.Configured) {
const tsconfig = info.project.getProjectName();
return vue.createParsedCommandLine(ts, ts.sys, tsconfig.replace(windowsPathReg, '/')).vueOptions;
}
else {
return vue.createParsedCommandLineByJson(ts, ts.sys, info.languageServiceHost.getCurrentDirectory(), {}).vueOptions;
}
}
}
);
export = plugin;