modes.ts 19.6 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

J
Johannes Rieken 已提交
7 8
import { MarkedString } from 'vs/base/common/htmlContent';
import { IDisposable } from 'vs/base/common/lifecycle';
A
Alex Dima 已提交
9
import URI from 'vs/base/common/uri';
J
Johannes Rieken 已提交
10
import { IFilter } from 'vs/base/common/filters';
A
Alex Dima 已提交
11
import * as editorCommon from 'vs/editor/common/editorCommon';
J
Johannes Rieken 已提交
12 13
import { ModeTransition } from 'vs/editor/common/core/modeTransition';
import { Token } from 'vs/editor/common/core/token';
14
import LanguageFeatureRegistry from 'vs/editor/common/modes/languageFeatureRegistry';
J
Johannes Rieken 已提交
15 16 17 18
import { CancellationToken } from 'vs/base/common/cancellation';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import Event, { Emitter } from 'vs/base/common/event';
E
Erich Gamma 已提交
19

20 21 22
/**
 * @internal
 */
E
Erich Gamma 已提交
23
export interface IModeDescriptor {
J
Johannes Rieken 已提交
24
	id: string;
E
Erich Gamma 已提交
25 26
}

A
Alex Dima 已提交
27 28 29
/**
 * A mode. Will soon be obsolete.
 */
E
Erich Gamma 已提交
30 31 32 33 34 35
export interface IMode {

	getId(): string;

}

36 37 38
/**
 * @internal
 */
E
Erich Gamma 已提交
39
export interface ILineTokens {
A
Alex Dima 已提交
40
	tokens: Token[];
E
Erich Gamma 已提交
41 42
	actualStopOffset: number;
	endState: IState;
43
	modeTransitions: ModeTransition[];
E
Erich Gamma 已提交
44 45
}

46 47 48
/**
 * @internal
 */
E
Erich Gamma 已提交
49 50
export interface ITokenizationSupport {

J
Johannes Rieken 已提交
51
	getInitialState(): IState;
E
Erich Gamma 已提交
52 53 54

	// add offsetDelta to each of the returned indices
	// stop tokenizing at absolute value stopAtOffset (i.e. stream.pos() + offsetDelta > stopAtOffset)
J
Johannes Rieken 已提交
55
	tokenize(line: string, state: IState, offsetDelta?: number, stopAtOffset?: number): ILineTokens;
E
Erich Gamma 已提交
56 57
}

A
Alex Dima 已提交
58 59 60
/**
 * A token. Only supports a single scope, but will soon support a scope array.
 */
A
Alex Dima 已提交
61 62
export interface IToken2 {
	startIndex: number;
J
Johannes Rieken 已提交
63
	scopes: string | string[];
A
Alex Dima 已提交
64
}
A
Alex Dima 已提交
65 66 67
/**
 * The result of a line tokenization.
 */
A
Alex Dima 已提交
68
export interface ILineTokens2 {
A
Alex Dima 已提交
69 70 71
	/**
	 * The list of tokens on the line.
	 */
A
Alex Dima 已提交
72
	tokens: IToken2[];
A
Alex Dima 已提交
73 74 75 76
	/**
	 * The tokenization end state.
	 * A pointer will be held to this and the object should not be modified by the tokenizer after the pointer is returned.
	 */
A
Alex Dima 已提交
77
	endState: IState;
A
Alex Dima 已提交
78
}
A
Alex Dima 已提交
79 80 81 82 83
/**
 * The state of the tokenizer between two lines.
 * It is useful to store flags such as in multiline comment, etc.
 * The model will clone the previous line's state and pass it in to tokenize the next line.
 */
A
Alex Dima 已提交
84 85 86
export interface IState {
	clone(): IState;
	equals(other: IState): boolean;
A
Alex Dima 已提交
87
}
A
Alex Dima 已提交
88 89 90
/**
 * A "manual" provider of tokens.
 */
91
export interface TokensProvider {
A
Alex Dima 已提交
92 93 94
	/**
	 * The initial state of a language. Will be the state passed in to tokenize the first line.
	 */
A
Alex Dima 已提交
95
	getInitialState(): IState;
A
Alex Dima 已提交
96 97 98
	/**
	 * Tokenize a line given the state at the beginning of the line.
	 */
A
Alex Dima 已提交
99
	tokenize(line: string, state: IState): ILineTokens2;
A
Alex Dima 已提交
100 101
}

