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

J
Johannes Rieken 已提交
7 8
import { MarkedString } from 'vs/base/common/htmlContent';
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.
	 */
M
Michel Kaporin 已提交
163
	contents: MarkedString[];
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 656 657
/**
 * A color inside the editor.
 */
658
export type IColorFormat = string | { opaque: string, transparent: string };
659
export interface IColorInfo {
J
Joao Moreno 已提交
660
	color: Color;
661 662
	format: IColorFormat;
	availableFormats: IColorFormat[];
663
	range: IRange;
J
Joao Moreno 已提交
664 665
}
/**
M
Michel Kaporin 已提交
666
 * A provider of colors.
J
Joao Moreno 已提交
667 668
 */
export interface ColorProvider {
M
Michel Kaporin 已提交
669

670
	provideColors(model: editorCommon.IReadOnlyModel, token: CancellationToken): IColorInfo[] | Thenable<IColorInfo[]>;
J
Joao Moreno 已提交
671
}
672

E
Erich Gamma 已提交
673 674
export interface IResourceEdit {
	resource: URI;
A
Alex Dima 已提交
675
	range: IRange;
E
Erich Gamma 已提交
676 677
	newText: string;
}
678
export interface WorkspaceEdit {
E
Erich Gamma 已提交
679 680 681
	edits: IResourceEdit[];
	rejectReason?: string;
}
682
export interface RenameProvider {
J
Johannes Rieken 已提交
683
	provideRenameEdits(model: editorCommon.IReadOnlyModel, position: Position, newName: string, token: CancellationToken): WorkspaceEdit | Thenable<WorkspaceEdit>;
E
Erich Gamma 已提交
684 685
}

686

A
Alex Dima 已提交
687
export interface Command {
E
Erich Gamma 已提交
688 689
	id: string;
	title: string;
690
	tooltip?: string;
E
Erich Gamma 已提交
691 692 693
	arguments?: any[];
}
export interface ICodeLensSymbol {
A
Alex Dima 已提交
694
	range: IRange;
E
Erich Gamma 已提交
695
	id?: string;
A
Alex Dima 已提交
696
	command?: Command;
E
Erich Gamma 已提交
697
}
698
export interface CodeLensProvider {
699
	onDidChange?: Event<this>;
J
Johannes Rieken 已提交
700 701
	provideCodeLenses(model: editorCommon.IReadOnlyModel, token: CancellationToken): ICodeLensSymbol[] | Thenable<ICodeLensSymbol[]>;
	resolveCodeLens?(model: editorCommon.IReadOnlyModel, codeLens: ICodeLensSymbol, token: CancellationToken): ICodeLensSymbol | Thenable<ICodeLensSymbol>;
E
Erich Gamma 已提交
702 703
}

704 705
// --- feature registries ------

706 707 708
/**
 * @internal
 */
709
export const ReferenceProviderRegistry = new LanguageFeatureRegistry<ReferenceProvider>();
710

711 712 713
/**
 * @internal
 */
714
export const RenameProviderRegistry = new LanguageFeatureRegistry<RenameProvider>();
715

716 717 718
/**
 * @internal
 */
719
export const SuggestRegistry = new LanguageFeatureRegistry<ISuggestSupport>();
720

721 722 723
/**
 * @internal
 */
724
export const SignatureHelpProviderRegistry = new LanguageFeatureRegistry<SignatureHelpProvider>();
725

726 727 728
/**
 * @internal
 */
729
export const HoverProviderRegistry = new LanguageFeatureRegistry<HoverProvider>();
730

731 732 733
/**
 * @internal
 */
734
export const DocumentSymbolProviderRegistry = new LanguageFeatureRegistry<DocumentSymbolProvider>();
735

736 737 738
/**
 * @internal
 */
739
export const DocumentHighlightProviderRegistry = new LanguageFeatureRegistry<DocumentHighlightProvider>();
740

741 742 743
/**
 * @internal
 */
744
export const DefinitionProviderRegistry = new LanguageFeatureRegistry<DefinitionProvider>();
745

746 747 748
/**
 * @internal
 */
M
Matt Bierner 已提交
749
export const ImplementationProviderRegistry = new LanguageFeatureRegistry<ImplementationProvider>();
750

751 752 753 754 755
/**
 * @internal
 */
export const TypeDefinitionProviderRegistry = new LanguageFeatureRegistry<TypeDefinitionProvider>();

756 757 758
/**
 * @internal
 */
759
export const CodeLensProviderRegistry = new LanguageFeatureRegistry<CodeLensProvider>();
760

761 762 763
/**
 * @internal
 */
764
export const CodeActionProviderRegistry = new LanguageFeatureRegistry<CodeActionProvider>();
765

766 767 768
/**
 * @internal
 */
769 770
export const DocumentFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentFormattingEditProvider>();

771 772 773
/**
 * @internal
 */
774
export const DocumentRangeFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentRangeFormattingEditProvider>();
775

776 777 778
/**
 * @internal
 */
779
export const OnTypeFormattingEditProviderRegistry = new LanguageFeatureRegistry<OnTypeFormattingEditProvider>();
780

781 782 783
/**
 * @internal
 */
A
Alex Dima 已提交
784
export const LinkProviderRegistry = new LanguageFeatureRegistry<LinkProvider>();
785

J
Joao Moreno 已提交
786 787 788 789 790
/**
 * @internal
 */
export const ColorProviderRegistry = new LanguageFeatureRegistry<ColorProvider>();

791 792 793 794
/**
 * @internal
 */
export interface ITokenizationSupportChangedEvent {
A
Alex Dima 已提交
795 796
	changedLanguages: string[];
	changedColorMap: boolean;
797 798 799 800 801
}

/**
 * @internal
 */
802
export interface ITokenizationRegistry {
A
Alex Dima 已提交
803 804 805 806 807 808

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

811 812 813 814
	/**
	 * Fire a change event for a language.
	 * This is useful for languages that embed other languages.
	 */
815
	fire(languages: string[]): void;
816

A
Alex Dima 已提交
817 818 819
	/**
	 * Register a tokenization support.
	 */
820
	register(language: string, support: ITokenizationSupport): IDisposable;
821

A
Alex Dima 已提交
822 823 824 825
	/**
	 * Get the tokenization support for a language.
	 * Returns null if not found.
	 */
826
	get(language: string): ITokenizationSupport;
A
Alex Dima 已提交
827

A
Alex Dima 已提交
828 829 830
	/**
	 * Set the new color map that all tokens will use in their ColorId binary encoded bits for foreground and background.
	 */
831
	setColorMap(colorMap: Color[]): void;
A
Alex Dima 已提交
832

833
	getColorMap(): Color[];
A
Alex Dima 已提交
834 835
	getDefaultForeground(): Color;
	getDefaultBackground(): Color;
836 837 838 839 840 841
}

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