forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguageService.ts
More file actions
408 lines (337 loc) · 16.2 KB
/
Copy pathlanguageService.ts
File metadata and controls
408 lines (337 loc) · 16.2 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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///<reference path='references.ts' />
///<reference path='diagnosticServices.ts' />
module TypeScript.Services {
//
// Public interface of the host of a language service instance.
//
export interface ILanguageServiceHost extends TypeScript.ILogger, TypeScript.IReferenceResolverHost {
getCompilationSettings(): TypeScript.CompilationSettings;
getScriptFileNames(): string[];
getScriptVersion(fileName: string): string;
getScriptIsOpen(fileName: string): boolean;
getScriptByteOrderMark(fileName: string): TypeScript.ByteOrderMark;
getScriptSnapshot(fileName: string): TypeScript.IScriptSnapshot;
getDiagnosticsObject(): TypeScript.Services.ILanguageServicesDiagnostics;
getLocalizedDiagnosticMessages(): any;
getCancellationToken(): ICancellationToken;
}
//
// Public services of a language service instance associated
// with a language service host instance
//
export interface ILanguageService {
// Note: refresh is a no-op now. It is only around for back compat purposes.
refresh(): void;
cleanupSemanticCache(): void;
getSyntacticDiagnostics(fileName: string): TypeScript.Diagnostic[];
getSemanticDiagnostics(fileName: string): TypeScript.Diagnostic[];
getCompilerOptionsDiagnostics(): TypeScript.Diagnostic[];
getCompletionsAtPosition(fileName: string, position: number, isMemberCompletion: boolean): CompletionInfo;
getCompletionEntryDetails(fileName: string, position: number, entryName: string): CompletionEntryDetails;
getTypeAtPosition(fileName: string, position: number): TypeInfo;
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan;
getBreakpointStatementAtPosition(fileName: string, position: number): TextSpan;
getSignatureHelpItems(fileName: string, position: number): SignatureHelpItems;
getSignatureHelpCurrentArgumentState(fileName: string, position: number, applicableSpanStart: number): SignatureHelpState;
getRenameInfo(fileName: string, position: number): RenameInfo;
getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[];
getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[];
getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[];
getImplementorsAtPosition(fileName: string, position: number): ReferenceEntry[];
getNavigateToItems(searchValue: string): NavigateToItem[];
getNavigationBarItems(fileName: string): NavigationBarItem[];
getOutliningSpans(fileName: string): OutliningSpan[];
getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[];
getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[];
getIndentationAtPosition(fileName: string, position: number, options: EditorOptions): number;
getFormattingEditsForRange(fileName: string, start: number, end: number, options: FormatCodeOptions): TextChange[];
getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions): TextChange[];
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[];
getEmitOutput(fileName: string): TypeScript.EmitOutput;
getSyntaxTree(fileName: string): TypeScript.SyntaxTree;
dispose(): void;
}
export function logInternalError(logger: TypeScript.ILogger, err: Error) {
logger.log("*INTERNAL ERROR* - Exception in typescript services: " + err.message);
}
export class ReferenceEntry {
public fileName: string = ""
public textSpan: TextSpan;
public isWriteAccess: boolean = false;
constructor(fileName: string, textSpan: TextSpan, isWriteAccess: boolean) {
this.fileName = fileName;
this.textSpan = textSpan;
this.isWriteAccess = isWriteAccess;
}
}
export class OutliningSpan {
/**
* @param textSpan The span of the document to actually collapse.
* @param hintSpan The span of the document to display when the user hovers over the
* collapsed span.
* @param bannerText The text to display in the editor for the collapsed region.
* @param autoCollapse Whether or not this region should be automatically collapsed when
* the 'Collapse to Definitions' command is invoked.
*/
constructor(public textSpan: TextSpan,
public hintSpan: TextSpan,
public bannerText: string,
public autoCollapse: boolean) {
}
}
export class NavigationBarItem {
constructor(public text: string,
public kind: string,
public kindModifiers: string,
public spans: TextSpan[],
public childItems: NavigationBarItem[] = null,
public indent = 0,
public bolded = false,
public grayed = false) {
}
}
export class SignatureHelpParameter {
constructor(public name: string,
public documentation: string,
public display: string,
public isOptional: boolean) {
}
}
/**
* Represents a single signature to show in signature help.
* The id is used for subsequent calls into the language service to ask questions about the
* signature help item in the context of any documents that have been updated. i.e. after
* an edit has happened, while signature help is still active, the host can ask important
* questions like 'what parameter is the user currently contained within?'.
*/
export class SignatureHelpItem {
constructor(public isVariadic: boolean,
public prefix: string,
public suffix: string,
public separator: string,
public parameters: SignatureHelpParameter[],
public documentation: string) {
}
}
/**
* Represents a set of signature help items, and the preferred item that should be selected.
*/
export class SignatureHelpItems {
constructor(public items: SignatureHelpItem[],
public applicableSpan: TextSpan,
public selectedItemIndex: number) {
}
}
export class SignatureHelpState {
constructor(public argumentIndex: number,
public argumentCount: number) {
}
}
export class TodoCommentDescriptor {
constructor(public text: string,
public priority: number) {
}
}
export class TodoComment {
constructor(public descriptor: TodoCommentDescriptor,
public message: string,
public position: number) {
}
}
export class NavigateToItem {
public name: string = "";
public kind: string = ""; // see ScriptElementKind
public kindModifiers: string = ""; // see ScriptElementKindModifier, comma separated
public matchKind: string = "";
public fileName: string = "";
public textSpan: TextSpan;
public containerName: string = "";
public containerKind: string = ""; // see ScriptElementKind
}
export class TextChange {
constructor(public span: TextSpan, public newText: string) {
}
static createInsert(pos: number, newText: string): TextChange {
return new TextChange(new TextSpan(pos, 0), newText);
}
static createDelete(minChar: number, limChar: number): TextChange {
return new TextChange(TextSpan.fromBounds(minChar, limChar), "");
}
static createReplace(minChar: number, limChar: number, newText: string): TextChange {
return new TextChange(TextSpan.fromBounds(minChar, limChar), newText);
}
}
export class EditorOptions {
public IndentSize: number = 4;
public TabSize: number = 4;
public NewLineCharacter: string = "\r\n";
public ConvertTabsToSpaces: boolean = true;
public static clone(objectToClone: EditorOptions): EditorOptions {
var editorOptions = new EditorOptions();
editorOptions.IndentSize = objectToClone.IndentSize;
editorOptions.TabSize = objectToClone.TabSize;
editorOptions.NewLineCharacter = objectToClone.NewLineCharacter;
editorOptions.ConvertTabsToSpaces = objectToClone.ConvertTabsToSpaces;
return editorOptions;
}
}
export class FormatCodeOptions extends EditorOptions {
public InsertSpaceAfterCommaDelimiter: boolean = true;
public InsertSpaceAfterSemicolonInForStatements: boolean = true;
public InsertSpaceBeforeAndAfterBinaryOperators: boolean = true;
public InsertSpaceAfterKeywordsInControlFlowStatements: boolean = true;
public InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean = false;
public InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean = false;
public PlaceOpenBraceOnNewLineForFunctions: boolean = false;
public PlaceOpenBraceOnNewLineForControlBlocks: boolean = false;
public static clone(objectToClone: FormatCodeOptions ): FormatCodeOptions {
var formatCodeOptions = <FormatCodeOptions>EditorOptions.clone(objectToClone);
formatCodeOptions.InsertSpaceAfterCommaDelimiter = objectToClone.InsertSpaceAfterCommaDelimiter;
formatCodeOptions.InsertSpaceAfterSemicolonInForStatements = objectToClone.InsertSpaceAfterSemicolonInForStatements;
formatCodeOptions.InsertSpaceBeforeAndAfterBinaryOperators = objectToClone.InsertSpaceBeforeAndAfterBinaryOperators;
formatCodeOptions.InsertSpaceAfterKeywordsInControlFlowStatements = objectToClone.InsertSpaceAfterKeywordsInControlFlowStatements;
formatCodeOptions.InsertSpaceAfterFunctionKeywordForAnonymousFunctions = objectToClone.InsertSpaceAfterFunctionKeywordForAnonymousFunctions;
formatCodeOptions.InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis = objectToClone.InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis;
formatCodeOptions.PlaceOpenBraceOnNewLineForFunctions = objectToClone.PlaceOpenBraceOnNewLineForFunctions;
formatCodeOptions.PlaceOpenBraceOnNewLineForControlBlocks = objectToClone.PlaceOpenBraceOnNewLineForControlBlocks;
return formatCodeOptions;
}
}
export class RenameInfo {
constructor(public canRename: boolean,
public localizedErrorMessage: string,
public displayName: string,
public fullDisplayName: string,
public kind: string,
public kindModifiers: string,
public triggerSpan: TextSpan) {
}
public static CreateError(localizedErrorMessage: string) {
return new RenameInfo(false, localizedErrorMessage, null, null, null, null, null);
}
public static Create(displayName: string,
fullDisplayName: string,
kind: string,
kindModifiers: string,
triggerSpan: TextSpan) {
return new RenameInfo(true, null, displayName, fullDisplayName, kind, kindModifiers, triggerSpan);
}
}
export class DefinitionInfo {
constructor(
public fileName: string,
public textSpan: TextSpan,
public kind: string,
public name: string,
public containerKind: string,
public containerName: string) {
}
}
export class TypeInfo {
constructor(
public memberName: TypeScript.MemberName,
public docComment: string,
public fullSymbolName: string,
public kind: string,
public textSpan: TextSpan) {
}
}
export class CompletionInfo {
public maybeInaccurate = false;
public isMemberCompletion = false;
public entries: CompletionEntry[] = [];
}
export interface CompletionEntry {
name: string;
kind: string; // see ScriptElementKind
kindModifiers: string; // see ScriptElementKindModifier, comma separated
}
export interface CompletionEntryDetails {
name: string;
kind: string; // see ScriptElementKind
kindModifiers: string; // see ScriptElementKindModifier, comma separated
type: string;
fullSymbolName: string;
docComment: string;
}
export class ScriptElementKind {
static unknown = "";
// predefined type (void) or keyword (class)
static keyword = "keyword";
// top level script node
static scriptElement = "script";
// module foo {}
static moduleElement = "module";
// class X {}
static classElement = "class";
// interface Y {}
static interfaceElement = "interface";
// enum E
static enumElement = "enum";
// Inside module and script only
// var v = ..
static variableElement = "var";
// Inside function
static localVariableElement = "local var";
// Inside module and script only
// function f() { }
static functionElement = "function";
// Inside function
static localFunctionElement = "local function";
// class X { [public|private]* foo() {} }
static memberFunctionElement = "method";
// class X { [public|private]* [get|set] foo:number; }
static memberGetAccessorElement = "getter";
static memberSetAccessorElement = "setter";
// class X { [public|private]* foo:number; }
// interface Y { foo:number; }
static memberVariableElement = "property";
// class X { constructor() { } }
static constructorImplementationElement = "constructor";
// interface Y { ():number; }
static callSignatureElement = "call";
// interface Y { []:number; }
static indexSignatureElement = "index";
// interface Y { new():Y; }
static constructSignatureElement = "construct";
// function foo(*Y*: string)
static parameterElement = "parameter";
static typeParameterElement = "type parameter";
static primitiveType = "primitive type";
}
export class ScriptElementKindModifier {
static none = "";
static publicMemberModifier = "public";
static privateMemberModifier = "private";
static exportedModifier = "export";
static ambientModifier = "declare";
static staticModifier = "static";
}
export enum MatchKind {
// Ordered from best match to worst. We'll always return the most optimistic result.
exact,
prefix,
substring,
regular
}
export class DiagnosticCategory {
static none = "";
static error = "error";
static warning = "warning";
static message = "message";
}
}