E
Erich Gamma 已提交
102
/**
103 104
 * A hover represents additional information for a symbol or word. Hovers are
 * rendered in a tooltip-like widget.
E
Erich Gamma 已提交
105
 */
106 107 108 109
export interface Hover {
	/**
	 * The contents of this hover.
	 */
110
	contents: MarkedString[];
111 112 113 114 115 116

	/**
	 * The range to which this hover applies. When missing, the
	 * editor will use the range at the current position or the
	 * current position itself.
	 */
A
Alex Dima 已提交
117
	range: editorCommon.IRange;
E
Erich Gamma 已提交
118
}
119

A
Alex Dima 已提交
120 121 122 123
/**
 * The hover provider interface defines the contract between extensions and
 * the [hover](https://code.visualstudio.com/docs/editor/editingevolved#_hover)-feature.
 */
A
Alex Dima 已提交
124
export interface HoverProvider {
A
Alex Dima 已提交
125 126 127 128 129
	/**
	 * Provide a hover for the given position and document. Multiple hovers at the same
	 * position will be merged by the editor. A hover can have a range which defaults
	 * to the word range at the position when omitted.
	 */
J
Johannes Rieken 已提交
130
	provideHover(model: editorCommon.IReadOnlyModel, position: Position, token: CancellationToken): Hover | Thenable<Hover>;
E
Erich Gamma 已提交
131 132
}

133 134 135
/**
 * @internal
 */
J
Johannes Rieken 已提交
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
export type SuggestionType = 'method'
	| 'function'
	| 'constructor'
	| 'field'
	| 'variable'
	| 'class'
	| 'interface'
	| 'module'
	| 'property'
	| 'unit'
	| 'value'
	| 'enum'
	| 'keyword'
	| 'snippet'
	| 'text'
	| 'color'
	| 'file'
	| 'reference'
154 155
	| 'customcolor'
	| 'folder';
J
Johannes Rieken 已提交
156

157 158 159
/**
 * @internal
 */
160
export type SnippetType = 'internal' | 'textmate';
161

162 163 164
/**
 * @internal
 */
E
Erich Gamma 已提交
165 166
export interface ISuggestion {
	label: string;
167
	insertText: string;
J
Johannes Rieken 已提交
168
	type: SuggestionType;
169 170
	detail?: string;
	documentation?: string;
E
Erich Gamma 已提交
171 172 173
	filterText?: string;
	sortText?: string;
	noAutoAccept?: boolean;
174 175
	overwriteBefore?: number;
	overwriteAfter?: number;
176
	additionalTextEdits?: editorCommon.ISingleEditOperation[];
177
	command?: Command;
178
	snippetType?: SnippetType;
E
Erich Gamma 已提交
179 180
}

181 182 183
/**
 * @internal
 */
184
export interface ISuggestResult {
J
Johannes Rieken 已提交
185
	suggestions: ISuggestion[];
E
Erich Gamma 已提交
186 187 188
	incomplete?: boolean;
}

189 190 191
/**
 * @internal
 */
E
Erich Gamma 已提交
192 193
export interface ISuggestSupport {

194 195
	triggerCharacters: string[];

196 197
	filter?: IFilter;

J
Johannes Rieken 已提交
198
	provideCompletionItems(model: editorCommon.IReadOnlyModel, position: Position, token: CancellationToken): ISuggestResult | Thenable<ISuggestResult>;
E
Erich Gamma 已提交
199

J
Johannes Rieken 已提交
200
	resolveCompletionItem?(model: editorCommon.IReadOnlyModel, position: Position, item: ISuggestion, token: CancellationToken): ISuggestion | Thenable<ISuggestion>;
E
Erich Gamma 已提交
201 202 203 204 205
}

/**
 * Interface used to quick fix typing errors while accesing member fields.
 */
