modes.ts 44.7 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6 7 8
import { CancellationToken } from 'vs/base/common/cancellation';
import { Color } from 'vs/base/common/color';
import { Event } from 'vs/base/common/event';
9
import { IMarkdownString } from 'vs/base/common/htmlContent';
J
Johannes Rieken 已提交
10
import { IDisposable } from 'vs/base/common/lifecycle';
11
import { isObject } from 'vs/base/common/types';
P
Peng Lyu 已提交
12
import { URI, UriComponents } from 'vs/base/common/uri';
13 14 15
import { Position } from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
A
Tweaks  
Alex Dima 已提交
16
import { TokenizationResult, TokenizationResult2 } from 'vs/editor/common/core/token';
17
import * as model from 'vs/editor/common/model';
A
Alex Dima 已提交
18
import { LanguageFeatureRegistry } from 'vs/editor/common/modes/languageFeatureRegistry';
19
import { TokenizationRegistryImpl } from 'vs/editor/common/modes/tokenizationRegistry';
20
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
21
import { IMarkerData } from 'vs/platform/markers/common/markers';
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
 *
 * @internal
 */
export const enum MetadataConsts {
	LANGUAGEID_MASK = 0b00000000000000000000000011111111,
	TOKEN_TYPE_MASK = 0b00000000000000000000011100000000,
	FONT_STYLE_MASK = 0b00000000000000000011100000000000,
	FOREGROUND_MASK = 0b00000000011111111100000000000000,
	BACKGROUND_MASK = 0b11111111100000000000000000000000,

128 129
	LANG_TTYPE_CMPL = 0b11111111111111111111100000000000,

A
Alex Dima 已提交
130 131 132 133 134 135 136
	LANGUAGEID_OFFSET = 0,
	TOKEN_TYPE_OFFSET = 8,
	FONT_STYLE_OFFSET = 11,
	FOREGROUND_OFFSET = 14,
	BACKGROUND_OFFSET = 23
}

A
Alex Dima 已提交
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 196 197
/**
 * @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;
	}
}

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

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

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

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

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

221 222 223 224 225 226
/**
 * A provider result represents the values a provider, like the [`HoverProvider`](#HoverProvider),
 * may return. For once this is the actual result type `T`, like `Hover`, or a thenable that resolves
 * to that type `T`. In addition, `null` and `undefined` can be returned - either directly or from a
 * thenable.
 */
227
export type ProviderResult<T> = T | undefined | null | Thenable<T | undefined | null>;
228

E
Erich Gamma 已提交
229
/**
230 231
 * A hover represents additional information for a symbol or word. Hovers are
 * rendered in a tooltip-like widget.
E
Erich Gamma 已提交
232
 */
