-
Notifications
You must be signed in to change notification settings - Fork 24.8k
/
ts_plugin.ts
80 lines (70 loc) 路 2.81 KB
/
ts_plugin.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as ts from 'typescript/lib/tsserverlibrary';
import {LanguageService} from './language_service';
export function create(info: ts.server.PluginCreateInfo): ts.LanguageService {
const {project, languageService: tsLS, config} = info;
const angularOnly = config?.angularOnly === true;
const ngLS = new LanguageService(project, tsLS);
function getSemanticDiagnostics(fileName: string): ts.Diagnostic[] {
const diagnostics: ts.Diagnostic[] = [];
if (!angularOnly) {
diagnostics.push(...tsLS.getSemanticDiagnostics(fileName));
}
diagnostics.push(...ngLS.getSemanticDiagnostics(fileName));
return diagnostics;
}
function getQuickInfoAtPosition(fileName: string, position: number): ts.QuickInfo|undefined {
if (angularOnly) {
return ngLS.getQuickInfoAtPosition(fileName, position);
} else {
// If TS could answer the query, then return that result. Otherwise, return from Angular LS.
return tsLS.getQuickInfoAtPosition(fileName, position) ??
ngLS.getQuickInfoAtPosition(fileName, position);
}
}
function getTypeDefinitionAtPosition(
fileName: string, position: number): readonly ts.DefinitionInfo[]|undefined {
if (angularOnly) {
return ngLS.getTypeDefinitionAtPosition(fileName, position);
} else {
// If TS could answer the query, then return that result. Otherwise, return from Angular LS.
return tsLS.getTypeDefinitionAtPosition(fileName, position) ??
ngLS.getTypeDefinitionAtPosition(fileName, position);
}
}
function getDefinitionAndBoundSpan(
fileName: string, position: number): ts.DefinitionInfoAndBoundSpan|undefined {
if (angularOnly) {
return ngLS.getDefinitionAndBoundSpan(fileName, position);
} else {
// If TS could answer the query, then return that result. Otherwise, return from Angular LS.
return tsLS.getDefinitionAndBoundSpan(fileName, position) ??
ngLS.getDefinitionAndBoundSpan(fileName, position);
}
}
function getReferencesAtPosition(fileName: string, position: number): ts.ReferenceEntry[]|
undefined {
return ngLS.getReferencesAtPosition(fileName, position);
}
function findRenameLocations(
fileName: string, position: number, findInStrings: boolean, findInComments: boolean,
providePrefixAndSuffixTextForRename?: boolean): readonly ts.RenameLocation[]|undefined {
// TODO(atscott): implement
return undefined;
}
return {
...tsLS,
getSemanticDiagnostics,
getTypeDefinitionAtPosition,
getQuickInfoAtPosition,
getDefinitionAndBoundSpan,
getReferencesAtPosition,
findRenameLocations,
};
}