A
Alex Dima 已提交
206 207
export interface CodeAction {
	command: Command;
E
Erich Gamma 已提交
208 209
	score: number;
}
A
Alex Dima 已提交
210 211 212
/**
 * The code action interface defines the contract between extensions and
 * the [light bulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) feature.
213
 * @internal
A
Alex Dima 已提交
214
 */
215
export interface CodeActionProvider {
A
Alex Dima 已提交
216 217 218
	/**
	 * Provide commands for the given document and range.
	 */
J
Johannes Rieken 已提交
219
	provideCodeActions(model: editorCommon.IReadOnlyModel, range: Range, token: CancellationToken): CodeAction[] | Thenable<CodeAction[]>;
E
Erich Gamma 已提交
220 221
}

A
Alex Dima 已提交
222 223 224 225
/**
 * Represents a parameter of a callable-signature. A parameter can
 * have a label and a doc-comment.
 */
226
export interface ParameterInformation {
A
Alex Dima 已提交
227 228 229 230
	/**
	 * The label of this signature. Will be shown in
	 * the UI.
	 */
231
	label: string;
A
Alex Dima 已提交
232 233 234 235
	/**
	 * The human-readable doc-comment of this signature. Will be shown
	 * in the UI but can be omitted.
	 */
236
	documentation?: string;
E
Erich Gamma 已提交
237
}
A
Alex Dima 已提交
238 239 240 241 242
/**
 * Represents the signature of something callable. A signature
 * can have a label, like a function-name, a doc-comment, and
 * a set of parameters.
 */
243
export interface SignatureInformation {
A
Alex Dima 已提交
244 245 246 247
	/**
	 * The label of this signature. Will be shown in
	 * the UI.
	 */
248
	label: string;
A
Alex Dima 已提交
249 250 251 252
	/**
	 * The human-readable doc-comment of this signature. Will be shown
	 * in the UI but can be omitted.
	 */
253
	documentation?: string;
A
Alex Dima 已提交
254 255 256
	/**
	 * The parameters of this signature.
	 */
257
	parameters: ParameterInformation[];
E
Erich Gamma 已提交
258
}
A
Alex Dima 已提交
259 260 261 262 263
/**
 * Signature help represents the signature of something
 * callable. There can be multiple signatures but only one
 * active and only one active parameter.
 */
264
export interface SignatureHelp {
A
Alex Dima 已提交
265 266 267
	/**
	 * One or more signatures.
	 */
268
	signatures: SignatureInformation[];
A
Alex Dima 已提交
269 270 271
	/**
	 * The active signature.
	 */
272
	activeSignature: number;
A
Alex Dima 已提交
273 274 275
	/**
	 * The active parameter of the active signature.
	 */
276
	activeParameter: number;
E
Erich Gamma 已提交
277
}
A
Alex Dima 已提交
278 279 280 281
/**
 * The signature help provider interface defines the contract between extensions and
 * the [parameter hints](https://code.visualstudio.com/docs/editor/editingevolved#_parameter-hints)-feature.
 */
A
Alex Dima 已提交
282
export interface SignatureHelpProvider {
283

A
Alex Dima 已提交
284
	signatureHelpTriggerCharacters: string[];
285

A
Alex Dima 已提交
286 287 288
	/**
	 * Provide help for the signature at the given position and document.
	 */
A
Alex Dima 已提交
289
	provideSignatureHelp(model: editorCommon.IReadOnlyModel, position: Position, token: CancellationToken): SignatureHelp | Thenable<SignatureHelp>;
E
Erich Gamma 已提交
290 291
}

A
Alex Dima 已提交
292 293 294
/**
 * A document highlight kind.
 */
295
export enum DocumentHighlightKind {
A
Alex Dima 已提交
296 297 298
	/**
	 * A textual occurrence.
	 */
299
	Text,
A
Alex Dima 已提交
300 301 302
	/**
	 * Read-access of a symbol, like reading a variable.
	 */
303
	Read,
A
Alex Dima 已提交
304 305 306
	/**
	 * Write-access of a symbol, like writing to a variable.
	 */
307 308
	Write
}
A
Alex Dima 已提交
309 310 311 312 313
/**
 * A document highlight is a range inside a text document which deserves
 * special attention. Usually a document highlight is visualized by changing
 * the background color of its range.
 */
