-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
createProjectService.ts
52 lines (46 loc) · 1.66 KB
/
createProjectService.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 type * as ts from 'typescript/lib/tsserverlibrary';
// eslint-disable-next-line @typescript-eslint/no-empty-function
const doNothing = (): void => {};
const createStubFileWatcher = (): ts.FileWatcher => ({
close: doNothing,
});
export type TypeScriptProjectService = ts.server.ProjectService;
export function createProjectService(
jsDocParsingMode?: ts.JSDocParsingMode,
): TypeScriptProjectService {
// We import this lazily to avoid its cost for users who don't use the service
// TODO: Once we drop support for TS<5.3 we can import from "typescript" directly
const tsserver = require('typescript/lib/tsserverlibrary') as typeof ts;
// TODO: see getWatchProgramsForProjects
// We don't watch the disk, we just refer to these when ESLint calls us
// there's a whole separate update pass in maybeInvalidateProgram at the bottom of getWatchProgramsForProjects
// (this "goes nuclear on TypeScript")
const system: ts.server.ServerHost = {
...tsserver.sys,
clearImmediate,
clearTimeout,
setImmediate,
setTimeout,
watchDirectory: createStubFileWatcher,
watchFile: createStubFileWatcher,
};
return new tsserver.server.ProjectService({
host: system,
cancellationToken: { isCancellationRequested: (): boolean => false },
useSingleInferredProject: false,
useInferredProjectPerProjectRoot: false,
logger: {
close: doNothing,
endGroup: doNothing,
getLogFileName: () => undefined,
hasLevel: () => false,
info: doNothing,
loggingEnabled: () => false,
msg: doNothing,
perftrc: doNothing,
startGroup: doNothing,
},
session: undefined,
jsDocParsingMode,
});
}