modes.ts 22.4 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 10
import URI from 'vs/base/common/uri';
import * as editorCommon from 'vs/editor/common/editorCommon';
A
Tweaks  
Alex Dima 已提交
11
import { TokenizationResult, TokenizationResult2 } from 'vs/editor/common/core/token';
12
import LanguageFeatureRegistry from 'vs/editor/common/modes/languageFeatureRegistry';
J
Johannes Rieken 已提交
13 14
import { CancellationToken } from 'vs/base/common/cancellation';
import { Position } from 'vs/editor/common/core/position';
A
Alex Dima 已提交
15
import { Range, IRange } from 'vs/editor/common/core/range';
16 17
import Event from 'vs/base/common/event';
import { TokenizationRegistryImpl } from 'vs/editor/common/modes/tokenizationRegistry';
18
import { Color } from 'vs/base/common/color';
E
Erich Gamma 已提交
19

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

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

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

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

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

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

	getId(): string;

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

E
Erich Gamma 已提交
61 62
}

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

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

132 133 134
/**
 * @internal
 */
E
Erich Gamma 已提交
135 136
export interface ITokenizationSupport {

J
Johannes Rieken 已提交
137
	getInitialState(): IState;
E
Erich Gamma 已提交
138 139

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

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

A
Alex Dima 已提交
145 146 147 148 149
/**
 * 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 已提交
150 151 152
export interface IState {
	clone(): IState;
	equals(other: IState): boolean;
A
Alex Dima 已提交
153 154
}

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

	/**
	 * 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 已提交
170
	range: IRange;
E
Erich Gamma 已提交
171
}
172

A
Alex Dima 已提交
173 174
/**
 * The hover provider interface defines the contract between extensions and
G
Greg Van Liew 已提交
175
 * the [hover](https://code.visualstudio.com/docs/editor/intellisense)-feature.
A
Alex Dima 已提交
176
 */
A
Alex Dima 已提交
177
export interface HoverProvider {
A
Alex Dima 已提交
178 179 180 181 182
	/**
	 * Provide a hover for the given position and document. Multiple hovers at the same
	 * position will be merged by the editor. A hover can have a range which defaults
	 * to the word range at the position when omitted.
	 */
J
Johannes Rieken 已提交
183
	provideHover(model: editorCommon.IReadOnlyModel, position: Position, token: CancellationToken): Hover | Thenable<Hover>;
E
Erich Gamma 已提交
184 185
}

186 187 188
/**
 * @internal
 */
J
Johannes Rieken 已提交
189 190 191 192 193 194
export type SuggestionType = 'method'
	| 'function'
	| 'constructor'
	| 'field'
	| 'variable'
	| 'class'
195
	| 'struct'
J
Johannes Rieken 已提交
196 197 198
	| 'interface'
	| 'module'
	| 'property'
199 200
	| 'event'
	| 'operator'
J
Johannes Rieken 已提交
201 202
	| 'unit'
	| 'value'
203
	| 'constant'
J
Johannes Rieken 已提交
204
	| 'enum'
205
	| 'enum-member'
J
Johannes Rieken 已提交
206 207 208 209 210 211
	| 'keyword'
	| 'snippet'
	| 'text'
	| 'color'
	| 'file'
	| 'reference'
212
	| 'customcolor'
213 214
	| 'folder'
	| 'type-parameter';
J
Johannes Rieken 已提交
215

216 217 218
/**
 * @internal
 */
219
export type SnippetType = 'internal' | 'textmate';
220

221 222 223
/**
 * @internal
 */
E
Erich Gamma 已提交
224 225
export interface ISuggestion {
	label: string;
226
	insertText: string;
J
Johannes Rieken 已提交
227
	type: SuggestionType;
228
	detail?: string;
229
	documentation?: string | IMarkdownString;
E
Erich Gamma 已提交
230 231 232
	filterText?: string;
	sortText?: string;
	noAutoAccept?: boolean;
233
	commitCharacters?: string[];
234 235
	overwriteBefore?: number;
	overwriteAfter?: number;
236
	additionalTextEdits?: editorCommon.ISingleEditOperation[];
237
	command?: Command;
238
	snippetType?: SnippetType;
E
Erich Gamma 已提交
239 240
}

241 242 243
/**
 * @internal
 */
244
export interface ISuggestResult {
J
Johannes Rieken 已提交
245
	suggestions: ISuggestion[];
E
Erich Gamma 已提交
246
	incomplete?: boolean;
247
	dispose?(): void;
E
Erich Gamma 已提交
248 249
}

250 251 252
/**
 * @internal
 */
E
Erich Gamma 已提交
253 254
export interface ISuggestSupport {

255
	triggerCharacters?: string[];
256

257
	provideCompletionItems(model: editorCommon.IModel, position: Position, token: CancellationToken): ISuggestResult | Thenable<ISuggestResult>;
E
Erich Gamma 已提交
258

259
	resolveCompletionItem?(model: editorCommon.IModel, position: Position, item: ISuggestion, token: CancellationToken): ISuggestion | Thenable<ISuggestion>;
E
Erich Gamma 已提交
260 261
}

A
Alex Dima 已提交
262 263 264
/**
 * The code action interface defines the contract between extensions and
 * the [light bulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) feature.
265
 * @internal
A
Alex Dima 已提交
266
 */
267
export interface CodeActionProvider {
A
Alex Dima 已提交
268 269 270
	/**
	 * Provide commands for the given document and range.
	 */
J
Johannes Rieken 已提交
271
	provideCodeActions(model: editorCommon.IReadOnlyModel, range: Range, token: CancellationToken): Command[] | Thenable<Command[]>;
E
Erich Gamma 已提交
272 273
}

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

A
Alex Dima 已提交
336
	signatureHelpTriggerCharacters: string[];
337

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

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

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

A
Alex Dima 已提交
409 410 411 412
/**
 * Represents a location inside a resource, such as a line
 * inside a text file.
 */
A
Alex Dima 已提交
413
export interface Location {
A
Alex Dima 已提交
414 415 416
	/**
	 * The resource identifier of this location.
	 */
417
	uri: URI;
A
Alex Dima 已提交
418 419 420
	/**
	 * The document range of this locations.
	 */
A
Alex Dima 已提交
421
	range: IRange;
E
Erich Gamma 已提交
422
}
A
Alex Dima 已提交
423 424 425 426 427
/**
 * 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.
 */
428
export type Definition = Location | Location[];
429

A
Alex Dima 已提交
430 431 432 433 434
/**
 * 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.
 */
435
export interface DefinitionProvider {
A
Alex Dima 已提交
436 437 438
	/**
	 * Provide the definition of the symbol at the given position and document.
	 */
J
Johannes Rieken 已提交
439
	provideDefinition(model: editorCommon.IReadOnlyModel, position: Position, token: CancellationToken): Definition | Thenable<Definition>;
440 441
}

442
/**
443
 * The implementation provider interface defines the contract between extensions and
444
 * the go to implementation feature.
445
 */
M
Matt Bierner 已提交
446
export interface ImplementationProvider {
447 448 449
	/**
	 * Provide the implementation of the symbol at the given position and document.
	 */
M
Matt Bierner 已提交
450
	provideImplementation(model: editorCommon.IReadOnlyModel, position: Position, token: CancellationToken): Definition | Thenable<Definition>;
451
}
452

453 454 455 456 457 458 459 460 461 462 463
/**
 * 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.
	 */
	provideTypeDefinition(model: editorCommon.IReadOnlyModel, position: Position, token: CancellationToken): Definition | Thenable<Definition>;
}

