|
1 | 1 | import { PluginStrictFileChecker } from './PluginStrictFileChecker'; |
2 | | -import { log, PluginInfo, setupProxy, turnOffStrictMode, turnOnStrictMode } from './utils'; |
| 2 | +import { |
| 3 | + log, |
| 4 | + PluginInfo, |
| 5 | + setupLanguageServiceProxy, |
| 6 | + setupStrictLanguageServiceHostProxy, |
| 7 | +} from './utils'; |
3 | 8 | import * as ts from 'typescript/lib/tsserverlibrary'; |
4 | 9 |
|
5 | | -const init: ts.server.PluginModuleFactory = () => { |
| 10 | +const init: ts.server.PluginModuleFactory = ({ typescript }) => { |
6 | 11 | function create(info: PluginInfo) { |
7 | | - const proxy = setupProxy(info); |
| 12 | + const proxy = setupLanguageServiceProxy(info); |
| 13 | + |
| 14 | + const strictLanguageServiceHost = setupStrictLanguageServiceHostProxy(info); |
| 15 | + const strictLanguageService = typescript.createLanguageService(strictLanguageServiceHost); |
| 16 | + |
8 | 17 | log(info, 'Plugin initialized'); |
9 | 18 |
|
10 | 19 | proxy.getSemanticDiagnostics = function (filePath) { |
11 | 20 | const strictFile = new PluginStrictFileChecker(info).isFileStrict(filePath); |
12 | 21 |
|
13 | 22 | if (strictFile) { |
14 | | - turnOnStrictMode(info); |
| 23 | + return strictLanguageService.getSemanticDiagnostics(filePath); |
15 | 24 | } else { |
16 | | - turnOffStrictMode(info); |
| 25 | + return info.languageService.getSemanticDiagnostics(filePath); |
17 | 26 | } |
18 | | - |
19 | | - return info.languageService.getSemanticDiagnostics(filePath); |
| 27 | + }; |
| 28 | + proxy.cleanupSemanticCache = function () { |
| 29 | + strictLanguageService.cleanupSemanticCache(); |
| 30 | + info.languageService.cleanupSemanticCache(); |
| 31 | + }; |
| 32 | + proxy.dispose = function () { |
| 33 | + strictLanguageService.dispose(); |
| 34 | + info.languageService.dispose(); |
20 | 35 | }; |
21 | 36 |
|
22 | 37 | return proxy; |
|
0 commit comments