modes.ts 26.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';
20
import { isObject } from 'vs/base/common/types';
E
Erich Gamma 已提交
21

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

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

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

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

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

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

	getId(): string;

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

E
Erich Gamma 已提交
63 64
}

A
Alex Dima 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77
/**
 * 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
}

/**
78
 * Open ended enum at runtime
A
Alex Dima 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
 * @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 已提交
98 99 100 101 102 103 104
/**
 * 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 已提交
105 106 107 108 109 110 111 112 113 114 115 116
 * - -------------------------------------------
 *     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 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
 *
 * @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 已提交
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
/**
 * @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;
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

335
	triggerCharacters?: string[];
336

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

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

342 343 344
export interface CodeAction {
	title: string;
	command?: Command;
345
	edit?: WorkspaceEdit;
346
	diagnostics?: IMarkerData[];
M
Matt Bierner 已提交
347 348 349 350 351 352 353 354
	kind?: string;
}

/**
 * @internal
 */
export interface CodeActionContext {
	only?: string;
355 356
}

A
Alex Dima 已提交
357 358 359
/**
 * The code action interface defines the contract between extensions and
 * the [light bulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) feature.
360
 * @internal
A
Alex Dima 已提交
361
 */
362
export interface CodeActionProvider {
A
Alex Dima 已提交
363 364 365
	/**
	 * Provide commands for the given document and range.
	 */
M
Matt Bierner 已提交
366
	provideCodeActions(model: model.ITextModel, range: Range, context: CodeActionContext, token: CancellationToken): CodeAction[] | Thenable<CodeAction[]>;
E
Erich Gamma 已提交
367 368
}

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

A
Alex Dima 已提交
431
	signatureHelpTriggerCharacters: string[];
432

A
Alex Dima 已提交
433 434 435
	/**
	 * Provide help for the signature at the given position and document.
	 */
A
Alex Dima 已提交
436
	provideSignatureHelp(model: model.ITextModel, position: Position, token: CancellationToken): SignatureHelp | Thenable<SignatureHelp>;
E
Erich Gamma 已提交
437 438
}

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

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

A
Alex Dima 已提交
504 505 506 507
/**
 * Represents a location inside a resource, such as a line
 * inside a text file.
 */
A
Alex Dima 已提交
508
export interface Location {
A
Alex Dima 已提交
509 510 511
	/**
	 * The resource identifier of this location.
	 */
512
	uri: URI;
A
Alex Dima 已提交
513 514 515
	/**
	 * The document range of this locations.
	 */
A
Alex Dima 已提交
516
	range: IRange;
E
Erich Gamma 已提交
517
}
A
Alex Dima 已提交
518 519 520 521 522
/**
 * 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.
 */
523
export type Definition = Location | Location[];
524

A
Alex Dima 已提交
525 526 527 528 529
/**
 * 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.
 */
530
export interface DefinitionProvider {
A
Alex Dima 已提交
531 532 533
	/**
	 * Provide the definition of the symbol at the given position and document.
	 */
A
Alex Dima 已提交
534
	provideDefinition(model: model.ITextModel, position: Position, token: CancellationToken): Definition | Thenable<Definition>;
535 536
}

537
/**
538
 * The implementation provider interface defines the contract between extensions and
539
 * the go to implementation feature.
540
 */
M
Matt Bierner 已提交
541
export interface ImplementationProvider {
542 543 544
	/**
	 * Provide the implementation of the symbol at the given position and document.
	 */
A
Alex Dima 已提交
545
	provideImplementation(model: model.ITextModel, position: Position, token: CancellationToken): Definition | Thenable<Definition>;
546
}
547

548 549 550 551 552 553 554 555
/**
 * 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 已提交
556
	provideTypeDefinition(model: model.ITextModel, position: Position, token: CancellationToken): Definition | Thenable<Definition>;
557 558
}

A
Alex Dima 已提交
559 560 561
/**
 * A symbol kind.
 */
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
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,
585 586
	Struct = 22,
	Event = 23,
