modes.ts 24.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';

7
import { IMarkdownString } from 'vs/base/common/htmlContent';
J
Johannes Rieken 已提交
8
import { IDisposable } from 'vs/base/common/lifecycle';
A
Alex Dima 已提交
9
import URI from 'vs/base/common/uri';
A
Tweaks  
Alex Dima 已提交
10
import { TokenizationResult, TokenizationResult2 } from 'vs/editor/common/core/token';
11
import LanguageFeatureRegistry from 'vs/editor/common/modes/languageFeatureRegistry';
J
Johannes Rieken 已提交
12 13
import { CancellationToken } from 'vs/base/common/cancellation';
import { Position } from 'vs/editor/common/core/position';
A
Alex Dima 已提交
14
import { Range, IRange } from 'vs/editor/common/core/range';
15 16
import Event from 'vs/base/common/event';
import { TokenizationRegistryImpl } from 'vs/editor/common/modes/tokenizationRegistry';
17
import { Color } from 'vs/base/common/color';
18
import { IMarkerData } from 'vs/platform/markers/common/markers';
A
Alex Dima 已提交
19
import * as model from 'vs/editor/common/model';
E
Erich Gamma 已提交
20

21
/**
22
 * Open ended enum at runtime
23 24
 * @internal
 */
A
Alex Dima 已提交
25 26 27 28 29 30 31 32 33
export const enum LanguageId {
	Null = 0,
	PlainText = 1
}

/**
 * @internal
 */
export class LanguageIdentifier {
A
Alex Dima 已提交
34 35 36 37

	/**
	 * A string identifier. Unique across languages. e.g. 'javascript'.
	 */
38
	public readonly language: string;
A
Alex Dima 已提交
39 40 41 42 43

	/**
	 * A numeric identifier. Unique across languages. e.g. 5
	 * Will vary at runtime based on registration order, etc.
	 */
44
	public readonly id: LanguageId;
A
Alex Dima 已提交
45

A
Alex Dima 已提交
46 47 48
	constructor(language: string, id: LanguageId) {
		this.language = language;
		this.id = id;
A
Alex Dima 已提交
49
	}
E
Erich Gamma 已提交
50 51
}

A
Alex Dima 已提交
52 53
/**
 * A mode. Will soon be obsolete.
A
Alex Dima 已提交
54
 * @internal
A
Alex Dima 已提交
55
 */
E
Erich Gamma 已提交
56 57 58 59
export interface IMode {

	getId(): string;

A
Alex Dima 已提交
60 61
	getLanguageIdentifier(): LanguageIdentifier;

E
Erich Gamma 已提交
62 63
}

A
Alex Dima 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76
/**
 * A font style. Values are 2^x such that a bit mask can be used.
 * @internal
 */
export const enum FontStyle {
	NotSet = -1,
	None = 0,
	Italic = 1,
	Bold = 2,
	Underline = 4
}

/**
77
 * Open ended enum at runtime
A
Alex Dima 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
 * @internal
 */
export const enum ColorId {
	None = 0,
	DefaultForeground = 1,
	DefaultBackground = 2
}

/**
 * A standard token type. Values are 2^x such that a bit mask can be used.
 * @internal
 */
export const enum StandardTokenType {
	Other = 0,
	Comment = 1,
	String = 2,
	RegEx = 4
}

A
Alex Dima 已提交
97 98 99 100 101 102 103
/**
 * 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:
A
Alex Dima 已提交
104 105 106 107 108 109 110 111 112 113 114 115
 * - -------------------------------------------
 *     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)
A
Alex Dima 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
 *
 * @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
}

A
Alex Dima 已提交
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
/**
 * @internal
 */
export class TokenMetadata {

	public static getLanguageId(metadata: number): LanguageId {
		return (metadata & MetadataConsts.LANGUAGEID_MASK) >>> MetadataConsts.LANGUAGEID_OFFSET;
	}

	public static getTokenType(metadata: number): StandardTokenType {
		return (metadata & MetadataConsts.TOKEN_TYPE_MASK) >>> MetadataConsts.TOKEN_TYPE_OFFSET;
	}

	public static getFontStyle(metadata: number): FontStyle {
		return (metadata & MetadataConsts.FONT_STYLE_MASK) >>> MetadataConsts.FONT_STYLE_OFFSET;
	}

