modes.ts 29.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';
M
Matt Bierner 已提交
15
import { Event } from 'vs/base/common/event';
16
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';
21
import { Selection } from 'vs/editor/common/core/selection';
E
Erich Gamma 已提交
22

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

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

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

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

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

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

	getId(): string;

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

E
Erich Gamma 已提交
64 65
}

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

/**
79
 * Open ended enum at runtime
A
Alex Dima 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
 * @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 已提交
99 100 101 102 103 104 105
/**
 * 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 已提交
106 107 108 109 110 111 112 113 114 115 116 117
 * - -------------------------------------------
 *     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 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
 *
 * @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 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
/**
 * @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;
	}
}

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

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

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

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

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

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

	/**
	 * The range to which this hover applies. When missing, the
	 * editor will use the range at the current position or the
	 * current position itself.
	 */
234
	range?: IRange;
E
Erich Gamma 已提交
235
}
236

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

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

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

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

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

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

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

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

337
	triggerCharacters?: string[];
338

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

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

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

352 353 354 355 356 357 358 359
/**
 * @internal
 */
export enum CodeActionTrigger {
	Automatic = 1,
	Manual = 2,
}

M
Matt Bierner 已提交
360 361 362 363 364
/**
 * @internal
 */
export interface CodeActionContext {
	only?: string;
365
	trigger: CodeActionTrigger;
366 367
}

A
Alex Dima 已提交
368 369 370
/**
 * The code action interface defines the contract between extensions and
 * the [light bulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) feature.
371
 * @internal
A
Alex Dima 已提交
372
 */
373
export interface CodeActionProvider {
A
Alex Dima 已提交
374 375 376
	/**
	 * Provide commands for the given document and range.
	 */
377
	provideCodeActions(model: model.ITextModel, range: Range | Selection, context: CodeActionContext, token: CancellationToken): CodeAction[] | Thenable<CodeAction[]>;
378 379 380 381 382

	/**
	 * Optional list of of CodeActionKinds that this provider returns.
	 */
	providedCodeActionKinds?: string[];
E
Erich Gamma 已提交
383 384
}

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

A
Alex Dima 已提交
447
	signatureHelpTriggerCharacters: string[];
448

A
Alex Dima 已提交
449 450 451
	/**
	 * Provide help for the signature at the given position and document.
	 */
A
Alex Dima 已提交
452
	provideSignatureHelp(model: model.ITextModel, position: Position, token: CancellationToken): SignatureHelp | Thenable<SignatureHelp>;
E
Erich Gamma 已提交
453 454
}

A
Alex Dima 已提交
455 456 457
/**
 * A document highlight kind.
 */
458
export enum DocumentHighlightKind {
A
Alex Dima 已提交
459 460 461
	/**
	 * A textual occurrence.
	 */
462
	Text,
A
Alex Dima 已提交
463 464 465
	/**
	 * Read-access of a symbol, like reading a variable.
	 */
466
	Read,
A
Alex Dima 已提交
467 468 469
	/**
	 * Write-access of a symbol, like writing to a variable.
	 */
470 471
	Write
}
A
Alex Dima 已提交
472 473 474 475 476
/**
 * 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.
 */
477
export interface DocumentHighlight {
A
Alex Dima 已提交
478 479 480
	/**
	 * The range this highlight applies to.
	 */
A
Alex Dima 已提交
481
	range: IRange;
A
Alex Dima 已提交
482 483 484
	/**
	 * The highlight kind, default is [text](#DocumentHighlightKind.Text).
	 */
485
	kind: DocumentHighlightKind;
E
Erich Gamma 已提交
486
}
A
Alex Dima 已提交
487 488 489 490
/**
 * The document highlight provider interface defines the contract between extensions and
 * the word-highlight-feature.
 */
491
export interface DocumentHighlightProvider {
A
Alex Dima 已提交
492 493 494 495
	/**
	 * Provide a set of document highlights, like all occurrences of a variable or
	 * all exit-points of a function.
	 */
A
Alex Dima 已提交
496
	provideDocumentHighlights(model: model.ITextModel, position: Position, token: CancellationToken): DocumentHighlight[] | Thenable<DocumentHighlight[]>;
E
Erich Gamma 已提交
497 498
}

A
Alex Dima 已提交
499 500 501 502
/**
 * Value-object that contains additional information when
 * requesting references.
 */
