modes.ts 22.3 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 229
	detail?: string;
	documentation?: string;
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 247 248
	incomplete?: boolean;
}

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

254
	triggerCharacters?: string[];
255

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

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

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

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

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

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

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

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

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

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

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

452 453 454 455 456 457 458 459 460 461 462
/**
 * 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 已提交
463 464 465
/**
 * A symbol kind.
 */
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
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,
489 490
	Struct = 22,
	Event = 23,
491 492
	Operator = 24,
	TypeParameter = 25
493 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
}


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

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

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

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

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

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

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

J
Joao Moreno 已提交
655
/**
J
Joao Moreno 已提交
656
 * A color in RGBA format.
J
Joao Moreno 已提交
657
 */
J
Joao Moreno 已提交
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
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 已提交
681
/**
J
Joao Moreno 已提交
682
 * A color formatter.
J
Joao Moreno 已提交
683
 */
J
Joao Moreno 已提交
684 685
export interface IColorFormatter {
	readonly supportsTransparency: boolean;
R
rebornix 已提交
686
	format(color: IColor): string;
J
Joao Moreno 已提交
687
}
J
Joao Moreno 已提交
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706

/**
 * 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 已提交
707
	formatters: IColorFormatter[];
J
Joao Moreno 已提交
708
}
J
Joao Moreno 已提交
709

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

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

733

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

751 752
// --- feature registries ------

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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