A
Alex Dima 已提交
464 465 466
/**
 * A symbol kind.
 */
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
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,
490 491
	Struct = 22,
	Event = 23,
492 493
	Operator = 24,
	TypeParameter = 25
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
}


/**
 * @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';
526 527
	_fromMapping[SymbolKind.Event] = 'event';
	_fromMapping[SymbolKind.Operator] = 'operator';
528
	_fromMapping[SymbolKind.TypeParameter] = 'type-parameter';
529 530 531 532 533 534

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

A
Alex Dima 已提交
535 536 537 538 539 540
/**
 * @internal
 */
export interface IOutline {
	entries: SymbolInformation[];
}
A
Alex Dima 已提交
541 542 543 544
/**
 * Represents information about programming constructs like variables, classes,
 * interfaces etc.
 */
545
export interface SymbolInformation {
A
Alex Dima 已提交
546 547 548
	/**
	 * The name of this symbol.
	 */
549
	name: string;
A
Alex Dima 已提交
550 551 552
	/**
	 * The name of the symbol containing this symbol.
	 */
553
	containerName?: string;
A
Alex Dima 已提交
554 555 556
	/**
	 * The kind of this symbol.
	 */
557
	kind: SymbolKind;
A
Alex Dima 已提交
558 559 560
	/**
	 * The location of this symbol.
	 */
561 562
	location: Location;
}
A
Alex Dima 已提交
563 564 565 566
/**
 * 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.
 */