503
export interface ReferenceContext {
A
Alex Dima 已提交
504 505 506
	/**
	 * Include the declaration of the current symbol.
	 */
507 508
	includeDeclaration: boolean;
}
A
Alex Dima 已提交
509 510 511 512
/**
 * The reference provider interface defines the contract between extensions and
 * the [find references](https://code.visualstudio.com/docs/editor/editingevolved#_peek)-feature.
 */
513
export interface ReferenceProvider {
A
Alex Dima 已提交
514 515 516
	/**
	 * Provide a set of project-wide references for the given position and document.
	 */
A
Alex Dima 已提交
517
	provideReferences(model: model.ITextModel, position: Position, context: ReferenceContext, token: CancellationToken): Location[] | Thenable<Location[]>;
E
Erich Gamma 已提交
518 519
}

A
Alex Dima 已提交
520 521 522 523
/**
 * Represents a location inside a resource, such as a line
 * inside a text file.
 */
A
Alex Dima 已提交
524
export interface Location {
A
Alex Dima 已提交
525 526 527
	/**
	 * The resource identifier of this location.
	 */
528
	uri: URI;
A
Alex Dima 已提交
529 530 531
	/**
	 * The document range of this locations.
	 */
A
Alex Dima 已提交
532
	range: IRange;
E
Erich Gamma 已提交
533
}
A
Alex Dima 已提交
534 535 536 537 538
/**
 * 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.
 */
539
export type Definition = Location | Location[];
540

M
Matt Bierner 已提交
541 542 543 544 545 546 547
export interface DefinitionLink {
	origin?: IRange;
	uri: URI;
	range: IRange;
	selectionRange?: IRange;
}

A
Alex Dima 已提交
548 549 550 551 552
/**
 * 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.
 */
553
export interface DefinitionProvider {
A
Alex Dima 已提交
554 555 556
	/**
	 * Provide the definition of the symbol at the given position and document.
	 */
557
	provideDefinition(model: model.ITextModel, position: Position, token: CancellationToken): Definition | DefinitionLink[] | Thenable<Definition | DefinitionLink[]>;
558 559
}

560
/**
561
 * The implementation provider interface defines the contract between extensions and
562
 * the go to implementation feature.
563
 */
M
Matt Bierner 已提交
564
export interface ImplementationProvider {
565 566 567
	/**
	 * Provide the implementation of the symbol at the given position and document.
	 */
568
	provideImplementation(model: model.ITextModel, position: Position, token: CancellationToken): Definition | DefinitionLink[] | Thenable<Definition | DefinitionLink[]>;
569
}
570

571 572 573 574 575 576 577 578
/**
 * 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.
	 */
579
	provideTypeDefinition(model: model.ITextModel, position: Position, token: CancellationToken): Definition | DefinitionLink[] | Thenable<Definition | DefinitionLink[]>;
580 581
}

A
Alex Dima 已提交
582 583 584
/**
 * A symbol kind.
 */
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
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,
608 609
	Struct = 22,
	Event = 23,
610 611
	Operator = 24,
	TypeParameter = 25
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
}


/**
 * @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';
644 645
	_fromMapping[SymbolKind.Event] = 'event';
	_fromMapping[SymbolKind.Operator] = 'operator';
646
	_fromMapping[SymbolKind.TypeParameter] = 'type-parameter';
647 648

	return function toCssClassName(kind: SymbolKind): string {
649
		return `symbol-icon ${_fromMapping[kind] || 'property'}`;
650 651 652
	};
})();

653
export interface DocumentSymbol {
654
	name: string;
655
	detail: string;
656
	kind: SymbolKind;
657
	containerName?: string;
658 659
	range: IRange;
	selectionRange: IRange;
660
	children?: DocumentSymbol[];
661
}
662

A
Alex Dima 已提交
663 664 665 666
/**
 * 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.
 */
667
export interface DocumentSymbolProvider {
668

669
	displayName?: string;
670

A
Alex Dima 已提交
671 672 673
	/**
	 * Provide symbol information for the given document.
	 */
674
	provideDocumentSymbols(model: model.ITextModel, token: CancellationToken): DocumentSymbol[] | Thenable<DocumentSymbol[]>;
E
Erich Gamma 已提交
675 676
}

677
export interface TextEdit {
A
Alex Dima 已提交
678
	range: IRange;
679
	text: string;
680
	eol?: model.EndOfLineSequence;
681 682
}

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

736 737 738
/**
 * @internal
 */
E
Erich Gamma 已提交
739 740
export interface IInplaceReplaceSupportResult {
	value: string;
A
Alex Dima 已提交
741
	range: IRange;
E
Erich Gamma 已提交
742 743
}

A
Alex Dima 已提交
744 745 746
/**
 * A link inside the editor.
 */