233
export interface Hover {
234 235 236
	/**
	 * The contents of this hover.
	 */
237
	contents: IMarkdownString[];
238 239 240 241 242 243

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

A
Alex Dima 已提交
247 248
/**
 * The hover provider interface defines the contract between extensions and
G
Greg Van Liew 已提交
249
 * the [hover](https://code.visualstudio.com/docs/editor/intellisense)-feature.
A
Alex Dima 已提交
250
 */
A
Alex Dima 已提交
251
export interface HoverProvider {
A
Alex Dima 已提交
252 253 254 255 256
	/**
	 * 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.
	 */
257
	provideHover(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Hover>;
E
Erich Gamma 已提交
258 259
}

260
export const enum CompletionItemKind {
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
	Method,
	Function,
	Constructor,
	Field,
	Variable,
	Class,
	Struct,
	Interface,
	Module,
	Property,
	Event,
	Operator,
	Unit,
	Value,
	Constant,
	Enum,
	EnumMember,
	Keyword,
	Text,
	Color,
	File,
	Reference,
	Customcolor,
	Folder,
	TypeParameter,
J
Johannes Rieken 已提交
286
	Snippet, // <- highest value (used for compare!)
287 288 289 290 291
}

/**
 * @internal
 */
M
Matt Bierner 已提交
292
export const completionKindToCssClass = (function () {
293
	let data = Object.create(null);
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
	data[CompletionItemKind.Method] = 'method';
	data[CompletionItemKind.Function] = 'function';
	data[CompletionItemKind.Constructor] = 'constructor';
	data[CompletionItemKind.Field] = 'field';
	data[CompletionItemKind.Variable] = 'variable';
	data[CompletionItemKind.Class] = 'class';
	data[CompletionItemKind.Struct] = 'struct';
	data[CompletionItemKind.Interface] = 'interface';
	data[CompletionItemKind.Module] = 'module';
	data[CompletionItemKind.Property] = 'property';
	data[CompletionItemKind.Event] = 'event';
	data[CompletionItemKind.Operator] = 'operator';
	data[CompletionItemKind.Unit] = 'unit';
	data[CompletionItemKind.Value] = 'value';
	data[CompletionItemKind.Constant] = 'constant';
	data[CompletionItemKind.Enum] = 'enum';
	data[CompletionItemKind.EnumMember] = 'enum-member';
	data[CompletionItemKind.Keyword] = 'keyword';
	data[CompletionItemKind.Snippet] = 'snippet';
	data[CompletionItemKind.Text] = 'text';
	data[CompletionItemKind.Color] = 'color';
	data[CompletionItemKind.File] = 'file';
	data[CompletionItemKind.Reference] = 'reference';
	data[CompletionItemKind.Customcolor] = 'customcolor';
	data[CompletionItemKind.Folder] = 'folder';
	data[CompletionItemKind.TypeParameter] = 'type-parameter';

	return function (kind: CompletionItemKind) {
322 323 324 325 326 327 328
		return data[kind] || 'property';
	};
})();

/**
 * @internal
 */
329 330 331 332
export let completionKindFromString: {
	(value: string): CompletionItemKind;
	(value: string, strict: true): CompletionItemKind | undefined;
} = (function () {
333
	let data: Record<string, CompletionItemKind> = Object.create(null);
334 335
	data['method'] = CompletionItemKind.Method;
	data['function'] = CompletionItemKind.Function;
336
	data['constructor'] = <any>CompletionItemKind.Constructor;
337 338 339 340 341 342 343 344 345 346 347 348 349 350
	data['field'] = CompletionItemKind.Field;
	data['variable'] = CompletionItemKind.Variable;
	data['class'] = CompletionItemKind.Class;
	data['struct'] = CompletionItemKind.Struct;
	data['interface'] = CompletionItemKind.Interface;
	data['module'] = CompletionItemKind.Module;
	data['property'] = CompletionItemKind.Property;
	data['event'] = CompletionItemKind.Event;
	data['operator'] = CompletionItemKind.Operator;
	data['unit'] = CompletionItemKind.Unit;
	data['value'] = CompletionItemKind.Value;
	data['constant'] = CompletionItemKind.Constant;
	data['enum'] = CompletionItemKind.Enum;
	data['enum-member'] = CompletionItemKind.EnumMember;
351
	data['enumMember'] = CompletionItemKind.EnumMember;
352 353 354 355 356 357 358 359 360
	data['keyword'] = CompletionItemKind.Keyword;
	data['snippet'] = CompletionItemKind.Snippet;
	data['text'] = CompletionItemKind.Text;
	data['color'] = CompletionItemKind.Color;
	data['file'] = CompletionItemKind.File;
	data['reference'] = CompletionItemKind.Reference;
	data['customcolor'] = CompletionItemKind.Customcolor;
	data['folder'] = CompletionItemKind.Folder;
	data['type-parameter'] = CompletionItemKind.TypeParameter;
361
	data['typeParameter'] = CompletionItemKind.TypeParameter;
362

363 364 365 366 367 368
	return function (value: string, strict?: true) {
		let res = data[value];
		if (typeof res === 'undefined' && !strict) {
			res = CompletionItemKind.Property;
		}
		return res;
369 370
	};
})();
J
Johannes Rieken 已提交
371

372
export const enum CompletionItemTag {
373 374 375
	Deprecated = 1
}

376
export const enum CompletionItemInsertTextRule {
377
	/**
378 379
	 * Adjust whitespace/indentation of multiline insert texts to
	 * match the current line indentation.
380
	 */
381
	KeepWhitespace = 0b001,
382 383

	/**
384
	 * `insertText` is a snippet.
385
	 */
386
	InsertAsSnippet = 0b100,
387 388
}

389
/**
390 391
 * A completion item represents a text snippet that is
 * proposed to complete text that is being typed.
392
 */
393
export interface CompletionItem {
394 395 396 397 398
	/**
	 * The label of this completion item. By default
	 * this is also the text that is inserted when selecting
	 * this completion.
	 */
E
Erich Gamma 已提交
399
	label: string;
400 401 402 403 404
	/**
	 * The kind of this completion item. Based on the kind
	 * an icon is chosen by the editor.
	 */
	kind: CompletionItemKind;
405
	/**
406 407
	 * A modifier to the `kind` which affect how the item
	 * is rendered, e.g. Deprecated is rendered with a strikeout
408
	 */
409
	tags?: ReadonlyArray<CompletionItemTag>;
410 411 412 413
	/**
	 * A human-readable string with additional information
	 * about this item, like type or symbol information.
	 */
414
	detail?: string;
415 416 417
	/**
	 * A human-readable string that represents a doc-comment.
	 */
418
	documentation?: string | IMarkdownString;
419 420 421 422 423
	/**
	 * A string that should be used when comparing this item
	 * with other items. When `falsy` the [label](#CompletionItem.label)
	 * is used.
	 */
E
Erich Gamma 已提交
424
	sortText?: string;
425 426 427 428 429
	/**
	 * A string that should be used when filtering a set of
	 * completion items. When `falsy` the [label](#CompletionItem.label)
	 * is used.
	 */
430
	filterText?: string;
J
Johannes Rieken 已提交
431 432 433 434 435
	/**
	 * Select this item when showing. *Note* that only one completion item can be selected and
	 * that the editor decides which item that is. The rule is that the *first* item of those
	 * that match best is selected.
	 */
436
	preselect?: boolean;
437 438
	/**
	 * A string or snippet that should be inserted in a document when selecting
439
	 * this completion. When `falsy` the [label](#CompletionItem.label)
440 441
	 * is used.
	 */
442
	insertText: string;
443
	/**
444 445
	 * Addition rules (as bitmask) that should be applied when inserting
	 * this completion.
446
	 */
447
	insertTextRules?: CompletionItemInsertTextRule;
448 449 450 451 452 453 454 455 456
	/**
	 * A range of text that should be replaced by this completion item.
	 *
	 * Defaults to a range from the start of the [current word](#TextDocument.getWordRangeAtPosition) to the
	 * current position.
	 *
	 * *Note:* The range must be a [single line](#Range.isSingleLine) and it must
	 * [contain](#Range.contains) the position at which completion has been [requested](#CompletionItemProvider.provideCompletionItems).
	 */
J
Johannes Rieken 已提交
457
	range: IRange | { insert: IRange, replace: IRange };
458 459 460 461 462
	/**
	 * An optional set of characters that when pressed while this completion is active will accept it first and
	 * then type that character. *Note* that all commit characters should have `length=1` and that superfluous
	 * characters will be ignored.
	 */
463
	commitCharacters?: string[];
464 465 466 467 468
	/**
	 * An optional array of additional text edits that are applied when
	 * selecting this completion. Edits must not overlap with the main edit
	 * nor with themselves.
	 */
469
	additionalTextEdits?: model.ISingleEditOperation[];
470 471 472
	/**
	 * A command that should be run upon acceptance of this item.
	 */
473
	command?: Command;
J
Johannes Rieken 已提交
474 475 476 477