	public static getForeground(metadata: number): ColorId {
		return (metadata & MetadataConsts.FOREGROUND_MASK) >>> MetadataConsts.FOREGROUND_OFFSET;
	}

	public static getBackground(metadata: number): ColorId {
		return (metadata & MetadataConsts.BACKGROUND_MASK) >>> MetadataConsts.BACKGROUND_OFFSET;
	}

	public static getClassNameFromMetadata(metadata: number): string {
		let foreground = this.getForeground(metadata);
		let className = 'mtk' + foreground;

		let fontStyle = this.getFontStyle(metadata);
		if (fontStyle & FontStyle.Italic) {
			className += ' mtki';
		}
		if (fontStyle & FontStyle.Bold) {
			className += ' mtkb';
		}
		if (fontStyle & FontStyle.Underline) {
			className += ' mtku';
		}

		return className;
	}

	public static getInlineStyleFromMetadata(metadata: number, colorMap: string[]): string {
		const foreground = this.getForeground(metadata);
		const fontStyle = this.getFontStyle(metadata);

		let result = `color: ${colorMap[foreground]};`;
		if (fontStyle & FontStyle.Italic) {
			result += 'font-style: italic;';
		}
		if (fontStyle & FontStyle.Bold) {
			result += 'font-weight: bold;';
		}
		if (fontStyle & FontStyle.Underline) {
			result += 'text-decoration: underline;';
		}
		return result;
	}
}

194 195 196
/**
 * @internal
 */
E
Erich Gamma 已提交
197 198
export interface ITokenizationSupport {

J
Johannes Rieken 已提交
199
	getInitialState(): IState;
E
Erich Gamma 已提交
200 201

	// add offsetDelta to each of the returned indices
A
Tweaks  
Alex Dima 已提交
202
	tokenize(line: string, state: IState, offsetDelta: number): TokenizationResult;
A
Alex Dima 已提交
203

A
Tweaks  
Alex Dima 已提交
204
	tokenize2(line: string, state: IState, offsetDelta: number): TokenizationResult2;
E
Erich Gamma 已提交
205 206
}

A
Alex Dima 已提交
207 208 209 210 211
/**
 * 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 已提交
212 213 214
export interface IState {
	clone(): IState;
	equals(other: IState): boolean;
A
Alex Dima 已提交
215 216
}

E
Erich Gamma 已提交
217
/**
218 219
 * A hover represents additional information for a symbol or word. Hovers are
 * rendered in a tooltip-like widget.
E
Erich Gamma 已提交
220
 */
221
export interface Hover {
222 223 224
	/**
	 * The contents of this hover.
	 */
225
	contents: IMarkdownString[];
226 227 228 229 230 231