567
export interface DocumentSymbolProvider {
A
Alex Dima 已提交
568 569 570
	/**
	 * Provide symbol information for the given document.
	 */
J
Johannes Rieken 已提交
571
	provideDocumentSymbols(model: editorCommon.IReadOnlyModel, token: CancellationToken): SymbolInformation[] | Thenable<SymbolInformation[]>;
E
Erich Gamma 已提交
572 573
}

574
export interface TextEdit {
A
Alex Dima 已提交
575
	range: IRange;
576 577
	text: string;
	eol?: editorCommon.EndOfLineSequence;
578 579
}

E
Erich Gamma 已提交
580 581 582
/**
 * Interface used to format a model
 */
A
Alex Dima 已提交
583 584 585 586
export interface FormattingOptions {
	/**
	 * Size of a tab in spaces.
	 */
J
Johannes Rieken 已提交
587
	tabSize: number;
A
Alex Dima 已提交
588 589 590
	/**
	 * Prefer spaces over tabs.
	 */
J
Johannes Rieken 已提交
591
	insertSpaces: boolean;
E
Erich Gamma 已提交
592
}
A
Alex Dima 已提交
593 594 595 596
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
597
export interface DocumentFormattingEditProvider {
A
Alex Dima 已提交
598 599 600
	/**
	 * Provide formatting edits for a whole document.
	 */
601
	provideDocumentFormattingEdits(model: editorCommon.IReadOnlyModel, options: FormattingOptions, token: CancellationToken): TextEdit[] | Thenable<TextEdit[]>;
602
}
A
Alex Dima 已提交
603 604 605 606
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
607
export interface DocumentRangeFormattingEditProvider {
A
Alex Dima 已提交
608 609 610 611 612 613 614
	/**
	 * 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.
	 */
615
	provideDocumentRangeFormattingEdits(model: editorCommon.IReadOnlyModel, range: Range, options: FormattingOptions, token: CancellationToken): TextEdit[] | Thenable<TextEdit[]>;
616
}
A
Alex Dima 已提交
617 618 619 620
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
621 622
export interface OnTypeFormattingEditProvider {
	autoFormatTriggerCharacters: string[];
A
Alex Dima 已提交
623 624 625 626 627 628 629
	/**
	 * 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.
	 */
630
	provideOnTypeFormattingEdits(model: editorCommon.IReadOnlyModel, position: Position, ch: string, options: FormattingOptions, token: CancellationToken): TextEdit[] | Thenable<TextEdit[]>;
E
Erich Gamma 已提交
631 632
}

633 634 635
/**
 * @internal
 */
E
Erich Gamma 已提交
636 637
export interface IInplaceReplaceSupportResult {
	value: string;
A
Alex Dima 已提交
638
	range: IRange;
E
Erich Gamma 已提交
639 640
}

A
Alex Dima 已提交
641 642 643
/**
 * A link inside the editor.
 */