587 588
	Operator = 24,
	TypeParameter = 25
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
}


/**
 * @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';
621 622
	_fromMapping[SymbolKind.Event] = 'event';
	_fromMapping[SymbolKind.Operator] = 'operator';
623
	_fromMapping[SymbolKind.TypeParameter] = 'type-parameter';
624 625 626 627 628 629

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

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

669
export interface TextEdit {
A
Alex Dima 已提交
670
	range: IRange;
671
	text: string;
672
	eol?: model.EndOfLineSequence;
673 674
}

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

728 729 730
/**
 * @internal
 */
E
Erich Gamma 已提交
731 732
export interface IInplaceReplaceSupportResult {
	value: string;
A
Alex Dima 已提交
733
	range: IRange;
E
Erich Gamma 已提交
734 735
}

A
Alex Dima 已提交
736 737 738
/**
 * A link inside the editor.
 */
739
export interface ILink {
A
Alex Dima 已提交
740
	range: IRange;
A
Alex Dima 已提交
741
	url?: string;
E
Erich Gamma 已提交
742
}
A
Alex Dima 已提交
743 744 745
/**
 * A provider of links.
 */
A
Alex Dima 已提交
746
export interface LinkProvider {
A
Alex Dima 已提交
747
	provideLinks(model: model.ITextModel, token: CancellationToken): ILink[] | Thenable<ILink[]>;
748
	resolveLink?: (link: ILink, token: CancellationToken) => ILink | Thenable<ILink>;
E
Erich Gamma 已提交
749 750
}

J
Joao Moreno 已提交
751
/**
J
Joao Moreno 已提交
752
 * A color in RGBA format.
J
Joao Moreno 已提交
753
 */
J
Joao Moreno 已提交
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
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;
}

777
/**
778
 * String representations for a color
779
 */
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
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 已提交
797
}
J
Joao Moreno 已提交
798 799 800 801

/**
 * A color range is a range in a text model which represents a color.
 */
802
export interface IColorInformation {
J
Joao Moreno 已提交
803 804 805 806 807 808 809 810 811 812

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

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

J
Joao Moreno 已提交
815
/**
J
Joao Moreno 已提交
816
 * A provider of colors for editor models.
J
Joao Moreno 已提交
817
 */
R
rebornix 已提交
818
export interface DocumentColorProvider {
J
Joao Moreno 已提交
819 820 821
	/**
	 * Provides the color ranges for a specific model.
	 */
A
Alex Dima 已提交
822
	provideDocumentColors(model: model.ITextModel, token: CancellationToken): IColorInformation[] | Thenable<IColorInformation[]>;
823
	/**
824
	 * Provide the string representations for a color.
825
	 */
A
Alex Dima 已提交
826
	provideColorPresentations(model: model.ITextModel, colorInfo: IColorInformation, token: CancellationToken): IColorPresentation[] | Thenable<IColorPresentation[]>;
J
Joao Moreno 已提交
827
}
828

829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
/**
 * A provider of colors for editor models.
 */
/**
 * @internal
 */
export interface FoldingProvider {
	/**
	 * Provides the color ranges for a specific model.
	 */
	provideFoldingRanges(model: model.ITextModel, token: CancellationToken): IFoldingRangeList | Thenable<IFoldingRangeList>;
}
/**
 * @internal
 */
export interface IFoldingRangeList {

	ranges: IFoldingRange[];
}
/**
 * @internal
 */
export interface IFoldingRange {

	/**
	 * The start line number
	 */
	startLineNumber: number;

	/**
	 * The end line number
	 */
	endLineNumber: number;

	/**
	 * The optional type of the folding range
	 */
	type?: FoldingRangeType | string;