314
export interface DocumentHighlight {
A
Alex Dima 已提交
315 316 317
	/**
	 * The range this highlight applies to.
	 */
318
	range: editorCommon.IRange;
A
Alex Dima 已提交
319 320 321
	/**
	 * The highlight kind, default is [text](#DocumentHighlightKind.Text).
	 */
322
	kind: DocumentHighlightKind;
E
Erich Gamma 已提交
323
}
A
Alex Dima 已提交
324 325 326 327
/**
 * The document highlight provider interface defines the contract between extensions and
 * the word-highlight-feature.
 */
328
export interface DocumentHighlightProvider {
A
Alex Dima 已提交
329 330 331 332
	/**
	 * Provide a set of document highlights, like all occurrences of a variable or
	 * all exit-points of a function.
	 */
A
Alex Dima 已提交
333
	provideDocumentHighlights(model: editorCommon.IReadOnlyModel, position: Position, token: CancellationToken): DocumentHighlight[] | Thenable<DocumentHighlight[]>;
E
Erich Gamma 已提交
334 335
}

A
Alex Dima 已提交
336 337 338 339
/**
 * Value-object that contains additional information when
 * requesting references.
 */
340
export interface ReferenceContext {
A
Alex Dima 已提交
341 342 343
	/**
	 * Include the declaration of the current symbol.
	 */
344 345
	includeDeclaration: boolean;
}
A
Alex Dima 已提交
346 347 348 349
/**
 * The reference provider interface defines the contract between extensions and
 * the [find references](https://code.visualstudio.com/docs/editor/editingevolved#_peek)-feature.
 */
350
export interface ReferenceProvider {
A
Alex Dima 已提交
351 352 353
	/**
	 * Provide a set of project-wide references for the given position and document.
	 */
J
Johannes Rieken 已提交
354
	provideReferences(model: editorCommon.IReadOnlyModel, position: Position, context: ReferenceContext, token: CancellationToken): Location[] | Thenable<Location[]>;
E
Erich Gamma 已提交
355 356
}

A
Alex Dima 已提交
357 358 359 360
/**
 * Represents a location inside a resource, such as a line
 * inside a text file.
 */
A
Alex Dima 已提交
361
export interface Location {
A
Alex Dima 已提交
362 363 364
	/**
	 * The resource identifier of this location.
	 */
365
	uri: URI;
A
Alex Dima 已提交
366 367 368
	/**
	 * The document range of this locations.
	 */
369
	range: editorCommon.IRange;
E
Erich Gamma 已提交
370
}
A
Alex Dima 已提交
371 372 373 374 375
/**
 * The definition of a symbol represented as one or many [locations](#Location).
 * For most programming languages there is only one location at which a symbol is
 * defined.
 */
376
export type Definition = Location | Location[];
A
Alex Dima 已提交
377 378 379 380 381
/**
 * The definition provider interface defines the contract between extensions and
 * the [go to definition](https://code.visualstudio.com/docs/editor/editingevolved#_go-to-definition)
 * and peek definition features.
 */
382
export interface DefinitionProvider {
A
Alex Dima 已提交
383 384 385
	/**
	 * Provide the definition of the symbol at the given position and document.
	 */
J
Johannes Rieken 已提交
386
	provideDefinition(model: editorCommon.IReadOnlyModel, position: Position, token: CancellationToken): Definition | Thenable<Definition>;
387 388
}

389

A
Alex Dima 已提交
390 391 392
/**
 * A symbol kind.
 */
393
export enum SymbolKind {
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
	File = 0,
	Module = 1,
	Namespace = 2,
	Package = 3,
	Class = 4,
	Method = 5,
	Property = 6,
	Field = 7,
	Constructor = 8,
	Enum = 9,
	Interface = 10,
	Function = 11,
	Variable = 12,
	Constant = 13,
	String = 14,
	Number = 15,
	Boolean = 16,
	Array = 17,
	Object = 18,
	Key = 19,
	Null = 20
415
}
416 417 418
/**
 * @internal
 */