	/**
	 * @internal
	 */
478
	_id?: [number, number];
E
Erich Gamma 已提交
479 480
}

481 482
export interface CompletionList {
	suggestions: CompletionItem[];
E
Erich Gamma 已提交
483
	incomplete?: boolean;
484
	dispose?(): void;
E
Erich Gamma 已提交
485 486
}

M
Matt Bierner 已提交
487 488 489
/**
 * How a suggest provider was triggered.
 */
490
export const enum CompletionTriggerKind {
M
Matt Bierner 已提交
491
	Invoke = 0,
492 493
	TriggerCharacter = 1,
	TriggerForIncompleteCompletions = 2
M
Matt Bierner 已提交
494
}
495
/**
496 497
 * Contains additional information about the context in which
 * [completion provider](#CompletionItemProvider.provideCompletionItems) is triggered.
498
 */
499
export interface CompletionContext {
500 501 502
	/**
	 * How the completion was triggered.
	 */
503
	triggerKind: CompletionTriggerKind;
504 505 506 507 508
	/**
	 * Character that triggered the completion item provider.
	 *
	 * `undefined` if provider was not triggered by a character.
	 */
509 510
	triggerCharacter?: string;
}
511
/**
512 513 514 515 516 517 518 519 520
 * The completion item provider interface defines the contract between extensions and
 * the [IntelliSense](https://code.visualstudio.com/docs/editor/intellisense).
 *
 * When computing *complete* completion items is expensive, providers can optionally implement
 * the `resolveCompletionItem`-function. In that case it is enough to return completion
 * items with a [label](#CompletionItem.label) from the
 * [provideCompletionItems](#CompletionItemProvider.provideCompletionItems)-function. Subsequently,
 * when a completion item is shown in the UI and gains focus this provider is asked to resolve
 * the item, like adding [doc-comment](#CompletionItem.documentation) or [details](#CompletionItem.detail).
521
 */
522
export interface CompletionItemProvider {
E
Erich Gamma 已提交
523

524 525 526 527 528
	/**
	 * @internal
	 */
	_debugDisplayName?: string;

529
	triggerCharacters?: string[];
530 531 532
	/**
	 * Provide completion items for the given position and document.
	 */
533
	provideCompletionItems(model: model.ITextModel, position: Position, context: CompletionContext, token: CancellationToken): ProviderResult<CompletionList>;
E
Erich Gamma 已提交
534

535 536 537 538 539 540
	/**
	 * Given a completion item fill in more data, like [doc-comment](#CompletionItem.documentation)
	 * or [details](#CompletionItem.detail).
	 *
	 * The editor will only resolve a completion item once.
	 */
541
	resolveCompletionItem?(model: model.ITextModel, position: Position, item: CompletionItem, token: CancellationToken): ProviderResult<CompletionItem>;
E
Erich Gamma 已提交
542 543
}

544 545 546
export interface CodeAction {
	title: string;
	command?: Command;
547
	edit?: WorkspaceEdit;
548
	diagnostics?: IMarkerData[];
M
Matt Bierner 已提交
549
	kind?: string;
550
	isPreferred?: boolean;
M
Matt Bierner 已提交
551
	disabled?: string;
M
Matt Bierner 已提交
552 553
}

554 555 556
/**
 * @internal
 */
557
export const enum CodeActionTrigger {
558 559 560 561
	Automatic = 1,
	Manual = 2,
}

M
Matt Bierner 已提交
562 563 564 565 566
/**
 * @internal
 */
export interface CodeActionContext {
	only?: string;
567
	trigger: CodeActionTrigger;
568 569
}

570 571 572 573
export interface CodeActionList extends IDisposable {
	readonly actions: ReadonlyArray<CodeAction>;
}

A
Alex Dima 已提交
574 575 576
/**
 * The code action interface defines the contract between extensions and
 * the [light bulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) feature.
577
 * @internal
A
Alex Dima 已提交
578
 */
579
export interface CodeActionProvider {
A
Alex Dima 已提交
580 581 582
	/**
	 * Provide commands for the given document and range.
	 */
583
	provideCodeActions(model: model.ITextModel, range: Range | Selection, context: CodeActionContext, token: CancellationToken): ProviderResult<CodeActionList>;
584 585

	/**
586
	 * Optional list of CodeActionKinds that this provider returns.
587
	 */
588
	providedCodeActionKinds?: ReadonlyArray<string>;
E
Erich Gamma 已提交
589 590
}

A
Alex Dima 已提交
591 592 593 594
/**
 * Represents a parameter of a callable-signature. A parameter can
 * have a label and a doc-comment.
 */
595
export interface ParameterInformation {
A
Alex Dima 已提交
596 597 598 599
	/**
	 * The label of this signature. Will be shown in
	 * the UI.
	 */
600
	label: string | [number, number];
A
Alex Dima 已提交
601 602 603 604
	/**
	 * The human-readable doc-comment of this signature. Will be shown
	 * in the UI but can be omitted.
	 */
605
	documentation?: string | IMarkdownString;
E
Erich Gamma 已提交
606
}
A
Alex Dima 已提交
607 608 609 610 611
/**
 * Represents the signature of something callable. A signature
 * can have a label, like a function-name, a doc-comment, and
 * a set of parameters.
 */
612
export interface SignatureInformation {
A
Alex Dima 已提交
613 614 615 616
	/**
	 * The label of this signature. Will be shown in
	 * the UI.
	 */
617
	label: string;
A
Alex Dima 已提交
618 619 620 621
	/**
	 * The human-readable doc-comment of this signature. Will be shown
	 * in the UI but can be omitted.
	 */
622
	documentation?: string | IMarkdownString;
A
Alex Dima 已提交
623 624 625
	/**
	 * The parameters of this signature.
	 */
626
	parameters: ParameterInformation[];
E
Erich Gamma 已提交
627
}
A
Alex Dima 已提交
628 629 630 631 632
/**
 * Signature help represents the signature of something
 * callable. There can be multiple signatures but only one
 * active and only one active parameter.
 */
633
export interface SignatureHelp {
A
Alex Dima 已提交
634 635 636
	/**
	 * One or more signatures.
	 */
637
	signatures: SignatureInformation[];
A
Alex Dima 已提交
638 639 640
	/**
	 * The active signature.
	 */
641
	activeSignature: number;
A
Alex Dima 已提交
642 643 644
	/**
	 * The active parameter of the active signature.
	 */
645
	activeParameter: number;
E
Erich Gamma 已提交
646
}
647

648 649 650 651
export interface SignatureHelpResult extends IDisposable {
	value: SignatureHelp;
}

M
Matt Bierner 已提交
652
export enum SignatureHelpTriggerKind {
653 654
	Invoke = 1,
	TriggerCharacter = 2,
655
	ContentChange = 3,
656 657 658
}

export interface SignatureHelpContext {
659
	readonly triggerKind: SignatureHelpTriggerKind;
660 661
	readonly triggerCharacter?: string;
	readonly isRetrigger: boolean;
662
	readonly activeSignatureHelp?: SignatureHelp;
663 664
}

A
Alex Dima 已提交
665 666
/**
 * The signature help provider interface defines the contract between extensions and
G
Greg Van Liew 已提交
667
 * the [parameter hints](https://code.visualstudio.com/docs/editor/intellisense)-feature.
A
Alex Dima 已提交
668
 */
A
Alex Dima 已提交
669
export interface SignatureHelpProvider {
670

A
Alex Dima 已提交
671 672
	readonly signatureHelpTriggerCharacters?: ReadonlyArray<string>;
	readonly signatureHelpRetriggerCharacters?: ReadonlyArray<string>;
673

A
Alex Dima 已提交
674 675 676
	/**
	 * Provide help for the signature at the given position and document.
	 */
677
	provideSignatureHelp(model: model.ITextModel, position: Position, token: CancellationToken, context: SignatureHelpContext): ProviderResult<SignatureHelpResult>;
E
Erich Gamma 已提交
678 679
}

A
Alex Dima 已提交
680 681 682
/**
 * A document highlight kind.
 */
683
export enum DocumentHighlightKind {
A
Alex Dima 已提交
684 685 686
	/**
	 * A textual occurrence.
	 */
687
	Text,
A
Alex Dima 已提交
688 689 690
	/**
	 * Read-access of a symbol, like reading a variable.
	 */
691
	Read,
A
Alex Dima 已提交
692 693 694
	/**
	 * Write-access of a symbol, like writing to a variable.
	 */
695 696
	Write
}
A
Alex Dima 已提交
697 698 699 700 701
/**
 * 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.
 */
702
export interface DocumentHighlight {
A
Alex Dima 已提交
703 704 705
	/**
	 * The range this highlight applies to.
	 */
A
Alex Dima 已提交
706
	range: IRange;
A
Alex Dima 已提交
707 708 709
	/**
	 * The highlight kind, default is [text](#DocumentHighlightKind.Text).
	 */
710
	kind?: DocumentHighlightKind;
E
Erich Gamma 已提交
711
}
A
Alex Dima 已提交
712 713 714 715
/**
 * The document highlight provider interface defines the contract between extensions and
 * the word-highlight-feature.
 */
716
export interface DocumentHighlightProvider {
A
Alex Dima 已提交
717 718 719 720
	/**
	 * Provide a set of document highlights, like all occurrences of a variable or
	 * all exit-points of a function.
	 */
721
	provideDocumentHighlights(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<DocumentHighlight[]>;
E
Erich Gamma 已提交
722 723
}

A
Alex Dima 已提交
724 725 726 727
/**
 * Value-object that contains additional information when
 * requesting references.
 */
728
export interface ReferenceContext {
A
Alex Dima 已提交
729 730 731
	/**
	 * Include the declaration of the current symbol.
	 */
732 733
	includeDeclaration: boolean;
}
A
Alex Dima 已提交
734 735 736 737
/**
 * The reference provider interface defines the contract between extensions and
 * the [find references](https://code.visualstudio.com/docs/editor/editingevolved#_peek)-feature.
 */
738
export interface ReferenceProvider {
A
Alex Dima 已提交
739 740 741
	/**
	 * Provide a set of project-wide references for the given position and document.
	 */
742
	provideReferences(model: model.ITextModel, position: Position, context: ReferenceContext, token: CancellationToken): ProviderResult<Location[]>;
E
Erich Gamma 已提交
743 744
}

A
Alex Dima 已提交
745 746 747 748
/**
 * Represents a location inside a resource, such as a line
 * inside a text file.
 */
A
Alex Dima 已提交
749
export interface Location {
A
Alex Dima 已提交
750 751 752
	/**
	 * The resource identifier of this location.
	 */
753
	uri: URI;
A
Alex Dima 已提交
754 755 756
	/**
	 * The document range of this locations.
	 */
A
Alex Dima 已提交
757
	range: IRange;
E
Erich Gamma 已提交
758
}
759

J
Johannes Rieken 已提交
760 761 762 763 764 765 766 767 768
export interface LocationLink {
	/**
	 * A range to select where this link originates from.
	 */
	originSelectionRange?: IRange;

