modes.ts 20.9 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
	endState: IState;
42
	modeTransitions: ModeTransition[];
E
Erich Gamma 已提交
43 44
}

A
Alex Dima 已提交
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
/**
 * Helpers to manage the "collapsed" metadata of an entire StackElement stack.
 * The following assumptions have been made:
 *  - languageId < 256 => needs 8 bits
 *  - unique color count < 512 => needs 9 bits
 *
 * The binary format is:
 * --------------------------------------------
 *   3322 2222 2222 1111 1111 1100 0000 0000
 *   1098 7654 3210 9876 5432 1098 7654 3210
 * --------------------------------------------
 *   xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
 *   bbbb bbbb bfff ffff ffFF FTTT LLLL LLLL
 * --------------------------------------------
 *   L = LanguageId (8 bits)
 *   T = StandardTokenType (3 bits)
 *   F = FontStyle (3 bits)
 *   f = foreground color (9 bits)
 *   b = background color (9 bits)
 *
 * @internal
 */
export const enum MetadataConsts {
	LANGUAGEID_MASK = 0b00000000000000000000000011111111,
	TOKEN_TYPE_MASK = 0b00000000000000000000011100000000,
	FONT_STYLE_MASK = 0b00000000000000000011100000000000,
	FOREGROUND_MASK = 0b00000000011111111100000000000000,
	BACKGROUND_MASK = 0b11111111100000000000000000000000,

	LANGUAGEID_OFFSET = 0,
	TOKEN_TYPE_OFFSET = 8,
	FONT_STYLE_OFFSET = 11,
	FOREGROUND_OFFSET = 14,
	BACKGROUND_OFFSET = 23
}

/**
 * @internal
 */
export interface ILineTokens3 {
	/**
	 * The tokens in binary format. Each token occupies two array indices. For token i:
	 *  - at offset 2*i => startIndex
	 *  - at offset 2*i + 1 => metadata
	 *
	 */
	readonly tokens: Uint32Array;
	readonly endState: IState;
}

95 96 97
/**
 * @internal
 */
E
Erich Gamma 已提交
98 99
export interface ITokenizationSupport {

J
Johannes Rieken 已提交
100
	getInitialState(): IState;
E
Erich Gamma 已提交
101 102

	// add offsetDelta to each of the returned indices
A
Alex Dima 已提交
103 104 105
	tokenize(line: string, state: IState, offsetDelta: number): ILineTokens;

	// tokenize3(line: string, state: IState, offsetDelta: number): ILineTokens3;
E
Erich Gamma 已提交
106 107
}

A
Alex Dima 已提交
108 109 110
/**
 * A token. Only supports a single scope, but will soon support a scope array.
 */
A
Alex Dima 已提交
111 112
export interface IToken2 {
	startIndex: number;
J
Johannes Rieken 已提交
113
	scopes: string | string[];
A
Alex Dima 已提交
114
}
A
Alex Dima 已提交
115 116 117
/**
 * The result of a line tokenization.
 */
A
Alex Dima 已提交
118
export interface ILineTokens2 {
A
Alex Dima 已提交
119 120 121
	/**
	 * The list of tokens on the line.
	 */
A
Alex Dima 已提交
122
	tokens: IToken2[];
A
Alex Dima 已提交
123 124 125 126
	/**
	 * 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 已提交
127
	endState: IState;
A
Alex Dima 已提交
128
}
A
Alex Dima 已提交
129 130 131 132 133
/**
 * 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 已提交
134 135 136
export interface IState {
	clone(): IState;
	equals(other: IState): boolean;
A
Alex Dima 已提交
137
}
A
Alex Dima 已提交
138 139 140
/**
 * A "manual" provider of tokens.
 */
141
export interface TokensProvider {
A
Alex Dima 已提交
142 143 144
	/**
	 * The initial state of a language. Will be the state passed in to tokenize the first line.
	 */
A
Alex Dima 已提交
145
	getInitialState(): IState;
A
Alex Dima 已提交
146 147 148
	/**
	 * Tokenize a line given the state at the beginning of the line.
	 */
A
Alex Dima 已提交
149
	tokenize(line: string, state: IState): ILineTokens2;
A
Alex Dima 已提交
150 151
}

E
Erich Gamma 已提交
152
/**
153 154
 * A hover represents additional information for a symbol or word. Hovers are
 * rendered in a tooltip-like widget.
E
Erich Gamma 已提交
155
 */
156 157 158 159
export interface Hover {
	/**
	 * The contents of this hover.
	 */
160
	contents: MarkedString[];
161 162 163 164 165 166