	/**
	 * 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 已提交
232
	range: IRange;
E
Erich Gamma 已提交
233
}
234

A
Alex Dima 已提交
235 236
/**
 * The hover provider interface defines the contract between extensions and
G
Greg Van Liew 已提交
237
 * the [hover](https://code.visualstudio.com/docs/editor/intellisense)-feature.
A
Alex Dima 已提交
238
 */
A
Alex Dima 已提交
239
export interface HoverProvider {
A
Alex Dima 已提交
240 241 242 243 244
	/**
	 * 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.
	 */
A
Alex Dima 已提交
245
	provideHover(model: model.ITextModel, position: Position, token: CancellationToken): Hover | Thenable<Hover>;
E
Erich Gamma 已提交
246 247
}

248 249 250
/**
 * @internal
 */
J
Johannes Rieken 已提交
251 252 253 254 255 256
export type SuggestionType = 'method'
	| 'function'
	| 'constructor'
	| 'field'
	| 'variable'
	| 'class'
257
	| 'struct'
J
Johannes Rieken 已提交
258 259 260
	| 'interface'
	| 'module'
	| 'property'
261 262
	| 'event'
	| 'operator'
J
Johannes Rieken 已提交
263 264
	| 'unit'
	| 'value'
265
	| 'constant'
J
Johannes Rieken 已提交
266
	| 'enum'
267
	| 'enum-member'
J
Johannes Rieken 已提交
268 269 270 271 272 273
	| 'keyword'
	| 'snippet'
	| 'text'
	| 'color'
	| 'file'
	| 'reference'
274
	| 'customcolor'
275 276
	| 'folder'
	| 'type-parameter';
J
Johannes Rieken 已提交
277

278 279 280
/**
 * @internal
 */
281
export type SnippetType = 'internal' | 'textmate';
282

283 284 285
/**
 * @internal
 */
E
Erich Gamma 已提交
286 287
export interface ISuggestion {
	label: string;
288
	insertText: string;
J
Johannes Rieken 已提交
289
	type: SuggestionType;
290
	detail?: string;
291
	documentation?: string | IMarkdownString;
E
Erich Gamma 已提交
292 293 294
	filterText?: string;
	sortText?: string;
	noAutoAccept?: boolean;
295
	commitCharacters?: string[];
296 297
	overwriteBefore?: number;
	overwriteAfter?: number;
298
	additionalTextEdits?: model.ISingleEditOperation[];
299
	command?: Command;
300
	snippetType?: SnippetType;
E
Erich Gamma 已提交
301 302
}

303 304 305
/**
 * @internal
 */
306
export interface ISuggestResult {
J
Johannes Rieken 已提交
307
	suggestions: ISuggestion[];
E
Erich Gamma 已提交
308
	incomplete?: boolean;
309
	dispose?(): void;
E
Erich Gamma 已提交
310 311
}

M
Matt Bierner 已提交
312 313 314 315 316
/**
 * How a suggest provider was triggered.
 */
export enum SuggestTriggerKind {
	Invoke = 0,
317 318
	TriggerCharacter = 1,
	TriggerForIncompleteCompletions = 2
M
Matt Bierner 已提交
319 320
}

321 322 323 324
/**
 * @internal
 */
export interface SuggestContext {
M
Matt Bierner 已提交
325
	triggerKind: SuggestTriggerKind;
326 327 328
	triggerCharacter?: string;
}

329 330 331
/**
 * @internal
 */
E
Erich Gamma 已提交
332 333
export interface ISuggestSupport {

334
	triggerCharacters?: string[];
335

A
Alex Dima 已提交
336
	provideCompletionItems(model: model.ITextModel, position: Position, context: SuggestContext, token: CancellationToken): ISuggestResult | Thenable<ISuggestResult>;
E
Erich Gamma 已提交
337

A
Alex Dima 已提交
338
	resolveCompletionItem?(model: model.ITextModel, position: Position, item: ISuggestion, token: CancellationToken): ISuggestion | Thenable<ISuggestion>;
E
Erich Gamma 已提交
339 340
}

341 342 343
export interface CodeAction {
	title: string;
	command?: Command;
344
	edit?: WorkspaceEdit;
345 346 347
	diagnostics?: IMarkerData[];
}

A
Alex Dima 已提交
348 349 350
/**
 * The code action interface defines the contract between extensions and
 * the [light bulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) feature.
351
 * @internal
A
Alex Dima 已提交
352
 */
353
export interface CodeActionProvider {
A
Alex Dima 已提交
354 355 356
	/**
	 * Provide commands for the given document and range.
	 */
A
Alex Dima 已提交
357
	provideCodeActions(model: model.ITextModel, range: Range, token: CancellationToken): CodeAction[] | Thenable<CodeAction[]>;
E
Erich Gamma 已提交
358 359
}

A
Alex Dima 已提交
360 361 362 363
/**
 * Represents a parameter of a callable-signature. A parameter can
 * have a label and a doc-comment.
 */
364
export interface ParameterInformation {
A
Alex Dima 已提交
365 366 367 368
	/**
	 * The label of this signature. Will be shown in
	 * the UI.
	 */
369
	label: string;
A
Alex Dima 已提交
370 371 372 373
	/**
	 * The human-readable doc-comment of this signature. Will be shown
	 * in the UI but can be omitted.
	 */
374
	documentation?: string | IMarkdownString;
E
Erich Gamma 已提交
375
}
A
Alex Dima 已提交
376 377 378 379 380
/**
 * Represents the signature of something callable. A signature
 * can have a label, like a function-name, a doc-comment, and
 * a set of parameters.
 */
381
export interface SignatureInformation {
A
Alex Dima 已提交
382 383 384 385
	/**
	 * The label of this signature. Will be shown in
	 * the UI.
	 */
386
	label: string;
A
Alex Dima 已提交
387 388 389 390
	/**
	 * The human-readable doc-comment of this signature. Will be shown
	 * in the UI but can be omitted.
	 */
391
	documentation?: string | IMarkdownString;
A
Alex Dima 已提交
392 393 394
	/**
	 * The parameters of this signature.
	 */
395
	parameters: ParameterInformation[];
E
Erich Gamma 已提交
396
}
A
Alex Dima 已提交
397 398 399 400 401
/**
 * Signature help represents the signature of something
 * callable. There can be multiple signatures but only one
 * active and only one active parameter.
 */
402
export interface SignatureHelp {
A
Alex Dima 已提交
403 404 405
	/**
	 * One or more signatures.
	 */
406
	signatures: SignatureInformation[];
A
Alex Dima 已提交
407 408 409
	/**
	 * The active signature.
	 */
410
	activeSignature: number;
A
Alex Dima 已提交
411 412 413
	/**
	 * The active parameter of the active signature.
	 */
414
	activeParameter: number;
E
Erich Gamma 已提交
415
}
A
Alex Dima 已提交
416 417
/**
 * The signature help provider interface defines the contract between extensions and
G
Greg Van Liew 已提交
418
 * the [parameter hints](https://code.visualstudio.com/docs/editor/intellisense)-feature.
A
Alex Dima 已提交
419
 */
A
Alex Dima 已提交
420
export interface SignatureHelpProvider {
421

A
Alex Dima 已提交
422
	signatureHelpTriggerCharacters: string[];
423

A
Alex Dima 已提交
424 425 426
	/**
	 * Provide help for the signature at the given position and document.
	 */
A
Alex Dima 已提交
427
	provideSignatureHelp(model: model.ITextModel, position: Position, token: CancellationToken): SignatureHelp | Thenable<SignatureHelp>;
E
Erich Gamma 已提交
428 429
}

A
Alex Dima 已提交
430 431 432
/**
 * A document highlight kind.
 */
433
export enum DocumentHighlightKind {
A
Alex Dima 已提交
434 435 436
	/**
	 * A textual occurrence.
	 */
437
	Text,
A
Alex Dima 已提交
438 439 440
	/**
	 * Read-access of a symbol, like reading a variable.
	 */
441
	Read,
A
Alex Dima 已提交
442 443 444
	/**
	 * Write-access of a symbol, like writing to a variable.
	 */
445 446
	Write
}
A
Alex Dima 已提交
447 448 449 450 451
/**
 * 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.
 */
452
export interface DocumentHighlight {
A
Alex Dima 已提交
453 454 455
	/**
	 * The range this highlight applies to.
	 */
A
Alex Dima 已提交
456
	range: IRange;
A
Alex Dima 已提交
457 458 459
	/**
	 * The highlight kind, default is [text](#DocumentHighlightKind.Text).
	 */
460
	kind: DocumentHighlightKind;
E
Erich Gamma 已提交
461
}
A
Alex Dima 已提交
462 463 464 465
/**
 * The document highlight provider interface defines the contract between extensions and
 * the word-highlight-feature.
 */
466
export interface DocumentHighlightProvider {
A
Alex Dima 已提交
467 468 469 470
	/**
	 * Provide a set of document highlights, like all occurrences of a variable or
	 * all exit-points of a function.
	 */
A
Alex Dima 已提交
471
	provideDocumentHighlights(model: model.ITextModel, position: Position, token: CancellationToken): DocumentHighlight[] | Thenable<DocumentHighlight[]>;
E
Erich Gamma 已提交
472 473
}

A
Alex Dima 已提交
474 475 476 477
/**
 * Value-object that contains additional information when
 * requesting references.
 */
478
export interface ReferenceContext {
A
Alex Dima 已提交
479 480 481
	/**
	 * Include the declaration of the current symbol.
	 */
482 483
	includeDeclaration: boolean;
}
A
Alex Dima 已提交
484 485 486 487
/**
 * The reference provider interface defines the contract between extensions and
 * the [find references](https://code.visualstudio.com/docs/editor/editingevolved#_peek)-feature.
 */
488
export interface ReferenceProvider {
A
Alex Dima 已提交
489 490 491
	/**
	 * Provide a set of project-wide references for the given position and document.
	 */
A
Alex Dima 已提交
492
	provideReferences(model: model.ITextModel, position: Position, context: ReferenceContext, token: CancellationToken): Location[] | Thenable<Location[]>;
E
Erich Gamma 已提交
493 494
}

A
Alex Dima 已提交
495 496 497 498
/**
 * Represents a location inside a resource, such as a line
 * inside a text file.
 */
A
Alex Dima 已提交
499
export interface Location {
A
Alex Dima 已提交
500 501 502
	/**
	 * The resource identifier of this location.
	 */
503
	uri: URI;
A
Alex Dima 已提交
504 505 506
	/**
	 * The document range of this locations.
	 */
A
Alex Dima 已提交
507
	range: IRange;
E
Erich Gamma 已提交
508
}
A
Alex Dima 已提交
509 510 511 512 513
/**
 * 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.
 */
514
export type Definition = Location | Location[];
515

A
Alex Dima 已提交
516 517 518 519 520
/**
 * 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.
 */
521
export interface DefinitionProvider {
A
Alex Dima 已提交
522 523 524
	/**
	 * Provide the definition of the symbol at the given position and document.
	 */
A
Alex Dima 已提交
525
	provideDefinition(model: model.ITextModel, position: Position, token: CancellationToken): Definition | Thenable<Definition>;
526 527
}

528
/**
529
 * The implementation provider interface defines the contract between extensions and
530
 * the go to implementation feature.
531
 */
M
Matt Bierner 已提交
532
export interface ImplementationProvider {
533 534 535
	/**
	 * Provide the implementation of the symbol at the given position and document.
	 */
A
Alex Dima 已提交
536
	provideImplementation(model: model.ITextModel, position: Position, token: CancellationToken): Definition | Thenable<Definition>;
537
}
538

539 540 541 542 543 544 545 546
/**
 * The type definition provider interface defines the contract between extensions and
 * the go to type definition feature.
 */
export interface TypeDefinitionProvider {
	/**
	 * Provide the type definition of the symbol at the given position and document.
	 */
A
Alex Dima 已提交
547
	provideTypeDefinition(model: model.ITextModel, position: Position, token: CancellationToken): Definition | Thenable<Definition>;
548 549
}

A
Alex Dima 已提交
550 551 552
/**
 * A symbol kind.
 */
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
export enum SymbolKind {
	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,
	EnumMember = 21,
576 577
	Struct = 22,
	Event = 23,
578 579
	Operator = 24,
	TypeParameter = 25
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
}


/**
 * @internal
 */
export const symbolKindToCssClass = (function () {

	const _fromMapping: { [n: number]: string } = Object.create(null);
	_fromMapping[SymbolKind.File] = 'file';
	_fromMapping[SymbolKind.Module] = 'module';
	_fromMapping[SymbolKind.Namespace] = 'namespace';
	_fromMapping[SymbolKind.Package] = 'package';
	_fromMapping[SymbolKind.Class] = 'class';
	_fromMapping[SymbolKind.Method] = 'method';
	_fromMapping[SymbolKind.Property] = 'property';
	_fromMapping[SymbolKind.Field] = 'field';
	_fromMapping[SymbolKind.Constructor] = 'constructor';
	_fromMapping[SymbolKind.Enum] = 'enum';
	_fromMapping[SymbolKind.Interface] = 'interface';
	_fromMapping[SymbolKind.Function] = 'function';
	_fromMapping[SymbolKind.Variable] = 'variable';
	_fromMapping[SymbolKind.Constant] = 'constant';
	_fromMapping[SymbolKind.String] = 'string';
	_fromMapping[SymbolKind.Number] = 'number';
	_fromMapping[SymbolKind.Boolean] = 'boolean';
	_fromMapping[SymbolKind.Array] = 'array';
	_fromMapping[SymbolKind.Object] = 'object';
	_fromMapping[SymbolKind.Key] = 'key';
	_fromMapping[SymbolKind.Null] = 'null';
	_fromMapping[SymbolKind.EnumMember] = 'enum-member';
	_fromMapping[SymbolKind.Struct] = 'struct';
612 613
	_fromMapping[SymbolKind.Event] = 'event';
	_fromMapping[SymbolKind.Operator] = 'operator';
614
	_fromMapping[SymbolKind.TypeParameter] = 'type-parameter';
615 616 617 618 619 620

	return function toCssClassName(kind: SymbolKind): string {
		return _fromMapping[kind] || 'property';
	};
})();

A
Alex Dima 已提交
621 622 623 624 625 626
/**
 * @internal
 */
export interface IOutline {
	entries: SymbolInformation[];
}
A
Alex Dima 已提交
627 628 629 630
/**
 * Represents information about programming constructs like variables, classes,
 * interfaces etc.
 */
631
export interface SymbolInformation {
A
Alex Dima 已提交
632 633 634
	/**
	 * The name of this symbol.
	 */
635
	name: string;
A
Alex Dima 已提交
636 637 638
	/**
	 * The name of the symbol containing this symbol.
	 */
639
	containerName?: string;
A
Alex Dima 已提交
640 641 642
	/**
	 * The kind of this symbol.
	 */
643
	kind: SymbolKind;
A
Alex Dima 已提交
644 645 646
	/**
	 * The location of this symbol.
	 */
647 648
	location: Location;
}
A
Alex Dima 已提交
649 650 651 652
/**
 * 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.
 */
653
export interface DocumentSymbolProvider {
A
Alex Dima 已提交
654 655 656
	/**
	 * Provide symbol information for the given document.
	 */
A
Alex Dima 已提交
657
	provideDocumentSymbols(model: model.ITextModel, token: CancellationToken): SymbolInformation[] | Thenable<SymbolInformation[]>;
E
Erich Gamma 已提交
658 659
}

660
export interface TextEdit {
A
Alex Dima 已提交
661
	range: IRange;
662
	text: string;
663
	eol?: model.EndOfLineSequence;
664 665
}

E
Erich Gamma 已提交
666 667 668
/**
 * Interface used to format a model
 */
A
Alex Dima 已提交
669 670 671 672
export interface FormattingOptions {
	/**
	 * Size of a tab in spaces.
	 */
J
Johannes Rieken 已提交
673
	tabSize: number;
A
Alex Dima 已提交
674 675 676
	/**
	 * Prefer spaces over tabs.
	 */
J
Johannes Rieken 已提交
677
	insertSpaces: boolean;
E
Erich Gamma 已提交
678
}
A
Alex Dima 已提交
679 680 681 682
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
683
export interface DocumentFormattingEditProvider {
A
Alex Dima 已提交
684 685 686
	/**
	 * Provide formatting edits for a whole document.
	 */
A
Alex Dima 已提交
687
	provideDocumentFormattingEdits(model: model.ITextModel, options: FormattingOptions, token: CancellationToken): TextEdit[] | Thenable<TextEdit[]>;
688
}
A
Alex Dima 已提交
689 690 691 692
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
693
export interface DocumentRangeFormattingEditProvider {
A
Alex Dima 已提交
694 695 696 697 698 699 700
	/**
	 * 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.
	 */
A
Alex Dima 已提交
701
	provideDocumentRangeFormattingEdits(model: model.ITextModel, range: Range, options: FormattingOptions, token: CancellationToken): TextEdit[] | Thenable<TextEdit[]>;
702
}
A
Alex Dima 已提交
703 704 705 706
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
707 708
export interface OnTypeFormattingEditProvider {
	autoFormatTriggerCharacters: string[];
A
Alex Dima 已提交
709 710 711 712 713 714 715
	/**
	 * 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.
	 */
A
Alex Dima 已提交
716
	provideOnTypeFormattingEdits(model: model.ITextModel, position: Position, ch: string, options: FormattingOptions, token: CancellationToken): TextEdit[] | Thenable<TextEdit[]>;
E
Erich Gamma 已提交
717 718
}

719 720 721
/**
 * @internal
 */
E
Erich Gamma 已提交
722 723
export interface IInplaceReplaceSupportResult {
	value: string;
A
Alex Dima 已提交
724
	range: IRange;
E
Erich Gamma 已提交
725 726
}

A
Alex Dima 已提交
727 728 729
/**
 * A link inside the editor.
 */
730
export interface ILink {
A
Alex Dima 已提交
731
	range: IRange;
E
Erich Gamma 已提交
732 733
	url: string;
}
A
Alex Dima 已提交
734 735 736
/**
 * A provider of links.
 */
A
Alex Dima 已提交
737
export interface LinkProvider {
A
Alex Dima 已提交
738
	provideLinks(model: model.ITextModel, token: CancellationToken): ILink[] | Thenable<ILink[]>;
739
	resolveLink?: (link: ILink, token: CancellationToken) => ILink | Thenable<ILink>;
E
Erich Gamma 已提交
740 741
}

J
Joao Moreno 已提交
742
/**
J
Joao Moreno 已提交
743
 * A color in RGBA format.
J
Joao Moreno 已提交
744
 */
J
Joao Moreno 已提交
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
export interface IColor {