	/**
	 * The target uri this link points to.
	 */
M
Matt Bierner 已提交
769
	uri: URI;
J
Johannes Rieken 已提交
770 771 772 773

	/**
	 * The full range this link points to.
	 */
M
Matt Bierner 已提交
774
	range: IRange;
J
Johannes Rieken 已提交
775 776 777 778 779 780

	/**
	 * A range to select this link points to. Must be contained
	 * in `LocationLink.range`.
	 */
	targetSelectionRange?: IRange;
M
Matt Bierner 已提交
781 782
}

783 784 785
/**
 * @internal
 */
786 787 788 789 790 791 792
export function isLocationLink(thing: any): thing is LocationLink {
	return thing
		&& URI.isUri((thing as LocationLink).uri)
		&& Range.isIRange((thing as LocationLink).range)
		&& (Range.isIRange((thing as LocationLink).originSelectionRange) || Range.isIRange((thing as LocationLink).targetSelectionRange));
}

J
Johannes Rieken 已提交
793 794
export type Definition = Location | Location[] | LocationLink[];

A
Alex Dima 已提交
795 796 797 798 799
/**
 * 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.
 */
800
export interface DefinitionProvider {
A
Alex Dima 已提交
801 802 803
	/**
	 * Provide the definition of the symbol at the given position and document.
	 */
J
Johannes Rieken 已提交
804
	provideDefinition(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
805 806
}

807 808 809 810 811 812 813 814 815
/**
 * 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.
 */
export interface DeclarationProvider {
	/**
	 * Provide the declaration of the symbol at the given position and document.
	 */
J
Johannes Rieken 已提交
816
	provideDeclaration(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
817 818
}

819
/**
820
 * The implementation provider interface defines the contract between extensions and
821
 * the go to implementation feature.
822
 */
M
Matt Bierner 已提交
823
export interface ImplementationProvider {
824 825 826
	/**
	 * Provide the implementation of the symbol at the given position and document.
	 */
J
Johannes Rieken 已提交
827
	provideImplementation(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
828
}
829

830 831 832 833 834 835 836 837
/**
 * 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.
	 */
J
Johannes Rieken 已提交
838
	provideTypeDefinition(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
839 840
}

A
Alex Dima 已提交
841 842 843
/**
 * A symbol kind.
 */
844
export const enum SymbolKind {
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
	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,
867 868
	Struct = 22,
	Event = 23,
869 870
	Operator = 24,
	TypeParameter = 25
871 872
}

873
export const enum SymbolTag {
874 875
	Deprecated = 1,
}
876 877 878 879

/**
 * @internal
 */
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
export namespace SymbolKinds {

	const byName = new Map<string, SymbolKind>();
	byName.set('file', SymbolKind.File);
	byName.set('module', SymbolKind.Module);
	byName.set('namespace', SymbolKind.Namespace);
	byName.set('package', SymbolKind.Package);
	byName.set('class', SymbolKind.Class);
	byName.set('method', SymbolKind.Method);
	byName.set('property', SymbolKind.Property);
	byName.set('field', SymbolKind.Field);
	byName.set('constructor', SymbolKind.Constructor);
	byName.set('enum', SymbolKind.Enum);
	byName.set('interface', SymbolKind.Interface);
	byName.set('function', SymbolKind.Function);
	byName.set('variable', SymbolKind.Variable);
	byName.set('constant', SymbolKind.Constant);
	byName.set('string', SymbolKind.String);
	byName.set('number', SymbolKind.Number);
	byName.set('boolean', SymbolKind.Boolean);
	byName.set('array', SymbolKind.Array);
	byName.set('object', SymbolKind.Object);
	byName.set('key', SymbolKind.Key);
	byName.set('null', SymbolKind.Null);
	byName.set('enum-member', SymbolKind.EnumMember);
	byName.set('struct', SymbolKind.Struct);
	byName.set('event', SymbolKind.Event);
	byName.set('operator', SymbolKind.Operator);
	byName.set('type-parameter', SymbolKind.TypeParameter);

