-
Notifications
You must be signed in to change notification settings - Fork 27
/
index.ts
52 lines (43 loc) · 1.62 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
import { PluginStrictFileChecker } from './PluginStrictFileChecker';
import {
log,
PluginInfo,
setupLanguageServiceProxy,
setupStrictLanguageServiceHostProxy,
} from './utils';
import * as ts from 'typescript/lib/tsserverlibrary';
const init: ts.server.PluginModuleFactory = ({ typescript }) => {
function create(info: PluginInfo) {
const proxy = setupLanguageServiceProxy(info);
const strictLanguageServiceHost = setupStrictLanguageServiceHostProxy(info);
const strictLanguageService = typescript.createLanguageService(strictLanguageServiceHost);
log(info, 'Plugin initialized');
proxy.getSemanticDiagnostics = function (filePath) {
const strictFile = new PluginStrictFileChecker(info).isFileStrict(filePath);
if (strictFile) {
return strictLanguageService.getSemanticDiagnostics(filePath);
} else {
return info.languageService.getSemanticDiagnostics(filePath);
}
};
proxy.cleanupSemanticCache = function () {
strictLanguageService.cleanupSemanticCache();
info.languageService.cleanupSemanticCache();
};
proxy.dispose = function () {
strictLanguageService.dispose();
info.languageService.dispose();
};
proxy.getQuickInfoAtPosition = function (filePath, position) {
const strictFile = new PluginStrictFileChecker(info).isFileStrict(filePath);
if (strictFile) {
return strictLanguageService.getQuickInfoAtPosition(filePath, position);
} else {
return info.languageService.getQuickInfoAtPosition(filePath, position);
}
};
return proxy;
}
return { create };
};
module.exports = init;