419 420
export namespace SymbolKind {

421 422 423
	/**
	 * @internal
	 */
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
	export function from(kind: number | SymbolKind): string {
		switch (kind) {
			case SymbolKind.Method:
				return 'method';
			case SymbolKind.Function:
				return 'function';
			case SymbolKind.Constructor:
				return 'constructor';
			case SymbolKind.Variable:
				return 'variable';
			case SymbolKind.Class:
				return 'class';
			case SymbolKind.Interface:
				return 'interface';
			case SymbolKind.Namespace:
				return 'namespace';
			case SymbolKind.Package:
				return 'package';
			case SymbolKind.Module:
				return 'module';
			case SymbolKind.Property:
				return 'property';
			case SymbolKind.Enum:
				return 'enum';
			case SymbolKind.String:
				return 'string';
			case SymbolKind.File:
				return 'file';
			case SymbolKind.Array:
				return 'array';
			case SymbolKind.Number:
				return 'number';
			case SymbolKind.Boolean:
				return 'boolean';
			case SymbolKind.Object:
				return 'object';
			case SymbolKind.Key:
				return 'key';
			case SymbolKind.Null:
				return 'null';
		}
		return 'property';
	}
E
Erich Gamma 已提交
467

468 469 470
	/**
	 * @internal
	 */
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
	export function to(type: string): SymbolKind {
		switch (type) {
			case 'method':
				return SymbolKind.Method;
			case 'function':
				return SymbolKind.Function;
			case 'constructor':
				return SymbolKind.Constructor;
			case 'variable':
				return SymbolKind.Variable;
			case 'class':
				return SymbolKind.Class;
			case 'interface':
				return SymbolKind.Interface;
			case 'namespace':
				return SymbolKind.Namespace;
			case 'package':
				return SymbolKind.Package;
			case 'module':
				return SymbolKind.Module;
			case 'property':
				return SymbolKind.Property;
			case 'enum':
				return SymbolKind.Enum;
			case 'string':
				return SymbolKind.String;
			case 'file':
				return SymbolKind.File;
			case 'array':
				return SymbolKind.Array;
			case 'number':
				return SymbolKind.Number;
			case 'boolean':
				return SymbolKind.Boolean;
			case 'object':
				return SymbolKind.Object;
			case 'key':
				return SymbolKind.Key;
			case 'null':
				return SymbolKind.Null;
		}
		return SymbolKind.Property;
	}
E
Erich Gamma 已提交
514
}
A
Alex Dima 已提交
515 516 517 518
/**
 * Represents information about programming constructs like variables, classes,
 * interfaces etc.
 */
519
export interface SymbolInformation {
A
Alex Dima 已提交
520 521 522
	/**
	 * The name of this symbol.
	 */
523
	name: string;
A
Alex Dima 已提交
524 525 526
	/**
	 * The name of the symbol containing this symbol.
	 */
527
	containerName?: string;
A
Alex Dima 已提交
528 529 530
	/**
	 * The kind of this symbol.
	 */
531
	kind: SymbolKind;
A
Alex Dima 已提交
532 533 534
	/**
	 * The location of this symbol.
	 */
535 536
	location: Location;
}
A
Alex Dima 已提交
537 538 539 540
/**
 * The document symbol provider interface defines the contract between extensions and
 * the [go to symbol](https://code.visualstudio.com/docs/editor/editingevolved#_goto-symbol)-feature.
 */
541
export interface DocumentSymbolProvider {
A
Alex Dima 已提交
542 543 544
	/**
	 * Provide symbol information for the given document.
	 */
J
Johannes Rieken 已提交
545
	provideDocumentSymbols(model: editorCommon.IReadOnlyModel, token: CancellationToken): SymbolInformation[] | Thenable<SymbolInformation[]>;
E
Erich Gamma 已提交
546 547 548 549 550
}

/**
 * Interface used to format a model
 */