	const byKind = new Map<SymbolKind, string>();
	byKind.set(SymbolKind.File, 'file');
	byKind.set(SymbolKind.Module, 'module');
	byKind.set(SymbolKind.Namespace, 'namespace');
	byKind.set(SymbolKind.Package, 'package');
	byKind.set(SymbolKind.Class, 'class');
	byKind.set(SymbolKind.Method, 'method');
	byKind.set(SymbolKind.Property, 'property');
	byKind.set(SymbolKind.Field, 'field');
	byKind.set(SymbolKind.Constructor, 'constructor');
	byKind.set(SymbolKind.Enum, 'enum');
	byKind.set(SymbolKind.Interface, 'interface');
	byKind.set(SymbolKind.Function, 'function');
	byKind.set(SymbolKind.Variable, 'variable');
	byKind.set(SymbolKind.Constant, 'constant');
	byKind.set(SymbolKind.String, 'string');
	byKind.set(SymbolKind.Number, 'number');
	byKind.set(SymbolKind.Boolean, 'boolean');
	byKind.set(SymbolKind.Array, 'array');
	byKind.set(SymbolKind.Object, 'object');
	byKind.set(SymbolKind.Key, 'key');
	byKind.set(SymbolKind.Null, 'null');
	byKind.set(SymbolKind.EnumMember, 'enum-member');
	byKind.set(SymbolKind.Struct, 'struct');
	byKind.set(SymbolKind.Event, 'event');
	byKind.set(SymbolKind.Operator, 'operator');
	byKind.set(SymbolKind.TypeParameter, 'type-parameter');
	/**
	 * @internal
	 */
	export function fromString(value: string): SymbolKind | undefined {
		return byName.get(value);
	}
	/**
	 * @internal
	 */
	export function toString(kind: SymbolKind): string | undefined {
		return byKind.get(kind);
	}
	/**
	 * @internal
	 */
	export function toCssClassName(kind: SymbolKind, inline?: boolean): string {
953
		return `codicon ${inline ? 'inline' : 'block'} codicon-symbol-${byKind.get(kind) || 'property'}`;
954 955
	}
}
956

957
export interface DocumentSymbol {
958
	name: string;
959
	detail: string;
960
	kind: SymbolKind;
961
	tags: ReadonlyArray<SymbolTag>;
962
	containerName?: string;
963 964
	range: IRange;
	selectionRange: IRange;
965
	children?: DocumentSymbol[];
966
}
967

A
Alex Dima 已提交
968 969
/**
 * The document symbol provider interface defines the contract between extensions and
L
Lars Hvam 已提交
970
 * the [go to symbol](https://code.visualstudio.com/docs/editor/editingevolved#_go-to-symbol)-feature.
A
Alex Dima 已提交
971
 */
972
export interface DocumentSymbolProvider {
973

974
	displayName?: string;
975

A
Alex Dima 已提交
976 977 978
	/**
	 * Provide symbol information for the given document.
	 */
979
	provideDocumentSymbols(model: model.ITextModel, token: CancellationToken): ProviderResult<DocumentSymbol[]>;
E
Erich Gamma 已提交
980 981
}

982
export type TextEdit = { range: IRange; text: string; eol?: model.EndOfLineSequence; };
983

E
Erich Gamma 已提交
984 985 986
/**
 * Interface used to format a model
 */
A
Alex Dima 已提交
987 988 989 990
export interface FormattingOptions {
	/**
	 * Size of a tab in spaces.
	 */
J
Johannes Rieken 已提交
991
	tabSize: number;
A
Alex Dima 已提交
992 993 994
	/**
	 * Prefer spaces over tabs.
	 */
J
Johannes Rieken 已提交
995
	insertSpaces: boolean;
E
Erich Gamma 已提交
996
}
A
Alex Dima 已提交
997 998 999 1000
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
1001
export interface DocumentFormattingEditProvider {
1002

1003 1004 1005 1006
	/**
	 * @internal
	 */
	readonly extensionId?: ExtensionIdentifier;
1007

1008 1009
	readonly displayName?: string;

A
Alex Dima 已提交
1010 1011 1012
	/**
	 * Provide formatting edits for a whole document.
	 */
1013
	provideDocumentFormattingEdits(model: model.ITextModel, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]>;
1014
}
A
Alex Dima 已提交
1015 1016 1017 1018
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
1019
export interface DocumentRangeFormattingEditProvider {
1020 1021 1022 1023
	/**
	 * @internal
	 */
	readonly extensionId?: ExtensionIdentifier;
1024

1025 1026
	readonly displayName?: string;

A
Alex Dima 已提交
1027 1028 1029 1030 1031 1032 1033
	/**
	 * 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.
	 */
1034
	provideDocumentRangeFormattingEdits(model: model.ITextModel, range: Range, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]>;
1035
}
A
Alex Dima 已提交
1036 1037 1038 1039
/**
 * The document formatting provider interface defines the contract between extensions and
 * the formatting-feature.
 */
1040
export interface OnTypeFormattingEditProvider {
1041 1042 1043 1044 1045 1046 1047