747
export interface ILink {
A
Alex Dima 已提交
748
	range: IRange;
A
Alex Dima 已提交
749
	url?: string;
E
Erich Gamma 已提交
750
}
A
Alex Dima 已提交
751 752 753
/**
 * A provider of links.
 */
A
Alex Dima 已提交
754
export interface LinkProvider {
A
Alex Dima 已提交
755
	provideLinks(model: model.ITextModel, token: CancellationToken): ILink[] | Thenable<ILink[]>;
756
	resolveLink?: (link: ILink, token: CancellationToken) => ILink | Thenable<ILink>;
E
Erich Gamma 已提交
757 758
}

J
Joao Moreno 已提交
759
/**
J
Joao Moreno 已提交
760
 * A color in RGBA format.
J
Joao Moreno 已提交
761
 */
J
Joao Moreno 已提交
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
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;
}

785
/**
786
 * String representations for a color
787
 */
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
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 已提交
805
}
J
Joao Moreno 已提交
806 807 808 809

/**
 * A color range is a range in a text model which represents a color.
 */
810
export interface IColorInformation {
J
Joao Moreno 已提交
811 812 813 814 815 816 817 818 819 820

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

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

J
Joao Moreno 已提交
823
/**
J
Joao Moreno 已提交
824
 * A provider of colors for editor models.
J
Joao Moreno 已提交
825
 */
R
rebornix 已提交
826
export interface DocumentColorProvider {
J
Joao Moreno 已提交
827 828 829
	/**
	 * Provides the color ranges for a specific model.
	 */
A
Alex Dima 已提交
830
	provideDocumentColors(model: model.ITextModel, token: CancellationToken): IColorInformation[] | Thenable<IColorInformation[]>;
831
	/**
832
	 * Provide the string representations for a color.
833
	 */
A
Alex Dima 已提交
834
	provideColorPresentations(model: model.ITextModel, colorInfo: IColorInformation, token: CancellationToken): IColorPresentation[] | Thenable<IColorPresentation[]>;
J
Joao Moreno 已提交
835
}
836 837
export interface FoldingContext {
}
838 839 840
/**
 * A provider of colors for editor models.
 */
841
export interface FoldingRangeProvider {
842 843 844
	/**
	 * Provides the color ranges for a specific model.
	 */
845
	provideFoldingRanges(model: model.ITextModel, context: FoldingContext, token: CancellationToken): FoldingRange[] | Thenable<FoldingRange[]>;
846 847
}

848
export interface FoldingRange {
849 850

	/**
851
	 * The zero-based start line of the range to fold. The folded area starts after the line's last character.
852
	 */
853
	start: number;
854 855

	/**
856
	 * The zero-based end line of the range to fold. The folded area ends with the line's last character.
857
	 */
858
	end: number;
859 860

	/**
861 862 863 864
	 * Describes the [Kind](#FoldingRangeKind) of the folding range such as [Comment](#FoldingRangeKind.Comment) or
	 * [Region](#FoldingRangeKind.Region). The kind is used to categorize folding ranges and used by commands
	 * like 'Fold all comments'. See
	 * [FoldingRangeKind](#FoldingRangeKind) for an enumeration of standardized kinds.
865
	 */
866
	kind?: FoldingRangeKind;
867
}
868
export class FoldingRangeKind {
869
	/**
870
	 * Kind for folding range representing a comment. The value of the kind is 'comment'.
871
	 */
872
	static readonly Comment = new FoldingRangeKind('comment');
873
	/**
874
	 * Kind for folding range representing a import. The value of the kind is 'imports'.
875
	 */
876
	static readonly Imports = new FoldingRangeKind('imports');
877
	/**
878 879
	 * Kind for folding range representing regions (for example marked by `#region`, `#endregion`).
	 * The value of the kind is 'region'.
880
	 */
881 882
	static readonly Region = new FoldingRangeKind('region');

883
	/**
884 885 886
	 * Creates a new [FoldingRangeKind](#FoldingRangeKind).
	 *
	 * @param value of the kind.
887
	 */
888 889
	public constructor(public value: string) {
	}
890 891
}

892 893 894 895 896 897 898 899 900 901 902 903
/**
 * @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 已提交
904
}
905

906 907 908
export interface ResourceFileEdit {
	oldUri: URI;
	newUri: URI;
J
Johannes Rieken 已提交
909
	options: { overwrite?: boolean, ignoreIfNotExists?: boolean, ignoreIfExists?: boolean, recursive?: boolean };
910 911
}

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

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

923 924 925 926 927
export interface RenameLocation {
	range: IRange;
	text: string;
}

928
export interface RenameProvider {
A
Alex Dima 已提交
929
	provideRenameEdits(model: model.ITextModel, position: Position, newName: string, token: CancellationToken): WorkspaceEdit | Thenable<WorkspaceEdit>;
930
	resolveRenameLocation?(model: model.ITextModel, position: Position, token: CancellationToken): RenameLocation | Thenable<RenameLocation>;
E
Erich Gamma 已提交
931 932
}

933

A
Alex Dima 已提交
934
export interface Command {
E
Erich Gamma 已提交
935 936
	id: string;
	title: string;
937
	tooltip?: string;
E
Erich Gamma 已提交
938 939
	arguments?: any[];
}
M
Matt Bierner 已提交
940

941 942 943 944 945 946
export interface CommentInfo {
	owner: number;
	threads: CommentThread[];
	commentingRanges?: IRange[];
	reply?: Command;
}
M
Matt Bierner 已提交
947

948 949 950 951 952 953 954 955 956 957 958
export enum CommentThreadCollapsibleState {
	/**
	 * Determines an item is collapsed
	 */
	Collapsed = 0,
	/**
	 * Determines an item is expanded
	 */
	Expanded = 1
}