A
Alex Dima 已提交
551 552 553 554
export interface FormattingOptions {
	/**
	 * Size of a tab in spaces.
	 */
J
Johannes Rieken 已提交
555
	tabSize: number;
A
Alex Dima 已提交
556 557 558
	/**
	 * Prefer spaces over tabs.
	 */
J
Johannes Rieken 已提交
559
	insertSpaces: boolean;
E
Erich Gamma 已提交
560
}
A
Alex Dima 已提交
561 562 563 564
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
565
export interface DocumentFormattingEditProvider {
A
Alex Dima 已提交
566 567 568 569
	/**
	 * Provide formatting edits for a whole document.
	 */
	provideDocumentFormattingEdits(model: editorCommon.IReadOnlyModel, options: FormattingOptions, token: CancellationToken): editorCommon.ISingleEditOperation[] | Thenable<editorCommon.ISingleEditOperation[]>;
570
}
A
Alex Dima 已提交
571 572 573 574
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
575
export interface DocumentRangeFormattingEditProvider {
A
Alex Dima 已提交
576 577 578 579 580 581 582 583
	/**
	 * Provide formatting edits for a range in a document.
	 *
	 * The given range is a hint and providers can decide to format a smaller
	 * or larger range. Often this is done by adjusting the start and end
	 * of the range to full syntax nodes.
	 */
	provideDocumentRangeFormattingEdits(model: editorCommon.IReadOnlyModel, range: Range, options: FormattingOptions, token: CancellationToken): editorCommon.ISingleEditOperation[] | Thenable<editorCommon.ISingleEditOperation[]>;
584
}
A
Alex Dima 已提交
585 586 587 588
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
589 590
export interface OnTypeFormattingEditProvider {
	autoFormatTriggerCharacters: string[];
A
Alex Dima 已提交
591 592 593 594 595 596 597 598
	/**
	 * Provide formatting edits after a character has been typed.
	 *
	 * The given position and character should hint to the provider
	 * what range the position to expand to, like find the matching `{`
	 * when `}` has been entered.
	 */
	provideOnTypeFormattingEdits(model: editorCommon.IReadOnlyModel, position: Position, ch: string, options: FormattingOptions, token: CancellationToken): editorCommon.ISingleEditOperation[] | Thenable<editorCommon.ISingleEditOperation[]>;
E
Erich Gamma 已提交
599 600
}

601 602 603
/**
 * @internal
 */
E
Erich Gamma 已提交
604 605
export interface IInplaceReplaceSupportResult {
	value: string;
J
Johannes Rieken 已提交
606
	range: editorCommon.IRange;
E
Erich Gamma 已提交
607 608
}

A
Alex Dima 已提交
609 610 611
/**
 * A link inside the editor.
 */
612
export interface ILink {
A
Alex Dima 已提交
613
	range: editorCommon.IRange;
E
Erich Gamma 已提交
614 615
	url: string;
}
A
Alex Dima 已提交
616 617 618
/**
 * A provider of links.
 */
A
Alex Dima 已提交
619
export interface LinkProvider {
620
	provideLinks(model: editorCommon.IReadOnlyModel, token: CancellationToken): ILink[] | Thenable<ILink[]>;
621
	resolveLink?: (link: ILink, token: CancellationToken) => ILink | Thenable<ILink>;
E
Erich Gamma 已提交
622 623
}

624

E
Erich Gamma 已提交
625 626
export interface IResourceEdit {
	resource: URI;
627
	range: editorCommon.IRange;
E
Erich Gamma 已提交
628 629
	newText: string;
}
630
export interface WorkspaceEdit {
E
Erich Gamma 已提交
631 632 633
	edits: IResourceEdit[];
	rejectReason?: string;
}
634
export interface RenameProvider {
J
Johannes Rieken 已提交
635
	provideRenameEdits(model: editorCommon.IReadOnlyModel, position: Position, newName: string, token: CancellationToken): WorkspaceEdit | Thenable<WorkspaceEdit>;
E
Erich Gamma 已提交
636 637
}

638

A
Alex Dima 已提交
639
export interface Command {
E
Erich Gamma 已提交
640 641 642 643 644
	id: string;
	title: string;
	arguments?: any[];
}
export interface ICodeLensSymbol {
A
Alex Dima 已提交
645
	range: editorCommon.IRange;
E
Erich Gamma 已提交
646
	id?: string;
A
Alex Dima 已提交
647
	command?: Command;
E
Erich Gamma 已提交
648
}
649
export interface CodeLensProvider {
J
Johannes Rieken 已提交
650 651
	provideCodeLenses(model: editorCommon.IReadOnlyModel, token: CancellationToken): ICodeLensSymbol[] | Thenable<ICodeLensSymbol[]>;
	resolveCodeLens?(model: editorCommon.IReadOnlyModel, codeLens: ICodeLensSymbol, token: CancellationToken): ICodeLensSymbol | Thenable<ICodeLensSymbol>;
E
Erich Gamma 已提交
652 653
}