	/**
	 * @internal
	 */
	readonly extensionId?: ExtensionIdentifier;

1048
	autoFormatTriggerCharacters: string[];
1049

A
Alex Dima 已提交
1050 1051 1052 1053 1054 1055 1056
	/**
	 * 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.
	 */
1057
	provideOnTypeFormattingEdits(model: model.ITextModel, position: Position, ch: string, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]>;
E
Erich Gamma 已提交
1058 1059
}

1060 1061 1062
/**
 * @internal
 */
E
Erich Gamma 已提交
1063 1064
export interface IInplaceReplaceSupportResult {
	value: string;
A
Alex Dima 已提交
1065
	range: IRange;
E
Erich Gamma 已提交
1066 1067
}

A
Alex Dima 已提交
1068 1069 1070
/**
 * A link inside the editor.
 */
1071
export interface ILink {
A
Alex Dima 已提交
1072
	range: IRange;
M
Martin Aeschlimann 已提交
1073
	url?: URI | string;
1074
	tooltip?: string;
E
Erich Gamma 已提交
1075
}
1076 1077 1078 1079 1080

export interface ILinksList {
	links: ILink[];
	dispose?(): void;
}
A
Alex Dima 已提交
1081 1082 1083
/**
 * A provider of links.
 */
A
Alex Dima 已提交
1084
export interface LinkProvider {
1085
	provideLinks(model: model.ITextModel, token: CancellationToken): ProviderResult<ILinksList>;
1086
	resolveLink?: (link: ILink, token: CancellationToken) => ProviderResult<ILink>;
E
Erich Gamma 已提交
1087 1088
}

J
Joao Moreno 已提交
1089
/**
J
Joao Moreno 已提交
1090
 * A color in RGBA format.
J
Joao Moreno 已提交
1091
 */
J
Joao Moreno 已提交
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
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;
}

1115
/**
1116
 * String representations for a color
1117
 */
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134
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 已提交
1135
}
J
Joao Moreno 已提交
1136 1137 1138 1139

/**
 * A color range is a range in a text model which represents a color.
 */
1140
export interface IColorInformation {
J
Joao Moreno 已提交
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150

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

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

J
Joao Moreno 已提交
1153
/**
J
Joao Moreno 已提交
1154
 * A provider of colors for editor models.
J
Joao Moreno 已提交
1155
 */
R
rebornix 已提交
1156
export interface DocumentColorProvider {
J
Joao Moreno 已提交
1157 1158 1159
	/**
	 * Provides the color ranges for a specific model.
	 */
1160
	provideDocumentColors(model: model.ITextModel, token: CancellationToken): ProviderResult<IColorInformation[]>;
1161
	/**
1162
	 * Provide the string representations for a color.
1163
	 */
1164
	provideColorPresentations(model: model.ITextModel, colorInfo: IColorInformation, token: CancellationToken): ProviderResult<IColorPresentation[]>;
J
Joao Moreno 已提交
1165
}
1166

1167 1168 1169 1170
export interface SelectionRange {
	range: IRange;
}

1171 1172 1173 1174
export interface SelectionRangeProvider {
	/**
	 * Provide ranges that should be selected from the given position.
	 */
1175
	provideSelectionRanges(model: model.ITextModel, positions: Position[], token: CancellationToken): ProviderResult<SelectionRange[][]>;
1176 1177
}

1178 1179
export interface FoldingContext {
}
1180 1181 1182
/**
 * A provider of colors for editor models.
 */
1183
export interface FoldingRangeProvider {
1184 1185 1186
	/**
	 * Provides the color ranges for a specific model.
	 */
1187
	provideFoldingRanges(model: model.ITextModel, context: FoldingContext, token: CancellationToken): ProviderResult<FoldingRange[]>;
1188 1189
}

1190
export interface FoldingRange {
1191 1192

	/**
1193
	 * The one-based start line of the range to fold. The folded area starts after the line's last character.
1194
	 */
1195
	start: number;
1196 1197

	/**
1198
	 * The one-based end line of the range to fold. The folded area ends with the line's last character.
1199
	 */
1200
	end: number;
1201 1202

	/**
1203 1204 1205 1206
	 * 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.
1207
	 */
1208
	kind?: FoldingRangeKind;
1209
}
1210
export class FoldingRangeKind {
1211
	/**
1212
	 * Kind for folding range representing a comment. The value of the kind is 'comment'.
1213
	 */
1214
	static readonly Comment = new FoldingRangeKind('comment');
1215
	/**
1216
	 * Kind for folding range representing a import. The value of the kind is 'imports'.
1217
	 */
1218
	static readonly Imports = new FoldingRangeKind('imports');
1219
	/**
1220 1221
	 * Kind for folding range representing regions (for example marked by `#region`, `#endregion`).
	 * The value of the kind is 'region'.
1222
	 */
1223 1224
	static readonly Region = new FoldingRangeKind('region');

1225
	/**
1226 1227 1228
	 * Creates a new [FoldingRangeKind](#FoldingRangeKind).
	 *
	 * @param value of the kind.
1229
	 */
1230 1231
	public constructor(public value: string) {
	}
1232 1233
}

1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245
/**
 * @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 已提交
1246
}
1247

1248
export interface ResourceFileEdit {
1249 1250 1251
	oldUri?: URI;
	newUri?: URI;
	options?: { overwrite?: boolean, ignoreIfNotExists?: boolean, ignoreIfExists?: boolean, recursive?: boolean };
1252 1253
}

1254
export interface ResourceTextEdit {
E
Erich Gamma 已提交
1255
	resource: URI;
1256 1257
	modelVersionId?: number;
	edits: TextEdit[];
E
Erich Gamma 已提交
1258
}
1259

1260
export interface WorkspaceEdit {
M
Matt Bierner 已提交
1261
	edits: Array<ResourceTextEdit | ResourceFileEdit>;
E
Erich Gamma 已提交
1262
}
1263

1264
export interface Rejection {
1265
	rejectReason?: string;
1266
}
1267 1268 1269 1270 1271
export interface RenameLocation {
	range: IRange;
	text: string;
}

1272
export interface RenameProvider {
1273
	provideRenameEdits(model: model.ITextModel, position: Position, newName: string, token: CancellationToken): ProviderResult<WorkspaceEdit & Rejection>;
1274
	resolveRenameLocation?(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<RenameLocation & Rejection>;
E
Erich Gamma 已提交
1275 1276
}

1277

A
Alex Dima 已提交
1278
export interface Command {
E
Erich Gamma 已提交
1279 1280
	id: string;
	title: string;
1281
	tooltip?: string;
E
Erich Gamma 已提交
1282 1283
	arguments?: any[];
}
M
Matt Bierner 已提交
1284

P
Peng Lyu 已提交
1285 1286 1287 1288
/**
 * @internal
 */
export interface CommentThreadTemplate {
P
Peng Lyu 已提交
1289
	controllerHandle: number;
P
Peng Lyu 已提交
1290 1291 1292 1293 1294 1295
	label: string;
	acceptInputCommand?: Command;
	additionalCommands?: Command[];
	deleteCommand?: Command;
}

A
Alex Dima 已提交
1296 1297 1298
/**
 * @internal
 */
1299
export interface CommentInfo {
1300
	extensionId?: string;
1301
	threads: CommentThread[];
1302
	commentingRanges: CommentingRanges;
1303
}
M
Matt Bierner 已提交
1304

A
Alex Dima 已提交
1305 1306 1307
/**
 * @internal
 */
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318
export enum CommentThreadCollapsibleState {
	/**
	 * Determines an item is collapsed
	 */
	Collapsed = 0,
	/**
	 * Determines an item is expanded
	 */
	Expanded = 1
}

1319 1320 1321 1322 1323 1324 1325 1326 1327


/**
 * @internal
 */
export interface CommentWidget {
	commentThread: CommentThread;
	comment?: Comment;
	input: string;
P
Peng Lyu 已提交
1328 1329 1330 1331 1332 1333
	onDidChangeInput: Event<string>;
}

/**
 * @internal
 */
1334 1335 1336 1337
export interface CommentInput {
	value: string;
	uri: URI;
}
P
Peng Lyu 已提交
1338

1339 1340 1341
/**
 * @internal
 */
1342
export interface CommentThread {
R
rebornix 已提交
1343
	commentThreadHandle: number;
P
Peng Lyu 已提交
1344
	controllerHandle: number;
1345
	extensionId?: string;
1346
	threadId: string;
M
Matt Bierner 已提交
1347
	resource: string | null;
P
Peng Lyu 已提交
1348
	range: IRange;
1349
	label: string | undefined;
P
Peng Lyu 已提交
1350
	contextValue: string | undefined;
1351 1352
	comments: Comment[] | undefined;
	onDidChangeComments: Event<Comment[] | undefined>;
P
Peng Lyu 已提交
1353
	collapsibleState?: CommentThreadCollapsibleState;
M
Matt Bierner 已提交
1354
	input?: CommentInput;
1355
	onDidChangeInput: Event<CommentInput | undefined>;
P
Peng Lyu 已提交
1356
	onDidChangeRange: Event<IRange>;
1357
	onDidChangeLabel: Event<string | undefined>;
1358
	onDidChangeCollasibleState: Event<CommentThreadCollapsibleState | undefined>;
P
Peng Lyu 已提交
1359
	isDisposed: boolean;
1360 1361
}

P
Peng Lyu 已提交
1362 1363 1364 1365 1366 1367 1368
/**
 * @internal
 */

export interface CommentingRanges {
	readonly resource: URI;
	ranges: IRange[];
P
Peng Lyu 已提交
1369 1370
}

P
Peng Lyu 已提交
1371 1372 1373 1374 1375
/**
 * @internal
 */
export interface CommentReaction {
	readonly label?: string;
P
Peng Lyu 已提交
1376 1377
	readonly iconPath?: UriComponents;
	readonly count?: number;
P
Peng Lyu 已提交
1378
	readonly hasReacted?: boolean;
1379
	readonly canEdit?: boolean;
P
Peng Lyu 已提交
1380 1381
}

P
Peng Lyu 已提交
1382 1383 1384 1385 1386 1387 1388 1389
/**
 * @internal
 */
export enum CommentMode {
	Editing = 0,
	Preview = 1
}

A
Alex Dima 已提交
1390 1391 1392
/**
 * @internal
 */
M
Matt Bierner 已提交
1393
export interface Comment {
P
Peng Lyu 已提交
1394
	readonly uniqueIdInThread: number;
M
Matt Bierner 已提交
1395 1396
	readonly body: IMarkdownString;
	readonly userName: string;
1397
	readonly userIconPath?: string;
P
Peng Lyu 已提交
1398
	readonly contextValue?: string;
P
Peng Lyu 已提交
1399
	readonly commentReactions?: CommentReaction[];
1400
	readonly label?: string;
P
Peng Lyu 已提交
1401
	readonly mode?: CommentMode;
M
Matt Bierner 已提交
1402 1403
}

A
Alex Dima 已提交
1404 1405 1406
/**
 * @internal
 */
1407 1408 1409 1410
export interface CommentThreadChangedEvent {
	/**
	 * Added comment threads.
	 */
1411
	readonly added: CommentThread[];
1412 1413 1414 1415