	/**
	 * 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 已提交
167
	range: editorCommon.IRange;
E
Erich Gamma 已提交
168
}
169

A
Alex Dima 已提交
170 171 172 173
/**
 * The hover provider interface defines the contract between extensions and
 * the [hover](https://code.visualstudio.com/docs/editor/editingevolved#_hover)-feature.
 */
A
Alex Dima 已提交
174
export interface HoverProvider {
A
Alex Dima 已提交
175 176 177 178 179
	/**
	 * 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 已提交
180
	provideHover(model: editorCommon.IReadOnlyModel, position: Position, token: CancellationToken): Hover | Thenable<Hover>;
E
Erich Gamma 已提交
181 182
}

183 184 185
/**
 * @internal
 */
J
Johannes Rieken 已提交
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
export type SuggestionType = 'method'
	| 'function'
	| 'constructor'
	| 'field'
	| 'variable'
	| 'class'
	| 'interface'
	| 'module'
	| 'property'
	| 'unit'
	| 'value'
	| 'enum'
	| 'keyword'
	| 'snippet'
	| 'text'
	| 'color'
	| 'file'
	| 'reference'
204 205
	| 'customcolor'
	| 'folder';
J
Johannes Rieken 已提交
206

207 208 209
/**
 * @internal
 */
210
export type SnippetType = 'internal' | 'textmate';
211

212 213 214
/**
 * @internal
 */
E
Erich Gamma 已提交
215 216
export interface ISuggestion {
	label: string;
217
	insertText: string;
J
Johannes Rieken 已提交
218
	type: SuggestionType;
219 220
	detail?: string;
	documentation?: string;
E
Erich Gamma 已提交
221 222 223
	filterText?: string;
	sortText?: string;
	noAutoAccept?: boolean;
224 225
	overwriteBefore?: number;
	overwriteAfter?: number;
226
	additionalTextEdits?: editorCommon.ISingleEditOperation[];
227
	command?: Command;
228
	snippetType?: SnippetType;
E
Erich Gamma 已提交
229 230
}

231 232 233
/**
 * @internal
 */
234
export interface ISuggestResult {
J
Johannes Rieken 已提交
235
	suggestions: ISuggestion[];
E
Erich Gamma 已提交
236 237 238
	incomplete?: boolean;
}

239 240 241
/**
 * @internal
 */
E
Erich Gamma 已提交
242 243
export interface ISuggestSupport {

244 245
	triggerCharacters: string[];

246 247
	filter?: IFilter;

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

J
Johannes Rieken 已提交
250
	resolveCompletionItem?(model: editorCommon.IReadOnlyModel, position: Position, item: ISuggestion, token: CancellationToken): ISuggestion | Thenable<ISuggestion>;
E
Erich Gamma 已提交
251 252 253 254 255
}

/**
 * Interface used to quick fix typing errors while accesing member fields.
 */
A
Alex Dima 已提交
256 257
export interface CodeAction {
	command: Command;
E
Erich Gamma 已提交
258 259
	score: number;
}
A
Alex Dima 已提交
260 261 262
/**
 * The code action interface defines the contract between extensions and
 * the [light bulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) feature.
263
 * @internal
A
Alex Dima 已提交
264
 */
265
export interface CodeActionProvider {
A
Alex Dima 已提交
266 267 268
	/**
	 * Provide commands for the given document and range.
	 */
J
Johannes Rieken 已提交
269
	provideCodeActions(model: editorCommon.IReadOnlyModel, range: Range, token: CancellationToken): CodeAction[] | Thenable<CodeAction[]>;
E
Erich Gamma 已提交
270 271
}

A
Alex Dima 已提交
272 273 274 275
/**
 * Represents a parameter of a callable-signature. A parameter can
 * have a label and a doc-comment.
 */
276
export interface ParameterInformation {
A
Alex Dima 已提交
277 278 279 280
	/**
	 * The label of this signature. Will be shown in
	 * the UI.
	 */
281
	label: string;
A
Alex Dima 已提交
282 283 284 285
	/**
	 * The human-readable doc-comment of this signature. Will be shown
	 * in the UI but can be omitted.
	 */
286
	documentation?: string;
E
Erich Gamma 已提交
287
}
A
Alex Dima 已提交
288 289 290 291 292
/**
 * Represents the signature of something callable. A signature
 * can have a label, like a function-name, a doc-comment, and
 * a set of parameters.
 */
293
export interface SignatureInformation {
A
Alex Dima 已提交
294 295 296 297
	/**
	 * The label of this signature. Will be shown in
	 * the UI.
	 */
298
	label: string;
A
Alex Dima 已提交
299 300 301 302
	/**
	 * The human-readable doc-comment of this signature. Will be shown
	 * in the UI but can be omitted.
	 */
303
	documentation?: string;
A
Alex Dima 已提交
304 305 306
	/**
	 * The parameters of this signature.
	 */
307
	parameters: ParameterInformation[];
E
Erich Gamma 已提交
308
}
A
Alex Dima 已提交
309 310 311 312 313
/**
 * Signature help represents the signature of something
 * callable. There can be multiple signatures but only one
 * active and only one active parameter.
 */
314
export interface SignatureHelp {
A
Alex Dima 已提交
315 316 317
	/**
	 * One or more signatures.
	 */
318
	signatures: SignatureInformation[];
A
Alex Dima 已提交
319 320 321
	/**
	 * The active signature.
	 */
322
	activeSignature: number;
A
Alex Dima 已提交
323 324 325
	/**
	 * The active parameter of the active signature.
	 */
326
	activeParameter: number;
E
Erich Gamma 已提交
327
}
A
Alex Dima 已提交
328 329 330 331
/**
 * 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 已提交
332
export interface SignatureHelpProvider {
333

A
Alex Dima 已提交
334
	signatureHelpTriggerCharacters: string[];
335

A
Alex Dima 已提交
336 337 338
	/**
	 * Provide help for the signature at the given position and document.
	 */
A
Alex Dima 已提交
339
	provideSignatureHelp(model: editorCommon.IReadOnlyModel, position: Position, token: CancellationToken): SignatureHelp | Thenable<SignatureHelp>;
E
Erich Gamma 已提交
340 341
}

A
Alex Dima 已提交
342 343 344
/**
 * A document highlight kind.
 */
345
export enum DocumentHighlightKind {
A
Alex Dima 已提交
346 347 348
	/**
	 * A textual occurrence.
	 */
349
	Text,
A
Alex Dima 已提交
350 351 352
	/**
	 * Read-access of a symbol, like reading a variable.
	 */
353
	Read,
A
Alex Dima 已提交
354 355 356
	/**
	 * Write-access of a symbol, like writing to a variable.
	 */
357 358
	Write
}
A
Alex Dima 已提交
359 360 361 362 363
/**
 * 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.
 */
364
export interface DocumentHighlight {
A
Alex Dima 已提交
365 366 367
	/**
	 * The range this highlight applies to.
	 */
368
	range: editorCommon.IRange;
A
Alex Dima 已提交
369 370 371
	/**
	 * The highlight kind, default is [text](#DocumentHighlightKind.Text).
	 */
372
	kind: DocumentHighlightKind;
E
Erich Gamma 已提交
373
}
A
Alex Dima 已提交
374 375 376 377
/**
 * The document highlight provider interface defines the contract between extensions and
 * the word-highlight-feature.
 */
378
export interface DocumentHighlightProvider {
A
Alex Dima 已提交
379 380 381 382
	/**
	 * Provide a set of document highlights, like all occurrences of a variable or
	 * all exit-points of a function.
	 */
A
Alex Dima 已提交
383
	provideDocumentHighlights(model: editorCommon.IReadOnlyModel, position: Position, token: CancellationToken): DocumentHighlight[] | Thenable<DocumentHighlight[]>;
E
Erich Gamma 已提交
384 385
}

A
Alex Dima 已提交
386 387 388 389
/**
 * Value-object that contains additional information when
 * requesting references.
 */
390
export interface ReferenceContext {
A
Alex Dima 已提交
391 392 393
	/**
	 * Include the declaration of the current symbol.
	 */
394 395
	includeDeclaration: boolean;
}
A
Alex Dima 已提交
396 397 398 399
/**
 * The reference provider interface defines the contract between extensions and
 * the [find references](https://code.visualstudio.com/docs/editor/editingevolved#_peek)-feature.
 */
400
export interface ReferenceProvider {
A
Alex Dima 已提交
401 402 403
	/**
	 * Provide a set of project-wide references for the given position and document.
	 */
J
Johannes Rieken 已提交
404
	provideReferences(model: editorCommon.IReadOnlyModel, position: Position, context: ReferenceContext, token: CancellationToken): Location[] | Thenable<Location[]>;
E
Erich Gamma 已提交
405 406
}

A
Alex Dima 已提交
407 408 409 410
/**
 * Represents a location inside a resource, such as a line
 * inside a text file.
 */
A
Alex Dima 已提交
411
export interface Location {
A
Alex Dima 已提交
412 413 414
	/**
	 * The resource identifier of this location.
	 */
415
	uri: URI;
A
Alex Dima 已提交
416 417 418
	/**
	 * The document range of this locations.
	 */
419
	range: editorCommon.IRange;
E
Erich Gamma 已提交
420
}
A
Alex Dima 已提交
421 422 423 424 425
/**
 * 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.
 */
426
export type Definition = Location | Location[];
A
Alex Dima 已提交
427 428 429 430 431
/**
 * 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.
 */
432
export interface DefinitionProvider {
A
Alex Dima 已提交
433 434 435
	/**
	 * Provide the definition of the symbol at the given position and document.
	 */
J
Johannes Rieken 已提交
436
	provideDefinition(model: editorCommon.IReadOnlyModel, position: Position, token: CancellationToken): Definition | Thenable<Definition>;
437 438
}

439

A
Alex Dima 已提交
440 441 442
/**
 * A symbol kind.
 */
443
export enum SymbolKind {
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
	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
465
}
466 467 468
/**
 * @internal
 */
469 470
export namespace SymbolKind {

471 472 473
	/**
	 * @internal
	 */
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 514 515 516
	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 已提交
517

518 519 520
	/**
	 * @internal
	 */
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
	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 已提交
564
}
A
Alex Dima 已提交
565 566 567 568
/**
 * Represents information about programming constructs like variables, classes,
 * interfaces etc.
 */
569
export interface SymbolInformation {
A
Alex Dima 已提交
570 571 572
	/**
	 * The name of this symbol.
	 */
573
	name: string;
A
Alex Dima 已提交
574 575 576
	/**
	 * The name of the symbol containing this symbol.
	 */
577
	containerName?: string;
A
Alex Dima 已提交
578 579 580
	/**
	 * The kind of this symbol.
	 */
581
	kind: SymbolKind;
A
Alex Dima 已提交
582 583 584
	/**
	 * The location of this symbol.
	 */
585 586
	location: Location;
}
A
Alex Dima 已提交
587 588 589 590
/**
 * 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.
 */
591
export interface DocumentSymbolProvider {
A
Alex Dima 已提交
592 593 594
	/**
	 * Provide symbol information for the given document.
	 */
J
Johannes Rieken 已提交
595
	provideDocumentSymbols(model: editorCommon.IReadOnlyModel, token: CancellationToken): SymbolInformation[] | Thenable<SymbolInformation[]>;
E
Erich Gamma 已提交
596 597 598 599 600
}

/**
 * Interface used to format a model
 */
A
Alex Dima 已提交
601 602 603 604
export interface FormattingOptions {
	/**
	 * Size of a tab in spaces.
	 */
J
Johannes Rieken 已提交
605
	tabSize: number;
A
Alex Dima 已提交
606 607 608
	/**
	 * Prefer spaces over tabs.
	 */
J
Johannes Rieken 已提交
609
	insertSpaces: boolean;
E
Erich Gamma 已提交
610
}
A
Alex Dima 已提交
611 612 613 614
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
615
export interface DocumentFormattingEditProvider {
A
Alex Dima 已提交
616 617 618 619
	/**
	 * Provide formatting edits for a whole document.
	 */
	provideDocumentFormattingEdits(model: editorCommon.IReadOnlyModel, options: FormattingOptions, token: CancellationToken): editorCommon.ISingleEditOperation[] | Thenable<editorCommon.ISingleEditOperation[]>;
620
}
A
Alex Dima 已提交
621 622 623 624
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
625
export interface DocumentRangeFormattingEditProvider {
A
Alex Dima 已提交
626 627 628 629 630 631 632 633
	/**
	 * 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[]>;
634
}
A
Alex Dima 已提交
635 636 637 638
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
639 640
export interface OnTypeFormattingEditProvider {
	autoFormatTriggerCharacters: string[];
A
Alex Dima 已提交
641 642 643 644 645 646 647 648
	/**
	 * 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 已提交
649 650
}

651 652 653
/**
 * @internal
 */
E
Erich Gamma 已提交
654 655
export interface IInplaceReplaceSupportResult {
	value: string;
J
Johannes Rieken 已提交
656
	range: editorCommon.IRange;
E
Erich Gamma 已提交
657 658
}

A
Alex Dima 已提交
659 660 661
/**
 * A link inside the editor.
 */
662
export interface ILink {
A
Alex Dima 已提交
663
	range: editorCommon.IRange;
E
Erich Gamma 已提交
664 665
	url: string;
}
A
Alex Dima 已提交
666 667 668
/**
 * A provider of links.
 */
A
Alex Dima 已提交
669
export interface LinkProvider {
670
	provideLinks(model: editorCommon.IReadOnlyModel, token: CancellationToken): ILink[] | Thenable<ILink[]>;
671
	resolveLink?: (link: ILink, token: CancellationToken) => ILink | Thenable<ILink>;
E
Erich Gamma 已提交
672 673
}

674

E
Erich Gamma 已提交
675 676
export interface IResourceEdit {
	resource: URI;
677
	range: editorCommon.IRange;
E
Erich Gamma 已提交
678 679
	newText: string;
}
680
export interface WorkspaceEdit {
E
Erich Gamma 已提交
681 682 683
	edits: IResourceEdit[];
	rejectReason?: string;
}
684
export interface RenameProvider {
J
Johannes Rieken 已提交
685
	provideRenameEdits(model: editorCommon.IReadOnlyModel, position: Position, newName: string, token: CancellationToken): WorkspaceEdit | Thenable<WorkspaceEdit>;
E
Erich Gamma 已提交
686 687
}

688

A
Alex Dima 已提交
689
export interface Command {
E
Erich Gamma 已提交
690 691 692 693 694
	id: string;
	title: string;
	arguments?: any[];
}
export interface ICodeLensSymbol {
A
Alex Dima 已提交
695
	range: editorCommon.IRange;
E
Erich Gamma 已提交
696
	id?: string;
A
Alex Dima 已提交
697
	command?: Command;
E
Erich Gamma 已提交
698
}
699
export interface CodeLensProvider {
J
Johannes Rieken 已提交
700 701
	provideCodeLenses(model: editorCommon.IReadOnlyModel, token: CancellationToken): ICodeLensSymbol[] | Thenable<ICodeLensSymbol[]>;
	resolveCodeLens?(model: editorCommon.IReadOnlyModel, codeLens: ICodeLensSymbol, token: CancellationToken): ICodeLensSymbol | Thenable<ICodeLensSymbol>;
E
Erich Gamma 已提交
702 703
}

704 705
// --- feature registries ------

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

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

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

721 722 723
/**
 * @internal
 */
724
export const SignatureHelpProviderRegistry = new LanguageFeatureRegistry<SignatureHelpProvider>();
725

726 727 728
/**
 * @internal
 */
729
export const HoverProviderRegistry = new LanguageFeatureRegistry<HoverProvider>();
730

731 732 733
/**
 * @internal
 */
734
export const DocumentSymbolProviderRegistry = new LanguageFeatureRegistry<DocumentSymbolProvider>();
735

736 737 738
/**
 * @internal
 */
739
export const DocumentHighlightProviderRegistry = new LanguageFeatureRegistry<DocumentHighlightProvider>();
740

741 742 743
/**
 * @internal
 */
744
export const DefinitionProviderRegistry = new LanguageFeatureRegistry<DefinitionProvider>();
745

746 747 748
/**
 * @internal
 */
749
export const CodeLensProviderRegistry = new LanguageFeatureRegistry<CodeLensProvider>();
750

751 752 753
/**
 * @internal
 */
754
export const CodeActionProviderRegistry = new LanguageFeatureRegistry<CodeActionProvider>();
755

756 757 758
/**
 * @internal
 */
759 760
export const DocumentFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentFormattingEditProvider>();

761 762 763
/**
 * @internal
 */
764
export const DocumentRangeFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentRangeFormattingEditProvider>();
765

766 767 768
/**
 * @internal
 */
769
export const OnTypeFormattingEditProviderRegistry = new LanguageFeatureRegistry<OnTypeFormattingEditProvider>();
770

771 772 773
/**
 * @internal
 */
A
Alex Dima 已提交
774
export const LinkProviderRegistry = new LanguageFeatureRegistry<LinkProvider>();
775 776 777 778 779 780 781 782 783 784 785 786 787

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

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

J
Johannes Rieken 已提交
788
	private _map: { [languageId: string]: ITokenizationSupport };
789 790 791 792 793 794 795 796 797 798 799 800

	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 已提交
801
	public fire(languageId: string): void {
802 803 804
		this._onDidChange.fire({ languageId: languageId });
	}

J
Johannes Rieken 已提交
805
	public register(languageId: string, support: ITokenizationSupport): IDisposable {
806 807 808 809 810 811 812 813 814 815 816 817 818
		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 已提交
819
	public get(languageId: string): ITokenizationSupport {
820 821 822 823 824 825 826 827
		return (this._map[languageId] || null);
	}
}

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