1 | /**
|
2 | * @license
|
3 | * Copyright Google LLC All Rights Reserved.
|
4 | *
|
5 | * Use of this source code is governed by an MIT-style license that can be
|
6 | * found in the LICENSE file at https://angular.io/license
|
7 | */
|
8 | /// <amd-module name="@angular/language-service/src/symbols" />
|
9 | import { StaticSymbol } from '@angular/compiler';
|
10 | import * as ts from 'typescript';
|
11 | /**
|
12 | * The range of a span of text in a source file.
|
13 | *
|
14 | * @publicApi
|
15 | */
|
16 | export interface Span {
|
17 | /**
|
18 | * The first code-point of the span as an offset relative to the beginning of the source assuming
|
19 | * a UTF-16 encoding.
|
20 | */
|
21 | start: number;
|
22 | /**
|
23 | * The first code-point after the span as an offset relative to the beginning of the source
|
24 | * assuming a UTF-16 encoding.
|
25 | */
|
26 | end: number;
|
27 | }
|
28 | /**
|
29 | * A file and span.
|
30 | */
|
31 | export interface Location {
|
32 | fileName: string;
|
33 | span: Span;
|
34 | }
|
35 | /**
|
36 | * A defnition location(s).
|
37 | */
|
38 | export declare type Definition = Location[] | undefined;
|
39 | /**
|
40 | * A symbol describing a language element that can be referenced by expressions
|
41 | * in an Angular template.
|
42 | *
|
43 | * @publicApi
|
44 | */
|
45 | export interface Symbol {
|
46 | /**
|
47 | * The name of the symbol as it would be referenced in an Angular expression.
|
48 | */
|
49 | readonly name: string;
|
50 | /**
|
51 | * The kind of completion this symbol should generate if included.
|
52 | */
|
53 | readonly kind: string;
|
54 | /**
|
55 | * The language of the source that defines the symbol. (e.g. typescript for TypeScript,
|
56 | * ng-template for an Angular template, etc.)
|
57 | */
|
58 | readonly language: string;
|
59 | /**
|
60 | * A symbol representing type of the symbol.
|
61 | */
|
62 | readonly type: Symbol | undefined;
|
63 | /**
|
64 | * A symbol for the container of this symbol. For example, if this is a method, the container
|
65 | * is the class or interface of the method. If no container is appropriate, undefined is
|
66 | * returned.
|
67 | */
|
68 | readonly container: Symbol | undefined;
|
69 | /**
|
70 | * The symbol is public in the container.
|
71 | */
|
72 | readonly public: boolean;
|
73 | /**
|
74 | * `true` if the symbol can be the target of a call.
|
75 | */
|
76 | readonly callable: boolean;
|
77 | /**
|
78 | * The location of the definition of the symbol
|
79 | */
|
80 | readonly definition: Definition | undefined;
|
81 | /**
|
82 | * `true` if the symbol is a type that is nullable (can be null or undefined).
|
83 | */
|
84 | readonly nullable: boolean;
|
85 | /**
|
86 | * Documentation comment on the Symbol, if any.
|
87 | */
|
88 | readonly documentation: ts.SymbolDisplayPart[];
|
89 | /**
|
90 | * A table of the members of the symbol; that is, the members that can appear
|
91 | * after a `.` in an Angular expression.
|
92 | */
|
93 | members(): SymbolTable;
|
94 | /**
|
95 | * The list of overloaded signatures that can be used if the symbol is the
|
96 | * target of a call.
|
97 | */
|
98 | signatures(): Signature[];
|
99 | /**
|
100 | * Return which signature of returned by `signatures()` would be used selected
|
101 | * given the `types` supplied. If no signature would match, this method should
|
102 | * return `undefined`.
|
103 | */
|
104 | selectSignature(types: Symbol[]): Signature | undefined;
|
105 | /**
|
106 | * Return the type of the expression if this symbol is indexed by `argument`.
|
107 | * Sometimes we need the key of arguments to get the type of the expression, for example
|
108 | * in the case of tuples (`type Example = [string, number]`).
|
109 | * [string, number]).
|
110 | * If the symbol cannot be indexed, this method should return `undefined`.
|
111 | */
|
112 | indexed(argument: Symbol, key?: any): Symbol | undefined;
|
113 | /**
|
114 | * Returns the type arguments of a Symbol, if any.
|
115 | */
|
116 | typeArguments(): Symbol[] | undefined;
|
117 | }
|
118 | /**
|
119 | * A table of `Symbol`s accessible by name.
|
120 | *
|
121 | * @publicApi
|
122 | */
|
123 | export interface SymbolTable {
|
124 | /**
|
125 | * The number of symbols in the table.
|
126 | */
|
127 | readonly size: number;
|
128 | /**
|
129 | * Get the symbol corresponding to `key` or `undefined` if there is no symbol in the
|
130 | * table by the name `key`.
|
131 | */
|
132 | get(key: string): Symbol | undefined;
|
133 | /**
|
134 | * Returns `true` if the table contains a `Symbol` with the name `key`.
|
135 | */
|
136 | has(key: string): boolean;
|
137 | /**
|
138 | * Returns all the `Symbol`s in the table. The order should be, but is not required to be,
|
139 | * in declaration order.
|
140 | */
|
141 | values(): Symbol[];
|
142 | }
|
143 | /**
|
144 | * A description of a function or method signature.
|
145 | *
|
146 | * @publicApi
|
147 | */
|
148 | export interface Signature {
|
149 | /**
|
150 | * The arguments of the signture. The order of `arguments.symbols()` must be in the order
|
151 | * of argument declaration.
|
152 | */
|
153 | readonly arguments: SymbolTable;
|
154 | /**
|
155 | * The symbol of the signature result type.
|
156 | */
|
157 | readonly result: Symbol;
|
158 | }
|
159 | /**
|
160 | * An enumeration of basic types.
|
161 | *
|
162 | * @publicApi
|
163 | */
|
164 | export declare enum BuiltinType {
|
165 | /**
|
166 | * The type is a type that can hold any other type.
|
167 | */
|
168 | Any = -1,
|
169 | /** Unknown types are functionally identical to any. */
|
170 | Unknown = -1,
|
171 | /**
|
172 | * The type of a string literal.
|
173 | */
|
174 | String = 1,
|
175 | /**
|
176 | * The type of a numeric literal.
|
177 | */
|
178 | Number = 2,
|
179 | /**
|
180 | * The type of the `true` and `false` literals.
|
181 | */
|
182 | Boolean = 4,
|
183 | /**
|
184 | * The type of the `undefined` literal.
|
185 | */
|
186 | Undefined = 8,
|
187 | /**
|
188 | * the type of the `null` literal.
|
189 | */
|
190 | Null = 16,
|
191 | /**
|
192 | * the type is an unbound type parameter.
|
193 | */
|
194 | Unbound = 32,
|
195 | /**
|
196 | * Not a built-in type.
|
197 | */
|
198 | Other = 64,
|
199 | Object = 128
|
200 | }
|
201 | /**
|
202 | * The kinds of definition.
|
203 | *
|
204 | * @publicApi
|
205 | */
|
206 | export declare type DeclarationKind = 'attribute' | 'html attribute' | 'component' | 'element' | 'entity' | 'key' | 'method' | 'pipe' | 'property' | 'type' | 'reference' | 'variable';
|
207 | /**
|
208 | * Describes a symbol to type binding used to build a symbol table.
|
209 | *
|
210 | * @publicApi
|
211 | */
|
212 | export interface SymbolDeclaration {
|
213 | /**
|
214 | * The name of the symbol in table.
|
215 | */
|
216 | readonly name: string;
|
217 | /**
|
218 | * The kind of symbol to declare.
|
219 | */
|
220 | readonly kind: DeclarationKind;
|
221 | /**
|
222 | * Type of the symbol. The type symbol should refer to a symbol for a type.
|
223 | */
|
224 | readonly type: Symbol;
|
225 | /**
|
226 | * The definion of the symbol if one exists.
|
227 | */
|
228 | readonly definition?: Definition;
|
229 | }
|
230 | /**
|
231 | * Information about the pipes that are available for use in a template.
|
232 | *
|
233 | * @publicApi
|
234 | */
|
235 | export interface PipeInfo {
|
236 | /**
|
237 | * The name of the pipe.
|
238 | */
|
239 | name: string;
|
240 | /**
|
241 | * The static symbol for the pipe's constructor.
|
242 | */
|
243 | symbol: StaticSymbol;
|
244 | }
|
245 | /**
|
246 | * A sequence of pipe information.
|
247 | *
|
248 | * @publicApi
|
249 | */
|
250 | export declare type Pipes = PipeInfo[] | undefined;
|
251 | /**
|
252 | * Describes the language context in which an Angular expression is evaluated.
|
253 | *
|
254 | * @publicApi
|
255 | */
|
256 | export interface SymbolQuery {
|
257 | /**
|
258 | * Return the built-in type this symbol represents or Other if it is not a built-in type.
|
259 | */
|
260 | getTypeKind(symbol: Symbol): BuiltinType;
|
261 | /**
|
262 | * Return a symbol representing the given built-in type.
|
263 | */
|
264 | getBuiltinType(kind: BuiltinType): Symbol;
|
265 | /**
|
266 | * Return the symbol for a type that represents the union of all the types given. Any value
|
267 | * of one of the types given should be assignable to the returned type. If no one type can
|
268 | * be constructed then this should be the Any type.
|
269 | */
|
270 | getTypeUnion(...types: Symbol[]): Symbol;
|
271 | /**
|
272 | * Return a symbol for an array type that has the `type` as its element type.
|
273 | */
|
274 | getArrayType(type: Symbol): Symbol;
|
275 | /**
|
276 | * Return element type symbol for an array type if the `type` is an array type. Otherwise return
|
277 | * undefined.
|
278 | */
|
279 | getElementType(type: Symbol): Symbol | undefined;
|
280 | /**
|
281 | * Return a type that is the non-nullable version of the given type. If `type` is already
|
282 | * non-nullable, return `type`.
|
283 | */
|
284 | getNonNullableType(type: Symbol): Symbol;
|
285 | /**
|
286 | * Return a symbol table for the pipes that are in scope.
|
287 | */
|
288 | getPipes(): SymbolTable;
|
289 | /**
|
290 | * Return the type symbol for the given static symbol.
|
291 | */
|
292 | getTypeSymbol(type: StaticSymbol): Symbol | undefined;
|
293 | /**
|
294 | * Return the members that are in the context of a type's template reference.
|
295 | */
|
296 | getTemplateContext(type: StaticSymbol): SymbolTable | undefined;
|
297 | /**
|
298 | * Produce a symbol table with the given symbols. Used to produce a symbol table
|
299 | * for use with mergeSymbolTables().
|
300 | */
|
301 | createSymbolTable(symbols: SymbolDeclaration[]): SymbolTable;
|
302 | /**
|
303 | * Produce a merged symbol table. If the symbol tables contain duplicate entries
|
304 | * the entries of the latter symbol tables will obscure the entries in the prior
|
305 | * symbol tables.
|
306 | *
|
307 | * The symbol tables passed to this routine MUST be produces by the same instance
|
308 | * of SymbolQuery that is being called.
|
309 | */
|
310 | mergeSymbolTable(symbolTables: SymbolTable[]): SymbolTable;
|
311 | /**
|
312 | * Return the span of the narrowest non-token node at the given location.
|
313 | */
|
314 | getSpanAt(line: number, column: number): Span | undefined;
|
315 | }
|