	// auto-collapse
	// header span

}
/**
 * @internal
 */
export enum FoldingRangeType {
	/**
	 * Folding range for a comment
	 */
	Comment = 'comment',
	/**
	 * Folding range for a imports or includes
	 */
	Imports = 'imports',
	/**
	 * Folding range for a region (e.g. `#region`)
	 */
	Region = 'region'
}

890 891 892 893 894 895 896 897 898 899 900 901
/**
 * @internal
 */
export function isResourceFileEdit(thing: any): thing is ResourceFileEdit {
	return isObject(thing) && (Boolean((<ResourceFileEdit>thing).newUri) || Boolean((<ResourceFileEdit>thing).oldUri));
}

/**
 * @internal
 */
export function isResourceTextEdit(thing: any): thing is ResourceTextEdit {
	return isObject(thing) && (<ResourceTextEdit>thing).resource && Array.isArray((<ResourceTextEdit>thing).edits);
E
Erich Gamma 已提交
902
}
903

904 905 906
export interface ResourceFileEdit {
	oldUri: URI;
	newUri: URI;
907 908
}

909
export interface ResourceTextEdit {
E
Erich Gamma 已提交
910
	resource: URI;
911 912
	modelVersionId?: number;
	edits: TextEdit[];
E
Erich Gamma 已提交
913
}
914

915
export interface WorkspaceEdit {
916 917
	edits: Array<ResourceTextEdit | ResourceFileEdit>;
	rejectReason?: string; // TODO@joh, move to rename
E
Erich Gamma 已提交
918
}
919

920
export interface RenameContext {
K
Krzysztof Cieslak 已提交
921
	range: IRange;
J
Johannes Rieken 已提交
922
	text: string;
K
Krzysztof Cieslak 已提交
923
}
924

925
export interface RenameProvider {
A
Alex Dima 已提交
926
	provideRenameEdits(model: model.ITextModel, position: Position, newName: string, token: CancellationToken): WorkspaceEdit | Thenable<WorkspaceEdit>;
927
	resolveRenameContext?(model: model.ITextModel, position: Position, token: CancellationToken): RenameContext | Thenable<RenameContext>;
E
Erich Gamma 已提交
928 929
}

930

A
Alex Dima 已提交
931
export interface Command {
E
Erich Gamma 已提交
932 933
	id: string;
	title: string;
934
	tooltip?: string;
E
Erich Gamma 已提交
935 936 937
	arguments?: any[];
}
export interface ICodeLensSymbol {
A
Alex Dima 已提交
938
	range: IRange;
E
Erich Gamma 已提交
939
	id?: string;
A
Alex Dima 已提交
940
	command?: Command;
E
Erich Gamma 已提交
941
}
942
export interface CodeLensProvider {
943
	onDidChange?: Event<this>;
A
Alex Dima 已提交
944 945
	provideCodeLenses(model: model.ITextModel, token: CancellationToken): ICodeLensSymbol[] | Thenable<ICodeLensSymbol[]>;
	resolveCodeLens?(model: model.ITextModel, codeLens: ICodeLensSymbol, token: CancellationToken): ICodeLensSymbol | Thenable<ICodeLensSymbol>;
E
Erich Gamma 已提交
946 947
}

948 949
// --- feature registries ------

950 951 952
/**
 * @internal
 */
953
export const ReferenceProviderRegistry = new LanguageFeatureRegistry<ReferenceProvider>();
954

955 956 957
/**
 * @internal
 */
958
export const RenameProviderRegistry = new LanguageFeatureRegistry<RenameProvider>();
959

960 961 962
/**
 * @internal
 */
963
export const SuggestRegistry = new LanguageFeatureRegistry<ISuggestSupport>();
964

965 966 967
/**
 * @internal
 */
968
export const SignatureHelpProviderRegistry = new LanguageFeatureRegistry<SignatureHelpProvider>();
969

970 971 972
/**
 * @internal
 */
973
export const HoverProviderRegistry = new LanguageFeatureRegistry<HoverProvider>();
974

975 976 977
/**
 * @internal
 */
978
export const DocumentSymbolProviderRegistry = new LanguageFeatureRegistry<DocumentSymbolProvider>();
979

980 981 982
/**
 * @internal
 */
983
export const DocumentHighlightProviderRegistry = new LanguageFeatureRegistry<DocumentHighlightProvider>();
984

985 986 987
/**
 * @internal
 */
988
export const DefinitionProviderRegistry = new LanguageFeatureRegistry<DefinitionProvider>();
989

990 991 992
/**
 * @internal
 */
M
Matt Bierner 已提交
993
export const ImplementationProviderRegistry = new LanguageFeatureRegistry<ImplementationProvider>();
994

995 996 997 998 999
/**
 * @internal
 */
export const TypeDefinitionProviderRegistry = new LanguageFeatureRegistry<TypeDefinitionProvider>();

1000 1001 1002
/**
 * @internal
 */
1003
export const CodeLensProviderRegistry = new LanguageFeatureRegistry<CodeLensProvider>();
1004

1005 1006 1007
/**
 * @internal
 */
1008
export const CodeActionProviderRegistry = new LanguageFeatureRegistry<CodeActionProvider>();
1009

1010 1011 1012
/**
 * @internal
 */
1013 1014
export const DocumentFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentFormattingEditProvider>();

1015 1016 1017
/**
 * @internal
 */
1018
export const DocumentRangeFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentRangeFormattingEditProvider>();
1019

1020 1021 1022
/**
 * @internal
 */
1023
export const OnTypeFormattingEditProviderRegistry = new LanguageFeatureRegistry<OnTypeFormattingEditProvider>();
1024

1025 1026 1027
/**
 * @internal
 */
A
Alex Dima 已提交
1028
export const LinkProviderRegistry = new LanguageFeatureRegistry<LinkProvider>();
1029

J
Joao Moreno 已提交
1030 1031 1032
/**
 * @internal
 */
R
rebornix 已提交
1033
export const ColorProviderRegistry = new LanguageFeatureRegistry<DocumentColorProvider>();
J
Joao Moreno 已提交
1034

1035 1036 1037 1038 1039
/**
 * @internal
 */
export const FoldingProviderRegistry = new LanguageFeatureRegistry<FoldingProvider>();

1040 1041 1042 1043
/**
 * @internal
 */
export interface ITokenizationSupportChangedEvent {
A
Alex Dima 已提交
1044 1045
	changedLanguages: string[];
	changedColorMap: boolean;
1046 1047 1048 1049 1050
}

/**
 * @internal
 */
1051
export interface ITokenizationRegistry {
A
Alex Dima 已提交
1052 1053 1054 1055 1056 1057

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

1060 1061 1062 1063
	/**
	 * Fire a change event for a language.
	 * This is useful for languages that embed other languages.
	 */
1064
	fire(languages: string[]): void;
1065

A
Alex Dima 已提交
1066 1067 1068
	/**
	 * Register a tokenization support.
	 */
1069
	register(language: string, support: ITokenizationSupport): IDisposable;
1070

A
Alex Dima 已提交
1071 1072 1073 1074
	/**
	 * Get the tokenization support for a language.
	 * Returns null if not found.
	 */
1075
	get(language: string): ITokenizationSupport;
A
Alex Dima 已提交
1076

A
Alex Dima 已提交
1077 1078 1079
	/**
	 * Set the new color map that all tokens will use in their ColorId binary encoded bits for foreground and background.
	 */
1080
	setColorMap(colorMap: Color[]): void;
A
Alex Dima 已提交
1081

1082
	getColorMap(): Color[];
A
Alex Dima 已提交
1083

A
Alex Dima 已提交
1084
	getDefaultBackground(): Color;
1085 1086 1087 1088 1089 1090
}

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