-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathinterfaces.ts
More file actions
326 lines (294 loc) · 9.59 KB
/
interfaces.ts
File metadata and controls
326 lines (294 loc) · 9.59 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
import type { Range, Diagnostic, CodeAction, SemanticTokenTypes, SemanticTokenModifiers } from 'vscode-languageserver';
import type { Scope } from './Scope';
import type { BrsFile } from './files/BrsFile';
import type { XmlFile } from './files/XmlFile';
import type { FunctionScope } from './FunctionScope';
import type { FunctionType } from './types/FunctionType';
import type { ParseMode } from './parser/Parser';
import type { Program, SourceObj, TranspileObj } from './Program';
import type { ProgramBuilder } from './ProgramBuilder';
import type { FunctionStatement } from './parser/Statement';
import type { Expression } from './parser/Expression';
import type { TranspileState } from './parser/TranspileState';
import type { SourceMapGenerator, SourceNode } from 'source-map';
import type { BscType } from './types/BscType';
import type { AstEditor } from './astUtils/AstEditor';
export interface BsDiagnostic extends Diagnostic {
file: BscFile;
/**
* A generic data container where additional details of the diagnostic can be stored. These are stripped out before being sent to a languageclient, and not printed to the console.
*/
data?: any;
}
export type BscFile = BrsFile | XmlFile;
export interface Callable {
file: BscFile;
name: string;
/**
* Is the callable declared as "sub". If falsey, assumed declared as "function"
*/
isSub: boolean;
type: FunctionType;
/**
* A short description of the callable. Should be a short sentence.
*/
shortDescription?: string;
/**
* A more lengthy explanation of the callable. This is parsed as markdown
*/
documentation?: string;
params: CallableParam[];
/**
* The full range of the function or sub.
*/
range: Range;
/**
* The range of the name of this callable
*/
nameRange?: Range;
isDeprecated?: boolean;
getName: (parseMode: ParseMode) => string;
/**
* Indicates whether or not this callable has an associated namespace
*/
hasNamespace: boolean;
/**
* Gives access to the whole statement if you need more data than provided by the interface
*/
functionStatement: FunctionStatement;
}
export interface FunctionCall {
/**
* The full range of this function call (from the start of the function name to its closing paren)
*/
range: Range;
functionScope: FunctionScope;
file: File;
name: string;
args: CallableArg[];
nameRange: Range;
}
/**
* An argument for an expression call.
*/
export interface CallableArg {
text: string;
type: BscType;
range: Range;
}
export interface CallableParam {
name: string;
type: BscType;
/**
* Is this parameter required or optional?
*/
isOptional: boolean;
/**
* Indicates that an unlimited number of arguments can be passed in
*/
isRestArgument?: boolean;
}
export interface FileObj {
src: string;
dest: string;
}
/**
* Represents a file import in a component <script> tag
*/
export interface FileReference {
/**
* The pkgPath to the referenced file.
*/
pkgPath: string;
text: string;
/**
* The file that is doing the import. Note this is NOT the file the pkgPath points to.
*/
sourceFile: XmlFile | BrsFile;
/**
* The full range of this file reference.
* Keep in mind that file references can come from xml script tags
* as well as bs file import statements.
* If the range is null, then this import is derived so skip any location-based logic
*/
filePathRange?: Range;
}
export interface File {
/**
* The absolute path to the file, relative to the pkg
*/
pkgPath: string;
pathAbsolute: string;
getDiagnostics(): BsDiagnostic[];
}
export interface VariableDeclaration {
name: string;
type: BscType;
/**
* The range for the variable name
*/
nameRange: Range;
/**
* Since only one variable can be declared at a time,
* we only need to know the line index
*/
lineIndex: number;
}
export interface LabelDeclaration {
name: string;
/**
* The range for the label name
*/
nameRange: Range;
/**
* The line of the label
*/
lineIndex: number;
}
/**
* A wrapper around a callable to provide more information about where it came from
*/
export interface CallableContainer {
callable: Callable;
scope: Scope;
}
export type CallableContainerMap = Map<string, CallableContainer[]>;
export interface CommentFlag {
file: BscFile;
/**
* The location of the ignore comment.
*/
range: Range;
/**
* The range that this flag applies to (i.e. the lines that should be suppressed/re-enabled)
*/
affectedRange: Range;
codes: DiagnosticCode[] | null;
}
type ValidateHandler = (scope: Scope, files: BscFile[], callables: CallableContainerMap) => void;
export type CompilerPluginFactory = () => CompilerPlugin;
export interface CompilerPlugin {
name: string;
//program events
beforeProgramCreate?: (builder: ProgramBuilder) => void;
beforePrepublish?: (builder: ProgramBuilder, files: FileObj[]) => void;
afterPrepublish?: (builder: ProgramBuilder, files: FileObj[]) => void;
beforePublish?: (builder: ProgramBuilder, files: FileObj[]) => void;
afterPublish?: (builder: ProgramBuilder, files: FileObj[]) => void;
afterProgramCreate?: (program: Program) => void;
beforeProgramValidate?: (program: Program) => void;
afterProgramValidate?: (program: Program) => void;
beforeProgramTranspile?: (program: Program, entries: TranspileObj[]) => void;
afterProgramTranspile?: (program: Program, entries: TranspileObj[]) => void;
onGetCodeActions?: PluginHandler<OnGetCodeActionsEvent>;
onGetSemanticTokens?: PluginHandler<OnGetSemanticTokensEvent>;
//scope events
afterScopeCreate?: (scope: Scope) => void;
beforeScopeDispose?: (scope: Scope) => void;
afterScopeDispose?: (scope: Scope) => void;
beforeScopeValidate?: ValidateHandler;
onScopeValidate?: PluginHandler<OnScopeValidateEvent>;
afterScopeValidate?: ValidateHandler;
//file events
beforeFileParse?: (source: SourceObj) => void;
afterFileParse?: (file: BscFile) => void;
/**
* Called before each file is validated
*/
beforeFileValidate?: PluginHandler<BeforeFileValidateEvent>;
/**
* Called during the file validation process. If your plugin contributes file validations, this is a good place to contribute them.
*/
onFileValidate?: PluginHandler<OnFileValidateEvent>;
/**
* Called after each file is validated
*/
afterFileValidate?: (file: BscFile) => void;
beforeFileTranspile?: PluginHandler<BeforeFileTranspileEvent>;
afterFileTranspile?: PluginHandler<AfterFileTranspileEvent>;
beforeFileDispose?: (file: BscFile) => void;
afterFileDispose?: (file: BscFile) => void;
}
export type PluginHandler<T> = (event: T) => void;
export interface OnGetCodeActionsEvent {
program: Program;
file: BscFile;
range: Range;
scopes: Scope[];
diagnostics: BsDiagnostic[];
codeActions: CodeAction[];
}
export interface OnGetSemanticTokensEvent<T extends BscFile = BscFile> {
program: Program;
file: T;
scopes: Scope[];
semanticTokens: SemanticToken[];
}
export interface BeforeFileValidateEvent<T extends BscFile = BscFile> {
program: Program;
file: T;
}
export interface OnFileValidateEvent<T extends BscFile = BscFile> {
program: Program;
file: T;
}
export interface OnScopeValidateEvent {
program: Program;
scope: Scope;
}
export type Editor = Pick<AstEditor, 'addToArray' | 'hasChanges' | 'removeFromArray' | 'setArrayValue' | 'setProperty'>;
export interface BeforeFileTranspileEvent {
file: BscFile;
outputPath: string;
/**
* An editor that can be used to transform properties or arrays. Once the `afterFileTranspile` event has fired, these changes will be reverted,
* restoring the objects to their prior state. This is useful for changing code right before a file gets transpiled, but when you don't want
* the changes to persist in the in-memory file.
*/
editor: Editor;
}
export interface AfterFileTranspileEvent {
file: BscFile;
outputPath: string;
/**
* The resulting transpiled file contents
*/
code: string;
/**
* The sourceMaps for the generated code (if emitting source maps is enabled)
*/
map?: SourceMapGenerator;
/**
* The generated type definition file contents (if emitting type definitions are enabled)
*/
typedef?: string;
/**
* An editor that can be used to transform properties or arrays. Once the `afterFileTranspile` event has fired, these changes will be reverted,
* restoring the objects to their prior state. This is useful for changing code right before a file gets transpiled, but when you don't want
* the changes to persist in the in-memory file.
*/
editor: Editor;
}
export interface SemanticToken {
range: Range;
tokenType: SemanticTokenTypes;
/**
* An optional array of modifiers for this token
*/
tokenModifiers?: SemanticTokenModifiers[];
}
export interface TypedefProvider {
getTypedef(state: TranspileState): Array<SourceNode | string>;
}
export type TranspileResult = Array<(string | SourceNode)>;
export type FileResolver = (pathAbsolute: string) => string | undefined | Thenable<string | undefined> | void;
export interface ExpressionInfo {
expressions: Expression[];
varExpressions: Expression[];
uniqueVarNames: string[];
}
export type DiagnosticCode = number | string;
export interface FileLink<T> {
item: T;
file: BrsFile;
}