644
export interface ILink {
A
Alex Dima 已提交
645
	range: IRange;
E
Erich Gamma 已提交
646 647
	url: string;
}
A
Alex Dima 已提交
648 649 650
/**
 * A provider of links.
 */
A
Alex Dima 已提交
651
export interface LinkProvider {
652
	provideLinks(model: editorCommon.IReadOnlyModel, token: CancellationToken): ILink[] | Thenable<ILink[]>;
653
	resolveLink?: (link: ILink, token: CancellationToken) => ILink | Thenable<ILink>;
E
Erich Gamma 已提交
654 655
}

J
Joao Moreno 已提交
656
/**
J
Joao Moreno 已提交
657
 * A color in RGBA format.
J
Joao Moreno 已提交
658
 */
J
Joao Moreno 已提交
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
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;
}

J
Joao Moreno 已提交
682
/**
J
Joao Moreno 已提交
683
 * A color formatter.
J
Joao Moreno 已提交
684
 */
J
Joao Moreno 已提交
685 686
export interface IColorFormatter {
	readonly supportsTransparency: boolean;
R
rebornix 已提交
687
	format(color: IColor): string;
J
Joao Moreno 已提交
688
}
J
Joao Moreno 已提交
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707

/**
 * A color range is a range in a text model which represents a color.
 */
export interface IColorRange {

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

	/**
	 * The color represented in this range.
	 */
	color: IColor;

	/**
	 * The available formats for this specific color.
	 */
J
Joao Moreno 已提交
708
	formatters: IColorFormatter[];
J
Joao Moreno 已提交
709
}
J
Joao Moreno 已提交
710

J
Joao Moreno 已提交
711
/**
J
Joao Moreno 已提交
712
 * A provider of colors for editor models.
J
Joao Moreno 已提交
713
 */
R
rebornix 已提交
714
export interface DocumentColorProvider {
J
Joao Moreno 已提交
715 716 717 718
	/**
	 * Provides the color ranges for a specific model.
	 */
	provideColorRanges(model: editorCommon.IReadOnlyModel, token: CancellationToken): IColorRange[] | Thenable<IColorRange[]>;
J
Joao Moreno 已提交
719
}
720

E
Erich Gamma 已提交
721 722
export interface IResourceEdit {
	resource: URI;
A
Alex Dima 已提交
723
	range: IRange;
E
Erich Gamma 已提交
724 725
	newText: string;
}
726
export interface WorkspaceEdit {
E
Erich Gamma 已提交
727 728 729
	edits: IResourceEdit[];
	rejectReason?: string;
}
730
export interface RenameProvider {
J
Johannes Rieken 已提交
731
	provideRenameEdits(model: editorCommon.IReadOnlyModel, position: Position, newName: string, token: CancellationToken): WorkspaceEdit | Thenable<WorkspaceEdit>;
E
Erich Gamma 已提交
732 733
}

734

A
Alex Dima 已提交
735
export interface Command {
E
Erich Gamma 已提交
736 737
	id: string;
	title: string;
738
	tooltip?: string;
E
Erich Gamma 已提交
739 740 741
	arguments?: any[];
}
export interface ICodeLensSymbol {
A
Alex Dima 已提交
742
	range: IRange;
E
Erich Gamma 已提交
743
	id?: string;
A
Alex Dima 已提交
744
	command?: Command;
E
Erich Gamma 已提交
745
}
746
export interface CodeLensProvider {
747
	onDidChange?: Event<this>;
J
Johannes Rieken 已提交
748 749
	provideCodeLenses(model: editorCommon.IReadOnlyModel, token: CancellationToken): ICodeLensSymbol[] | Thenable<ICodeLensSymbol[]>;
	resolveCodeLens?(model: editorCommon.IReadOnlyModel, codeLens: ICodeLensSymbol, token: CancellationToken): ICodeLensSymbol | Thenable<ICodeLensSymbol>;
E
Erich Gamma 已提交
750 751
}

752 753
// --- feature registries ------

754 755 756
/**
 * @internal
 */
757
export const ReferenceProviderRegistry = new LanguageFeatureRegistry<ReferenceProvider>();
758