	/**
	 * Removed comment threads.
	 */
1416
	readonly removed: CommentThread[];
1417 1418 1419 1420

	/**
	 * Changed comment threads.
	 */
1421
	readonly changed: CommentThread[];
M
Matt Bierner 已提交
1422 1423
}

1424 1425 1426 1427 1428 1429 1430 1431
/**
 * @internal
 */
export interface IWebviewPortMapping {
	webviewPort: number;
	extensionHostPort: number;
}

1432 1433 1434 1435 1436 1437 1438
/**
 * @internal
 */
export interface IWebviewOptions {
	readonly enableScripts?: boolean;
	readonly enableCommandUris?: boolean;
	readonly localResourceRoots?: ReadonlyArray<URI>;
1439
	readonly portMapping?: ReadonlyArray<IWebviewPortMapping>;
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449
}

/**
 * @internal
 */
export interface IWebviewPanelOptions {
	readonly enableFindWidget?: boolean;
	readonly retainContextWhenHidden?: boolean;
}

R
rebornix 已提交
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500
/**
 * @internal
 */

export interface INotebookSelectors {
	readonly filenamePattern?: string;
}

/**
 * @internal
 */
export interface IStreamOutput {
	output_type: 'stream';
	text: string;
}

/**
 * @internal
 */
export interface IErrorOutput {
	output_type: 'error';
	evalue: string;
	traceback: string[];
}

/**
 * @internal
 */
export interface IDisplayOutput {
	output_type: 'display_data';
	data: { string: string };
}

/**
 * @internal
 */
export interface IGenericOutput {
	output_type: string;
}

/**
 * @internal
 */
export type IOutput = IStreamOutput | any;

/**
 * @internal
 */
export interface ICell {
	handle: number;
	source: string[];
R
rebornix 已提交
1501
	language: string;
R
rebornix 已提交
1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525
	cell_type: 'markdown' | 'code';
	outputs: IOutput[];
	onDidChangeOutputs?: Event<void>;
}

/**
 * @internal
 */
export interface LanguageInfo {
	file_extension: string;
}

/**
 * @internal
 */
export interface IMetadata {
	language_info: LanguageInfo;
}

/**
 * @internal
 */
export interface INotebook {
	handle: number;
R
rebornix 已提交
1526
	// metadata: IMetadata;
R
rebornix 已提交
1527
	readonly uri: URI;
R
rebornix 已提交
1528 1529
	cells: ICell[];
	onDidChangeCells?: Event<void>;
R
rebornix 已提交
1530
	onWillDispose(listener: () => void): IDisposable;
R
rebornix 已提交
1531
}
1532

1533
export interface CodeLens {
A
Alex Dima 已提交
1534
	range: IRange;
E
Erich Gamma 已提交
1535
	id?: string;
A
Alex Dima 已提交
1536
	command?: Command;
E
Erich Gamma 已提交
1537
}
1538 1539 1540 1541 1542 1543

export interface CodeLensList {
	lenses: CodeLens[];
	dispose(): void;
}

1544
export interface CodeLensProvider {
1545
	onDidChange?: Event<this>;
1546 1547
	provideCodeLenses(model: model.ITextModel, token: CancellationToken): ProviderResult<CodeLensList>;
	resolveCodeLens?(model: model.ITextModel, codeLens: CodeLens, token: CancellationToken): ProviderResult<CodeLens>;
E
Erich Gamma 已提交
1548 1549
}

1550
export interface SemanticTokensLegend {
A
wip  
Alexandru Dima 已提交
1551 1552 1553 1554
	readonly tokenTypes: string[];
	readonly tokenModifiers: string[];
}

1555 1556
export interface SemanticTokens {
	readonly resultId?: string;
A
wip  
Alexandru Dima 已提交
1557
	readonly data: Uint32Array;
1558
}
A
wip  
Alexandru Dima 已提交
1559

1560 1561 1562 1563
export interface SemanticTokensEdit {
	readonly start: number;
	readonly deleteCount: number;
	readonly data?: Uint32Array;
A
wip  
Alexandru Dima 已提交
1564 1565
}

1566 1567 1568
export interface SemanticTokensEdits {
	readonly resultId?: string;
	readonly edits: SemanticTokensEdit[];
A
wip  
Alexandru Dima 已提交
1569 1570
}

1571 1572 1573 1574
export interface SemanticTokensProvider {
	getLegend(): SemanticTokensLegend;
	provideSemanticTokens(model: model.ITextModel, lastResultId: string | null, ranges: Range[] | null, token: CancellationToken): ProviderResult<SemanticTokens | SemanticTokensEdits>;
	releaseSemanticTokens(resultId: string | undefined): void;
A
wip  
Alexandru Dima 已提交
1575 1576
}

1577 1578
// --- feature registries ------

1579 1580 1581
/**
 * @internal
 */
1582
export const ReferenceProviderRegistry = new LanguageFeatureRegistry<ReferenceProvider>();
1583

1584 1585 1586
/**
 * @internal
 */
1587
export const RenameProviderRegistry = new LanguageFeatureRegistry<RenameProvider>();
1588

1589 1590 1591
/**
 * @internal
 */
1592
export const CompletionProviderRegistry = new LanguageFeatureRegistry<CompletionItemProvider>();
1593

1594 1595 1596
/**
 * @internal
 */
1597
export const SignatureHelpProviderRegistry = new LanguageFeatureRegistry<SignatureHelpProvider>();
1598

1599 1600 1601
/**
 * @internal
 */
1602
export const HoverProviderRegistry = new LanguageFeatureRegistry<HoverProvider>();
1603

1604 1605 1606
/**
 * @internal
 */
1607
export const DocumentSymbolProviderRegistry = new LanguageFeatureRegistry<DocumentSymbolProvider>();
1608

1609 1610 1611
/**
 * @internal
 */
1612
export const DocumentHighlightProviderRegistry = new LanguageFeatureRegistry<DocumentHighlightProvider>();
1613

1614 1615 1616
/**
 * @internal
 */
1617
export const DefinitionProviderRegistry = new LanguageFeatureRegistry<DefinitionProvider>();
1618

1619 1620 1621 1622 1623
/**
 * @internal
 */
export const DeclarationProviderRegistry = new LanguageFeatureRegistry<DeclarationProvider>();

1624 1625 1626
/**
 * @internal
 */
M
Matt Bierner 已提交
1627
export const ImplementationProviderRegistry = new LanguageFeatureRegistry<ImplementationProvider>();
1628

1629 1630 1631 1632 1633
/**
 * @internal
 */
export const TypeDefinitionProviderRegistry = new LanguageFeatureRegistry<TypeDefinitionProvider>();

1634 1635 1636
/**
 * @internal
 */
1637
export const CodeLensProviderRegistry = new LanguageFeatureRegistry<CodeLensProvider>();
1638

1639 1640 1641
/**
 * @internal
 */
1642
export const CodeActionProviderRegistry = new LanguageFeatureRegistry<CodeActionProvider>();
1643

1644 1645 1646
/**
 * @internal
 */
1647 1648
export const DocumentFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentFormattingEditProvider>();

1649 1650 1651
/**
 * @internal
 */
1652
export const DocumentRangeFormattingEditProviderRegistry = new LanguageFeatureRegistry<DocumentRangeFormattingEditProvider>();
1653

1654 1655 1656
/**
 * @internal
 */
1657
export const OnTypeFormattingEditProviderRegistry = new LanguageFeatureRegistry<OnTypeFormattingEditProvider>();
1658

1659 1660 1661
/**
 * @internal
 */
A
Alex Dima 已提交
1662
export const LinkProviderRegistry = new LanguageFeatureRegistry<LinkProvider>();
1663

J
Joao Moreno 已提交
1664 1665 1666
/**
 * @internal
 */
R
rebornix 已提交
1667
export const ColorProviderRegistry = new LanguageFeatureRegistry<DocumentColorProvider>();
J
Joao Moreno 已提交
1668

1669 1670 1671 1672 1673
/**
 * @internal
 */
export const SelectionRangeRegistry = new LanguageFeatureRegistry<SelectionRangeProvider>();

1674 1675 1676
/**
 * @internal
 */
1677
export const FoldingRangeProviderRegistry = new LanguageFeatureRegistry<FoldingRangeProvider>();
1678

A
wip  
Alexandru Dima 已提交
1679 1680 1681
/**
 * @internal
 */
1682
export const SemanticTokensProviderRegistry = new LanguageFeatureRegistry<SemanticTokensProvider>();
A
wip  
Alexandru Dima 已提交
1683

1684 1685 1686 1687
/**
 * @internal
 */
export interface ITokenizationSupportChangedEvent {
A
Alex Dima 已提交
1688 1689
	changedLanguages: string[];
	changedColorMap: boolean;
1690 1691 1692 1693 1694
}

/**
 * @internal
 */
1695
export interface ITokenizationRegistry {
A
Alex Dima 已提交
1696 1697 1698 1699 1700 1701

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

1704 1705 1706 1707
	/**
	 * Fire a change event for a language.
	 * This is useful for languages that embed other languages.
	 */
1708
	fire(languages: string[]): void;
1709

A
Alex Dima 已提交
1710 1711 1712
	/**
	 * Register a tokenization support.
	 */
1713
	register(language: string, support: ITokenizationSupport): IDisposable;
1714

1715 1716 1717
	/**
	 * Register a promise for a tokenization support.
	 */
1718
	registerPromise(language: string, promise: Thenable<ITokenizationSupport>): IDisposable;
1719

A
Alex Dima 已提交
1720 1721
	/**
	 * Get the tokenization support for a language.
1722
	 * Returns `null` if not found.
A
Alex Dima 已提交
1723
	 */
1724
	get(language: string): ITokenizationSupport | null;
A
Alex Dima 已提交
1725

1726 1727 1728 1729
	/**
	 * Get the promise of a tokenization support for a language.
	 * `null` is returned if no support is available and no promise for the support has been registered yet.
	 */
1730
	getPromise(language: string): Thenable<ITokenizationSupport> | null;
1731

A
Alex Dima 已提交
1732 1733 1734
	/**
	 * Set the new color map that all tokens will use in their ColorId binary encoded bits for foreground and background.
	 */
1735
	setColorMap(colorMap: Color[]): void;
A
Alex Dima 已提交
1736

A
Alex Dima 已提交
1737
	getColorMap(): Color[] | null;
A
Alex Dima 已提交
1738

A
Alex Dima 已提交
1739
	getDefaultBackground(): Color | null;
1740 1741 1742 1743 1744 1745
}

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