M
Matt Bierner 已提交
959
export interface CommentThread {
960 961 962 963 964 965
	threadId: string;
	resource: string;
	range: IRange;
	comments: Comment[];
	collapsibleState?: CommentThreadCollapsibleState;
	reply?: Command;
M
Matt Bierner 已提交
966 967
}

P
Peng Lyu 已提交
968 969 970 971 972
export interface NewCommentAction {
	ranges: IRange[];
	actions: Command[];
}

M
Matt Bierner 已提交
973
export interface Comment {
P
Peng Lyu 已提交
974
	readonly commentId: string;
M
Matt Bierner 已提交
975 976
	readonly body: IMarkdownString;
	readonly userName: string;
977
	readonly gravatar: string;
978
	readonly command?: Command;
M
Matt Bierner 已提交
979 980
}

981
export interface CommentThreadChangedEvent {
982
	readonly owner: number;
983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999
	/**
	 * Added comment threads.
	 */
	readonly added: CommentThread[];

	/**
	 * Removed comment threads.
	 */
	readonly removed: CommentThread[];

	/**
	 * Changed comment threads.
	 */
	readonly changed: CommentThread[];
}


1000
export interface DocumentCommentProvider {
1001 1002 1003
	provideDocumentComments(resource: URI, token: CancellationToken): Promise<CommentInfo>;
	createNewCommentThread(resource: URI, range: Range, text: string, token: CancellationToken): Promise<CommentThread>;
	replyToCommentThread(resource: URI, range: Range, thread: CommentThread, text: string, token: CancellationToken): Promise<CommentThread>;
1004 1005 1006 1007 1008 1009
	onDidChangeCommentThreads(): Event<CommentThreadChangedEvent>;
}


export interface WorkspaceCommentProvider {
	provideWorkspaceComments(token: CancellationToken): Promise<CommentThread[]>;
1010 1011
	createNewCommentThread(resource: URI, range: Range, text: string, token: CancellationToken): Promise<CommentThread>;
	replyToCommentThread(resource: URI, range: Range, thread: CommentThread, text: string, token: CancellationToken): Promise<CommentThread>;
1012
	onDidChangeCommentThreads(): Event<CommentThreadChangedEvent>;
M
Matt Bierner 已提交
1013 1014
}

E
Erich Gamma 已提交
1015
export interface ICodeLensSymbol {
A
Alex Dima 已提交
1016
	range: IRange;
E
Erich Gamma 已提交
1017
	id?: string;
A
Alex Dima 已提交
1018
	command?: Command;
E
Erich Gamma 已提交
1019
}
1020
export interface CodeLensProvider {
1021
	onDidChange?: Event<this>;
A
Alex Dima 已提交
1022 1023
	provideCodeLenses(model: model.ITextModel, token: CancellationToken): ICodeLensSymbol[] | Thenable<ICodeLensSymbol[]>;
	resolveCodeLens?(model: model.ITextModel, codeLens: ICodeLensSymbol, token: CancellationToken): ICodeLensSymbol | Thenable<ICodeLensSymbol>;
E
Erich Gamma 已提交
1024 1025
}

1026 1027
// --- feature registries ------

1028 1029 1030
/**
 * @internal
 */
1031
export const ReferenceProviderRegistry = new LanguageFeatureRegistry<ReferenceProvider>();
1032