	/**
	 * The red component in the range [0-1].
	 */
	readonly red: number;

	/**
	 * The green component in the range [0-1].
	 */
	readonly green: number;

	/**
	 * The blue component in the range [0-1].
	 */
	readonly blue: number;

	/**
	 * The alpha component in the range [0-1].
	 */
	readonly alpha: number;
}

768
/**
769
 * String representations for a color
770
 */
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
export interface IColorPresentation {
	/**
	 * The label of this color presentation. It will be shown on the color
	 * picker header. By default this is also the text that is inserted when selecting
	 * this color presentation.
	 */
	label: string;
	/**
	 * An [edit](#TextEdit) which is applied to a document when selecting
	 * this presentation for the color.
	 */
	textEdit?: TextEdit;
	/**
	 * An optional array of additional [text edits](#TextEdit) that are applied when
	 * selecting this color presentation.
	 */
	additionalTextEdits?: TextEdit[];
J
Joao Moreno 已提交
788
}
J
Joao Moreno 已提交
789 790 791 792

/**
 * A color range is a range in a text model which represents a color.
 */
793
export interface IColorInformation {
J
Joao Moreno 已提交
794 795 796 797 798 799 800 801 802 803

	/**
	 * The range within the model.
	 */
	range: IRange;

	/**
	 * The color represented in this range.
	 */
	color: IColor;
J
Joao Moreno 已提交
804
}
J
Joao Moreno 已提交
805

J
Joao Moreno 已提交
806
/**
J
Joao Moreno 已提交
807
 * A provider of colors for editor models.
J
Joao Moreno 已提交
808
 */
R
rebornix 已提交
809
export interface DocumentColorProvider {
J
Joao Moreno 已提交
810 811 812
	/**
	 * Provides the color ranges for a specific model.
	 */
A
Alex Dima 已提交
813
	provideDocumentColors(model: model.ITextModel, token: CancellationToken): IColorInformation[] | Thenable<IColorInformation[]>;
814
	/**
815
	 * Provide the string representations for a color.
816
	 */
A
Alex Dima 已提交
817
	provideColorPresentations(model: model.ITextModel, colorInfo: IColorInformation, token: CancellationToken): IColorPresentation[] | Thenable<IColorPresentation[]>;
J
Joao Moreno 已提交
818
}
819

E
Erich Gamma 已提交
820 821
export interface IResourceEdit {
	resource: URI;
A
Alex Dima 已提交
822
	range: IRange;
E
Erich Gamma 已提交
823 824
	newText: string;
}
825
export interface WorkspaceEdit {
E
Erich Gamma 已提交
826 827 828
	edits: IResourceEdit[];
	rejectReason?: string;
}
829
export interface RenameProvider {
A
Alex Dima 已提交
830
	provideRenameEdits(model: model.ITextModel, position: Position, newName: string, token: CancellationToken): WorkspaceEdit | Thenable<WorkspaceEdit>;
E
Erich Gamma 已提交
831 832
}

833

A
Alex Dima 已提交
834
export interface Command {
E
Erich Gamma 已提交
835 836
	id: string;
	title: string;
837
	tooltip?: string;
E
Erich Gamma 已提交
838 839 840
	arguments?: any[];
}
export interface ICodeLensSymbol {
A
Alex Dima 已提交
841
	range: IRange;
E
Erich Gamma 已提交
842
	id?: string;
A
Alex Dima 已提交
843
	command?: Command;
E
Erich Gamma 已提交
844
}
845
export interface CodeLensProvider {
846
	onDidChange?: Event<this>;
A
Alex Dima 已提交
847 848
	provideCodeLenses(model: model.ITextModel, token: CancellationToken): ICodeLensSymbol[] | Thenable<ICodeLensSymbol[]>;
	resolveCodeLens?(model: model.ITextModel, codeLens: ICodeLensSymbol, token: CancellationToken): ICodeLensSymbol | Thenable<ICodeLensSymbol>;
E
Erich Gamma 已提交
849 850
}

851 852
// --- feature registries ------

853 854 855
/**
 * @internal
 */
856
export const ReferenceProviderRegistry = new LanguageFeatureRegistry<ReferenceProvider>();
857

858 859 860
/**
 * @internal
 */
861
export const RenameProviderRegistry = new LanguageFeatureRegistry<RenameProvider>();
862

863 864 865
/**
 * @internal
 */
866
export const SuggestRegistry = new LanguageFeatureRegistry<ISuggestSupport>();
867

868 869 870
/**
 * @internal
 */
871
export const SignatureHelpProviderRegistry = new LanguageFeatureRegistry<SignatureHelpProvider>();
872

873 874 875
/**
 * @internal
 */
876
export const HoverProviderRegistry = new LanguageFeatureRegistry<HoverProvider>();
877

878 879 880
/**
 * @internal
 */
881
export const DocumentSymbolProviderRegistry = new LanguageFeatureRegistry<DocumentSymbolProvider>();
882

883 884 885
/**
 * @internal
 */
886
export const DocumentHighlightProviderRegistry = new LanguageFeatureRegistry<DocumentHighlightProvider>();
887

888 889 890
/**
 * @internal
 */
891
export const DefinitionProviderRegistry = new LanguageFeatureRegistry<DefinitionProvider>();
892

893 894 895
/**
 * @internal
 */
M
Matt Bierner 已提交
896
export const ImplementationProviderRegistry = new LanguageFeatureRegistry<ImplementationProvider>();
897

898 899 900 901 902
/**
 * @internal
 */
export const TypeDefinitionProviderRegistry = new LanguageFeatureRegistry<TypeDefinitionProvider>();

903 904 905
/**
 * @internal
 */
906
export const CodeLensProviderRegistry = new LanguageFeatureRegistry<CodeLensProvider>();
907

908 909 910
/**
 * @internal
 */
911
export const CodeActionProviderRegistry = new LanguageFeatureRegistry<CodeActionProvider>();
912

913 914 915
/**
 * @internal
 */
916 917
export const DocumentFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentFormattingEditProvider>();

918 919 920
/**
 * @internal
 */
921
export const DocumentRangeFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentRangeFormattingEditProvider>();
922

923 924 925
/**
 * @internal
 */
926
export const OnTypeFormattingEditProviderRegistry = new LanguageFeatureRegistry<OnTypeFormattingEditProvider>();
927

928 929 930
/**
 * @internal
 */
A
Alex Dima 已提交
931
export const LinkProviderRegistry = new LanguageFeatureRegistry<LinkProvider>();
932

J
Joao Moreno 已提交
933 934 935
/**
 * @internal
 */
R
rebornix 已提交
936
export const ColorProviderRegistry = new LanguageFeatureRegistry<DocumentColorProvider>();
J
Joao Moreno 已提交
937

938 939 940 941
/**
 * @internal
 */
export interface ITokenizationSupportChangedEvent {
A
Alex Dima 已提交
942 943
	changedLanguages: string[];
	changedColorMap: boolean;
944 945 946 947 948
}

/**
 * @internal
 */
949
export interface ITokenizationRegistry {
A
Alex Dima 已提交
950 951 952 953 954 955

	/**
	 * An event triggered when:
	 *  - a tokenization support is registered, unregistered or changed.
	 *  - the color map is changed.
	 */
956
	onDidChange: Event<ITokenizationSupportChangedEvent>;
A
Alex Dima 已提交
957

958 959 960 961
	/**
	 * Fire a change event for a language.
	 * This is useful for languages that embed other languages.
	 */
962
	fire(languages: string[]): void;
963

A
Alex Dima 已提交
964 965 966
	/**
	 * Register a tokenization support.
	 */
967
	register(language: string, support: ITokenizationSupport): IDisposable;
968

A
Alex Dima 已提交
969 970 971 972
	/**
	 * Get the tokenization support for a language.
	 * Returns null if not found.
	 */
973
	get(language: string): ITokenizationSupport;
A
Alex Dima 已提交
974

A
Alex Dima 已提交
975 976 977
	/**
	 * Set the new color map that all tokens will use in their ColorId binary encoded bits for foreground and background.
	 */
978
	setColorMap(colorMap: Color[]): void;
A
Alex Dima 已提交
979

980
	getColorMap(): Color[];
A
Alex Dima 已提交
981

A
Alex Dima 已提交
982
	getDefaultBackground(): Color;
983 984 985 986 987 988
}

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