759 760 761
/**
 * @internal
 */
762
export const RenameProviderRegistry = new LanguageFeatureRegistry<RenameProvider>();
763

764 765 766
/**
 * @internal
 */
767
export const SuggestRegistry = new LanguageFeatureRegistry<ISuggestSupport>();
768

769 770 771
/**
 * @internal
 */
772
export const SignatureHelpProviderRegistry = new LanguageFeatureRegistry<SignatureHelpProvider>();
773

774 775 776
/**
 * @internal
 */
777
export const HoverProviderRegistry = new LanguageFeatureRegistry<HoverProvider>();
778

779 780 781
/**
 * @internal
 */
782
export const DocumentSymbolProviderRegistry = new LanguageFeatureRegistry<DocumentSymbolProvider>();
783

784 785 786
/**
 * @internal
 */
787
export const DocumentHighlightProviderRegistry = new LanguageFeatureRegistry<DocumentHighlightProvider>();
788

789 790 791
/**
 * @internal
 */
792
export const DefinitionProviderRegistry = new LanguageFeatureRegistry<DefinitionProvider>();
793

794 795 796
/**
 * @internal
 */
M
Matt Bierner 已提交
797
export const ImplementationProviderRegistry = new LanguageFeatureRegistry<ImplementationProvider>();
798

799 800 801 802 803
/**
 * @internal
 */
export const TypeDefinitionProviderRegistry = new LanguageFeatureRegistry<TypeDefinitionProvider>();

804 805 806
/**
 * @internal
 */
807
export const CodeLensProviderRegistry = new LanguageFeatureRegistry<CodeLensProvider>();
808

809 810 811
/**
 * @internal
 */
812
export const CodeActionProviderRegistry = new LanguageFeatureRegistry<CodeActionProvider>();
813

814 815 816
/**
 * @internal
 */
817 818
export const DocumentFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentFormattingEditProvider>();

819 820 821
/**
 * @internal
 */
822
export const DocumentRangeFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentRangeFormattingEditProvider>();
823

824 825 826
/**
 * @internal
 */
827
export const OnTypeFormattingEditProviderRegistry = new LanguageFeatureRegistry<OnTypeFormattingEditProvider>();
828

829 830 831
/**
 * @internal
 */
A
Alex Dima 已提交
832
export const LinkProviderRegistry = new LanguageFeatureRegistry<LinkProvider>();
833

J
Joao Moreno 已提交
834 835 836
/**
 * @internal
 */
R
rebornix 已提交
837
export const ColorProviderRegistry = new LanguageFeatureRegistry<DocumentColorProvider>();
J
Joao Moreno 已提交
838

839 840 841 842
/**
 * @internal
 */
export interface ITokenizationSupportChangedEvent {
A
Alex Dima 已提交
843 844
	changedLanguages: string[];
	changedColorMap: boolean;
845 846 847 848 849
}

/**
 * @internal
 */
850
export interface ITokenizationRegistry {
A
Alex Dima 已提交
851 852 853 854 855 856

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

859 860 861 862
	/**
	 * Fire a change event for a language.
	 * This is useful for languages that embed other languages.
	 */
863
	fire(languages: string[]): void;
864

A
Alex Dima 已提交
865 866 867
	/**
	 * Register a tokenization support.
	 */
868
	register(language: string, support: ITokenizationSupport): IDisposable;
869

A
Alex Dima 已提交
870 871 872 873
	/**
	 * Get the tokenization support for a language.
	 * Returns null if not found.
	 */
874
	get(language: string): ITokenizationSupport;
A
Alex Dima 已提交
875

A
Alex Dima 已提交
876 877 878
	/**
	 * Set the new color map that all tokens will use in their ColorId binary encoded bits for foreground and background.
	 */
879
	setColorMap(colorMap: Color[]): void;
A
Alex Dima 已提交
880

881
	getColorMap(): Color[];
A
Alex Dima 已提交
882 883
	getDefaultForeground(): Color;
	getDefaultBackground(): Color;
884 885 886 887 888 889
}

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