1033 1034 1035
/**
 * @internal
 */
1036
export const RenameProviderRegistry = new LanguageFeatureRegistry<RenameProvider>();
1037

1038 1039 1040
/**
 * @internal
 */
1041
export const SuggestRegistry = new LanguageFeatureRegistry<ISuggestSupport>();
1042

1043 1044 1045
/**
 * @internal
 */
1046
export const SignatureHelpProviderRegistry = new LanguageFeatureRegistry<SignatureHelpProvider>();
1047

1048 1049 1050
/**
 * @internal
 */
1051
export const HoverProviderRegistry = new LanguageFeatureRegistry<HoverProvider>();
1052

1053 1054 1055
/**
 * @internal
 */
1056
export const DocumentSymbolProviderRegistry = new LanguageFeatureRegistry<DocumentSymbolProvider>();
1057

1058 1059 1060
/**
 * @internal
 */
1061
export const DocumentHighlightProviderRegistry = new LanguageFeatureRegistry<DocumentHighlightProvider>();
1062

1063 1064 1065
/**
 * @internal
 */
1066
export const DefinitionProviderRegistry = new LanguageFeatureRegistry<DefinitionProvider>();
1067

1068 1069 1070
/**
 * @internal
 */
M
Matt Bierner 已提交
1071
export const ImplementationProviderRegistry = new LanguageFeatureRegistry<ImplementationProvider>();
1072

1073 1074 1075 1076 1077
/**
 * @internal
 */
export const TypeDefinitionProviderRegistry = new LanguageFeatureRegistry<TypeDefinitionProvider>();

1078 1079 1080
/**
 * @internal
 */
1081
export const CodeLensProviderRegistry = new LanguageFeatureRegistry<CodeLensProvider>();
1082

1083 1084 1085
/**
 * @internal
 */
1086
export const CodeActionProviderRegistry = new LanguageFeatureRegistry<CodeActionProvider>();
1087

1088 1089 1090
/**
 * @internal
 */
1091 1092
export const DocumentFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentFormattingEditProvider>();

1093 1094 1095
/**
 * @internal
 */
1096
export const DocumentRangeFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentRangeFormattingEditProvider>();
1097

1098 1099 1100
/**
 * @internal
 */
1101
export const OnTypeFormattingEditProviderRegistry = new LanguageFeatureRegistry<OnTypeFormattingEditProvider>();
1102

1103 1104 1105
/**
 * @internal
 */
A
Alex Dima 已提交
1106
export const LinkProviderRegistry = new LanguageFeatureRegistry<LinkProvider>();
1107

J
Joao Moreno 已提交
1108 1109 1110
/**
 * @internal
 */
R
rebornix 已提交
1111
export const ColorProviderRegistry = new LanguageFeatureRegistry<DocumentColorProvider>();
J
Joao Moreno 已提交
1112

1113 1114 1115
/**
 * @internal
 */
1116
export const FoldingRangeProviderRegistry = new LanguageFeatureRegistry<FoldingRangeProvider>();
1117

1118 1119 1120 1121
/**
 * @internal
 */
export interface ITokenizationSupportChangedEvent {
A
Alex Dima 已提交
1122 1123
	changedLanguages: string[];
	changedColorMap: boolean;
1124 1125 1126 1127 1128
}

/**
 * @internal
 */
1129
export interface ITokenizationRegistry {
A
Alex Dima 已提交
1130 1131 1132 1133 1134 1135

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

1138 1139 1140 1141
	/**
	 * Fire a change event for a language.
	 * This is useful for languages that embed other languages.
	 */
1142
	fire(languages: string[]): void;
1143

A
Alex Dima 已提交
1144 1145 1146
	/**
	 * Register a tokenization support.
	 */
1147
	register(language: string, support: ITokenizationSupport): IDisposable;
1148

A
Alex Dima 已提交
1149 1150 1151 1152
	/**
	 * Get the tokenization support for a language.
	 * Returns null if not found.
	 */
1153
	get(language: string): ITokenizationSupport;
A
Alex Dima 已提交
1154

A
Alex Dima 已提交
1155 1156 1157
	/**
	 * Set the new color map that all tokens will use in their ColorId binary encoded bits for foreground and background.
	 */
1158
	setColorMap(colorMap: Color[]): void;
A
Alex Dima 已提交
1159

1160
	getColorMap(): Color[];
A
Alex Dima 已提交
1161

A
Alex Dima 已提交
1162
	getDefaultBackground(): Color;
1163 1164 1165 1166 1167 1168
}

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