654 655
// --- feature registries ------

656 657 658
/**
 * @internal
 */
659
export const ReferenceProviderRegistry = new LanguageFeatureRegistry<ReferenceProvider>();
660

661 662 663
/**
 * @internal
 */
664
export const RenameProviderRegistry = new LanguageFeatureRegistry<RenameProvider>();
665

666 667 668
/**
 * @internal
 */
669
export const SuggestRegistry = new LanguageFeatureRegistry<ISuggestSupport>();
670

671 672 673
/**
 * @internal
 */
674
export const SignatureHelpProviderRegistry = new LanguageFeatureRegistry<SignatureHelpProvider>();
675

676 677 678
/**
 * @internal
 */
679
export const HoverProviderRegistry = new LanguageFeatureRegistry<HoverProvider>();
680

681 682 683
/**
 * @internal
 */
684
export const DocumentSymbolProviderRegistry = new LanguageFeatureRegistry<DocumentSymbolProvider>();
685

686 687 688
/**
 * @internal
 */
689
export const DocumentHighlightProviderRegistry = new LanguageFeatureRegistry<DocumentHighlightProvider>();
690

691 692 693
/**
 * @internal
 */
694
export const DefinitionProviderRegistry = new LanguageFeatureRegistry<DefinitionProvider>();
695

696 697 698
/**
 * @internal
 */
699
export const CodeLensProviderRegistry = new LanguageFeatureRegistry<CodeLensProvider>();
700

701 702 703
/**
 * @internal
 */
704
export const CodeActionProviderRegistry = new LanguageFeatureRegistry<CodeActionProvider>();
705

706 707 708
/**
 * @internal
 */
709 710
export const DocumentFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentFormattingEditProvider>();

711 712 713
/**
 * @internal
 */
714
export const DocumentRangeFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentRangeFormattingEditProvider>();
715

716 717 718
/**
 * @internal
 */
719
export const OnTypeFormattingEditProviderRegistry = new LanguageFeatureRegistry<OnTypeFormattingEditProvider>();
720

721 722 723
/**
 * @internal
 */
A
Alex Dima 已提交
724
export const LinkProviderRegistry = new LanguageFeatureRegistry<LinkProvider>();
725 726 727 728 729 730 731 732 733 734 735 736 737

/**
 * @internal
 */
export interface ITokenizationSupportChangedEvent {
	languageId: string;
}

/**
 * @internal
 */
export class TokenizationRegistryImpl {

J
Johannes Rieken 已提交
738
	private _map: { [languageId: string]: ITokenizationSupport };
739 740 741 742 743 744 745 746 747 748 749 750

	private _onDidChange: Emitter<ITokenizationSupportChangedEvent> = new Emitter<ITokenizationSupportChangedEvent>();
	public onDidChange: Event<ITokenizationSupportChangedEvent> = this._onDidChange.event;

	constructor() {
		this._map = Object.create(null);
	}

	/**
	 * Fire a change event for a language.
	 * This is useful for languages that embed other languages.
	 */
J
Johannes Rieken 已提交
751
	public fire(languageId: string): void {
752 753 754
		this._onDidChange.fire({ languageId: languageId });
	}

J
Johannes Rieken 已提交
755
	public register(languageId: string, support: ITokenizationSupport): IDisposable {
756 757 758 759 760 761 762 763 764 765 766 767 768
		this._map[languageId] = support;
		this.fire(languageId);
		return {
			dispose: () => {
				if (this._map[languageId] !== support) {
					return;
				}
				delete this._map[languageId];
				this.fire(languageId);
			}
		};
	}

J
Johannes Rieken 已提交
769
	public get(languageId: string): ITokenizationSupport {
770 771 772 773 774 775 776 777
		return (this._map[languageId] || null);
	}
}

/**
 * @internal
 */
export const TokenizationRegistry = new TokenizationRegistryImpl();