extHostTypes.ts 68.9 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
import { coalesceInPlace, equals } from 'vs/base/common/arrays';
M
Matt Bierner 已提交
7
import { escapeCodicons } from 'vs/base/common/codicons';
8
import { illegalArgument } from 'vs/base/common/errors';
9
import { IRelativePattern } from 'vs/base/common/glob';
10
import { isMarkdownString } from 'vs/base/common/htmlContent';
11
import { ResourceMap } from 'vs/base/common/map';
M
Matt Bierner 已提交
12
import { isStringArray } from 'vs/base/common/types';
13
import { URI } from 'vs/base/common/uri';
14
import { generateUuid } from 'vs/base/common/uuid';
15
import { FileSystemProviderErrorCode, markAsFileSystemProviderError } from 'vs/platform/files/common/files';
A
Tweaks  
Alex Dima 已提交
16
import { RemoteAuthorityResolverErrorCode } from 'vs/platform/remote/common/remoteAuthorityResolver';
17
import { addIdToOutput, CellEditType, ICellEditOperation } from 'vs/workbench/contrib/notebook/common/notebookCommon';
M
Matt Bierner 已提交
18
import type * as vscode from 'vscode';
E
Erich Gamma 已提交
19

J
Johannes Rieken 已提交
20
function es5ClassCompat(target: Function): any {
21
	///@ts-expect-error
J
Johannes Rieken 已提交
22
	function _() { return Reflect.construct(target, arguments, this.constructor); }
J
Johannes Rieken 已提交
23
	Object.defineProperty(_, 'name', Object.getOwnPropertyDescriptor(target, 'name')!);
J
Johannes Rieken 已提交
24 25 26 27 28 29
	Object.setPrototypeOf(_, target);
	Object.setPrototypeOf(_.prototype, target.prototype);
	return _;
}

@es5ClassCompat
E
Erich Gamma 已提交
30 31
export class Disposable {

32 33
	static from(...inDisposables: { dispose(): any; }[]): Disposable {
		let disposables: ReadonlyArray<{ dispose(): any; }> | undefined = inDisposables;
E
Erich Gamma 已提交
34 35
		return new Disposable(function () {
			if (disposables) {
36
				for (const disposable of disposables) {
E
Erich Gamma 已提交
37 38 39 40 41 42 43 44 45
					if (disposable && typeof disposable.dispose === 'function') {
						disposable.dispose();
					}
				}
				disposables = undefined;
			}
		});
	}

46
	#callOnDispose?: () => any;
E
Erich Gamma 已提交
47

48
	constructor(callOnDispose: () => any) {
49
		this.#callOnDispose = callOnDispose;
E
Erich Gamma 已提交
50 51 52
	}

	dispose(): any {
53 54 55
		if (typeof this.#callOnDispose === 'function') {
			this.#callOnDispose();
			this.#callOnDispose = undefined;
E
Erich Gamma 已提交
56 57 58 59
		}
	}
}

J
Johannes Rieken 已提交
60
@es5ClassCompat
E
Erich Gamma 已提交
61 62 63
export class Position {

	static Min(...positions: Position[]): Position {
64 65 66 67 68
		if (positions.length === 0) {
			throw new TypeError();
		}
		let result = positions[0];
		for (let i = 1; i < positions.length; i++) {
69
			const p = positions[i];
70
			if (p.isBefore(result!)) {
E
Erich Gamma 已提交
71 72 73 74 75 76 77
				result = p;
			}
		}
		return result;
	}

	static Max(...positions: Position[]): Position {
78 79 80 81 82
		if (positions.length === 0) {
			throw new TypeError();
		}
		let result = positions[0];
		for (let i = 1; i < positions.length; i++) {
83
			const p = positions[i];
84
			if (p.isAfter(result!)) {
E
Erich Gamma 已提交
85 86 87 88 89 90
				result = p;
			}
		}
		return result;
	}

91
	static isPosition(other: any): other is Position {
92 93 94 95 96 97
		if (!other) {
			return false;
		}
		if (other instanceof Position) {
			return true;
		}
98
		let { line, character } = <Position>other;
99 100 101 102 103 104
		if (typeof line === 'number' && typeof character === 'number') {
			return true;
		}
		return false;
	}

E
Erich Gamma 已提交
105 106 107 108 109 110 111 112 113 114 115 116 117
	private _line: number;
	private _character: number;

	get line(): number {
		return this._line;
	}

	get character(): number {
		return this._character;
	}

	constructor(line: number, character: number) {
		if (line < 0) {
M
Manzur Khan Sarguru 已提交
118
			throw illegalArgument('line must be non-negative');
E
Erich Gamma 已提交
119 120
		}
		if (character < 0) {
M
Manzur Khan Sarguru 已提交
121
			throw illegalArgument('character must be non-negative');
E
Erich Gamma 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
		}
		this._line = line;
		this._character = character;
	}

	isBefore(other: Position): boolean {
		if (this._line < other._line) {
			return true;
		}
		if (other._line < this._line) {
			return false;
		}
		return this._character < other._character;
	}

	isBeforeOrEqual(other: Position): boolean {
		if (this._line < other._line) {
			return true;
		}
		if (other._line < this._line) {
			return false;
		}
		return this._character <= other._character;
	}

	isAfter(other: Position): boolean {
		return !this.isBeforeOrEqual(other);
	}

	isAfterOrEqual(other: Position): boolean {
		return !this.isBefore(other);
	}

	isEqual(other: Position): boolean {
		return this._line === other._line && this._character === other._character;
	}

	compareTo(other: Position): number {
		if (this._line < other._line) {
			return -1;
		} else if (this._line > other.line) {
			return 1;
		} else {
			// equal line
			if (this._character < other._character) {
				return -1;
			} else if (this._character > other._character) {
				return 1;
			} else {
				// equal line and character
				return 0;
			}
		}
	}

177
	translate(change: { lineDelta?: number; characterDelta?: number; }): Position;
178
	translate(lineDelta?: number, characterDelta?: number): Position;
179
	translate(lineDeltaOrChange: number | undefined | { lineDelta?: number; characterDelta?: number; }, characterDelta: number = 0): Position {
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

		if (lineDeltaOrChange === null || characterDelta === null) {
			throw illegalArgument();
		}

		let lineDelta: number;
		if (typeof lineDeltaOrChange === 'undefined') {
			lineDelta = 0;
		} else if (typeof lineDeltaOrChange === 'number') {
			lineDelta = lineDeltaOrChange;
		} else {
			lineDelta = typeof lineDeltaOrChange.lineDelta === 'number' ? lineDeltaOrChange.lineDelta : 0;
			characterDelta = typeof lineDeltaOrChange.characterDelta === 'number' ? lineDeltaOrChange.characterDelta : 0;
		}

E
Erich Gamma 已提交
195 196 197 198 199 200
		if (lineDelta === 0 && characterDelta === 0) {
			return this;
		}
		return new Position(this.line + lineDelta, this.character + characterDelta);
	}

201 202
	with(change: { line?: number; character?: number; }): Position;
	with(line?: number, character?: number): Position;
203
	with(lineOrChange: number | undefined | { line?: number; character?: number; }, character: number = this.character): Position {
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220

		if (lineOrChange === null || character === null) {
			throw illegalArgument();
		}

		let line: number;
		if (typeof lineOrChange === 'undefined') {
			line = this.line;

		} else if (typeof lineOrChange === 'number') {
			line = lineOrChange;

		} else {
			line = typeof lineOrChange.line === 'number' ? lineOrChange.line : this.line;
			character = typeof lineOrChange.character === 'number' ? lineOrChange.character : this.character;
		}

E
Erich Gamma 已提交
221 222 223 224 225
		if (line === this.line && character === this.character) {
			return this;
		}
		return new Position(line, character);
	}
226 227

	toJSON(): any {
J
Johannes Rieken 已提交
228
		return { line: this.line, character: this.character };
229
	}
E
Erich Gamma 已提交
230 231
}

J
Johannes Rieken 已提交
232
@es5ClassCompat
E
Erich Gamma 已提交
233 234
export class Range {

235
	static isRange(thing: any): thing is vscode.Range {
J
Johannes Rieken 已提交
236 237 238 239 240 241
		if (thing instanceof Range) {
			return true;
		}
		if (!thing) {
			return false;
		}
242 243
		return Position.isPosition((<Range>thing).start)
			&& Position.isPosition((<Range>thing.end));
J
Johannes Rieken 已提交
244 245
	}

E
Erich Gamma 已提交
246 247 248 249 250 251 252 253 254 255 256 257
	protected _start: Position;
	protected _end: Position;

	get start(): Position {
		return this._start;
	}

	get end(): Position {
		return this._end;
	}

	constructor(start: Position, end: Position);
J
Johannes Rieken 已提交
258
	constructor(startLine: number, startColumn: number, endLine: number, endColumn: number);
259
	constructor(startLineOrStart: number | Position, startColumnOrEnd: number | Position, endLine?: number, endColumn?: number) {
260 261
		let start: Position | undefined;
		let end: Position | undefined;
E
Erich Gamma 已提交
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304

		if (typeof startLineOrStart === 'number' && typeof startColumnOrEnd === 'number' && typeof endLine === 'number' && typeof endColumn === 'number') {
			start = new Position(startLineOrStart, startColumnOrEnd);
			end = new Position(endLine, endColumn);
		} else if (startLineOrStart instanceof Position && startColumnOrEnd instanceof Position) {
			start = startLineOrStart;
			end = startColumnOrEnd;
		}

		if (!start || !end) {
			throw new Error('Invalid arguments');
		}

		if (start.isBefore(end)) {
			this._start = start;
			this._end = end;
		} else {
			this._start = end;
			this._end = start;
		}
	}

	contains(positionOrRange: Position | Range): boolean {
		if (positionOrRange instanceof Range) {
			return this.contains(positionOrRange._start)
				&& this.contains(positionOrRange._end);

		} else if (positionOrRange instanceof Position) {
			if (positionOrRange.isBefore(this._start)) {
				return false;
			}
			if (this._end.isBefore(positionOrRange)) {
				return false;
			}
			return true;
		}
		return false;
	}

	isEqual(other: Range): boolean {
		return this._start.isEqual(other._start) && this._end.isEqual(other._end);
	}

305
	intersection(other: Range): Range | undefined {
306 307
		const start = Position.Max(other.start, this._start);
		const end = Position.Min(other.end, this._end);
E
Erich Gamma 已提交
308 309 310 311
		if (start.isAfter(end)) {
			// this happens when there is no overlap:
			// |-----|
			//          |----|
M
Matt Bierner 已提交
312
			return undefined;
E
Erich Gamma 已提交
313 314 315 316 317 318 319 320 321 322
		}
		return new Range(start, end);
	}

	union(other: Range): Range {
		if (this.contains(other)) {
			return this;
		} else if (other.contains(this)) {
			return other;
		}
323 324
		const start = Position.Min(other.start, this._start);
		const end = Position.Max(other.end, this.end);
E
Erich Gamma 已提交
325 326 327 328 329 330 331 332 333 334 335
		return new Range(start, end);
	}

	get isEmpty(): boolean {
		return this._start.isEqual(this._end);
	}

	get isSingleLine(): boolean {
		return this._start.line === this._end.line;
	}

336
	with(change: { start?: Position, end?: Position; }): Range;
337
	with(start?: Position, end?: Position): Range;
338
	with(startOrChange: Position | undefined | { start?: Position, end?: Position; }, end: Position = this.end): Range {
339 340 341 342 343 344 345 346 347

		if (startOrChange === null || end === null) {
			throw illegalArgument();
		}

		let start: Position;
		if (!startOrChange) {
			start = this.start;

348
		} else if (Position.isPosition(startOrChange)) {
349 350 351 352 353 354 355
			start = startOrChange;

		} else {
			start = startOrChange.start || this.start;
			end = startOrChange.end || this.end;
		}

E
Erich Gamma 已提交
356 357 358 359 360
		if (start.isEqual(this._start) && end.isEqual(this.end)) {
			return this;
		}
		return new Range(start, end);
	}
361 362 363 364

	toJSON(): any {
		return [this.start, this.end];
	}
E
Erich Gamma 已提交
365 366
}

J
Johannes Rieken 已提交
367
@es5ClassCompat
E
Erich Gamma 已提交
368 369
export class Selection extends Range {

370 371 372 373 374 375 376 377 378 379 380 381 382
	static isSelection(thing: any): thing is Selection {
		if (thing instanceof Selection) {
			return true;
		}
		if (!thing) {
			return false;
		}
		return Range.isRange(thing)
			&& Position.isPosition((<Selection>thing).anchor)
			&& Position.isPosition((<Selection>thing).active)
			&& typeof (<Selection>thing).isReversed === 'boolean';
	}

E
Erich Gamma 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395
	private _anchor: Position;

	public get anchor(): Position {
		return this._anchor;
	}

	private _active: Position;

	public get active(): Position {
		return this._active;
	}

	constructor(anchor: Position, active: Position);
J
Johannes Rieken 已提交
396
	constructor(anchorLine: number, anchorColumn: number, activeLine: number, activeColumn: number);
397
	constructor(anchorLineOrAnchor: number | Position, anchorColumnOrActive: number | Position, activeLine?: number, activeColumn?: number) {
398 399
		let anchor: Position | undefined;
		let active: Position | undefined;
E
Erich Gamma 已提交
400 401 402 403 404 405 406 407 408 409 410 411 412

		if (typeof anchorLineOrAnchor === 'number' && typeof anchorColumnOrActive === 'number' && typeof activeLine === 'number' && typeof activeColumn === 'number') {
			anchor = new Position(anchorLineOrAnchor, anchorColumnOrActive);
			active = new Position(activeLine, activeColumn);
		} else if (anchorLineOrAnchor instanceof Position && anchorColumnOrActive instanceof Position) {
			anchor = anchorLineOrAnchor;
			active = anchorColumnOrActive;
		}

		if (!anchor || !active) {
			throw new Error('Invalid arguments');
		}

413 414
		super(anchor, active);

E
Erich Gamma 已提交
415 416 417 418 419 420 421
		this._anchor = anchor;
		this._active = active;
	}

	get isReversed(): boolean {
		return this._anchor === this._end;
	}
422 423 424 425 426 427 428

	toJSON() {
		return {
			start: this.start,
			end: this.end,
			active: this.active,
			anchor: this.anchor
B
Benjamin Pasero 已提交
429
		};
430
	}
E
Erich Gamma 已提交
431 432
}

A
Alex Dima 已提交
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
export class ResolvedAuthority {
	readonly host: string;
	readonly port: number;

	constructor(host: string, port: number) {
		if (typeof host !== 'string' || host.length === 0) {
			throw illegalArgument('host');
		}
		if (typeof port !== 'number' || port === 0 || Math.round(port) !== port) {
			throw illegalArgument('port');
		}
		this.host = host;
		this.port = Math.round(port);
	}
}

A
Tweaks  
Alex Dima 已提交
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
export class RemoteAuthorityResolverError extends Error {

	static NotAvailable(message?: string, handled?: boolean): RemoteAuthorityResolverError {
		return new RemoteAuthorityResolverError(message, RemoteAuthorityResolverErrorCode.NotAvailable, handled);
	}

	static TemporarilyNotAvailable(message?: string): RemoteAuthorityResolverError {
		return new RemoteAuthorityResolverError(message, RemoteAuthorityResolverErrorCode.TemporarilyNotAvailable);
	}

	public readonly _message: string | undefined;
	public readonly _code: RemoteAuthorityResolverErrorCode;
	public readonly _detail: any;

	constructor(message?: string, code: RemoteAuthorityResolverErrorCode = RemoteAuthorityResolverErrorCode.Unknown, detail?: any) {
		super(message);

		this._message = message;
		this._code = code;
		this._detail = detail;

		// workaround when extending builtin objects and when compiling to ES5, see:
C
ChaseKnowlden 已提交
471
		// https://github.com/microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
A
Tweaks  
Alex Dima 已提交
472 473 474 475 476 477
		if (typeof (<any>Object).setPrototypeOf === 'function') {
			(<any>Object).setPrototypeOf(this, RemoteAuthorityResolverError.prototype);
		}
	}
}

478 479 480 481 482
export enum EndOfLine {
	LF = 1,
	CRLF = 2
}

483 484 485 486 487 488
export enum EnvironmentVariableMutatorType {
	Replace = 1,
	Append = 2,
	Prepend = 3
}

J
Johannes Rieken 已提交
489
@es5ClassCompat
E
Erich Gamma 已提交
490 491
export class TextEdit {

492 493 494 495 496 497 498 499 500 501 502
	static isTextEdit(thing: any): thing is TextEdit {
		if (thing instanceof TextEdit) {
			return true;
		}
		if (!thing) {
			return false;
		}
		return Range.isRange((<TextEdit>thing))
			&& typeof (<TextEdit>thing).newText === 'string';
	}

E
Erich Gamma 已提交
503 504 505 506 507 508 509 510 511 512 513 514
	static replace(range: Range, newText: string): TextEdit {
		return new TextEdit(range, newText);
	}

	static insert(position: Position, newText: string): TextEdit {
		return TextEdit.replace(new Range(position, position), newText);
	}

	static delete(range: Range): TextEdit {
		return TextEdit.replace(range, '');
	}

515
	static setEndOfLine(eol: EndOfLine): TextEdit {
516
		const ret = new TextEdit(new Range(new Position(0, 0), new Position(0, 0)), '');
517 518 519
		ret.newEol = eol;
		return ret;
	}
E
Erich Gamma 已提交
520

521
	protected _range: Range;
522
	protected _newText: string | null;
J
Johannes Rieken 已提交
523
	protected _newEol?: EndOfLine;
E
Erich Gamma 已提交
524 525 526 527 528 529

	get range(): Range {
		return this._range;
	}

	set range(value: Range) {
530
		if (value && !Range.isRange(value)) {
B
Benjamin Pasero 已提交
531
			throw illegalArgument('range');
E
Erich Gamma 已提交
532 533 534 535 536 537 538 539
		}
		this._range = value;
	}

	get newText(): string {
		return this._newText || '';
	}

540 541 542 543
	set newText(value: string) {
		if (value && typeof value !== 'string') {
			throw illegalArgument('newText');
		}
E
Erich Gamma 已提交
544 545 546
		this._newText = value;
	}

J
Johannes Rieken 已提交
547
	get newEol(): EndOfLine | undefined {
548 549 550
		return this._newEol;
	}

J
Johannes Rieken 已提交
551
	set newEol(value: EndOfLine | undefined) {
552 553 554 555 556 557
		if (value && typeof value !== 'number') {
			throw illegalArgument('newEol');
		}
		this._newEol = value;
	}

558
	constructor(range: Range, newText: string | null) {
J
Johannes Rieken 已提交
559
		this._range = range;
560
		this._newText = newText;
E
Erich Gamma 已提交
561
	}
562 563 564 565

	toJSON(): any {
		return {
			range: this.range,
566 567
			newText: this.newText,
			newEol: this._newEol
568 569
		};
	}
E
Erich Gamma 已提交
570 571
}

572 573 574
export interface IFileOperationOptions {
	overwrite?: boolean;
	ignoreIfExists?: boolean;
J
Johannes Rieken 已提交
575
	ignoreIfNotExists?: boolean;
576 577 578
	recursive?: boolean;
}

579 580
export const enum FileEditType {
	File = 1,
581 582
	Text = 2,
	Cell = 3
583 584
}

585
export interface IFileOperation {
586
	_type: FileEditType.File;
587 588
	from?: URI;
	to?: URI;
589
	options?: IFileOperationOptions;
590
	metadata?: vscode.WorkspaceEditEntryMetadata;
591 592 593
}

export interface IFileTextEdit {
594
	_type: FileEditType.Text;
595 596
	uri: URI;
	edit: TextEdit;
597
	metadata?: vscode.WorkspaceEditEntryMetadata;
598
}
E
Erich Gamma 已提交
599

600 601 602
export interface IFileCellEdit {
	_type: FileEditType.Cell;
	uri: URI;
603 604
	edit?: ICellEditOperation;
	notebookMetadata?: vscode.NotebookDocumentMetadata;
605 606 607
	metadata?: vscode.WorkspaceEditEntryMetadata;
}

J
Johannes Rieken 已提交
608
@es5ClassCompat
609 610
export class WorkspaceEdit implements vscode.WorkspaceEdit {

611
	private readonly _edits = new Array<IFileOperation | IFileTextEdit | IFileCellEdit>();
612 613


614
	_allEntries(): ReadonlyArray<IFileTextEdit | IFileOperation | IFileCellEdit> {
615 616 617 618
		return this._edits;
	}

	// --- file
619

620
	renameFile(from: vscode.Uri, to: vscode.Uri, options?: { overwrite?: boolean, ignoreIfExists?: boolean; }, metadata?: vscode.WorkspaceEditEntryMetadata): void {
621
		this._edits.push({ _type: FileEditType.File, from, to, options, metadata });
J
Johannes Rieken 已提交
622
	}
623

624
	createFile(uri: vscode.Uri, options?: { overwrite?: boolean, ignoreIfExists?: boolean; }, metadata?: vscode.WorkspaceEditEntryMetadata): void {
625
		this._edits.push({ _type: FileEditType.File, from: undefined, to: uri, options, metadata });
J
Johannes Rieken 已提交
626
	}
627

628
	deleteFile(uri: vscode.Uri, options?: { recursive?: boolean, ignoreIfNotExists?: boolean; }, metadata?: vscode.WorkspaceEditEntryMetadata): void {
629
		this._edits.push({ _type: FileEditType.File, from: uri, to: undefined, options, metadata });
J
Johannes Rieken 已提交
630
	}
631

632 633 634 635 636
	// --- notebook

	replaceNotebookMetadata(uri: URI, value: vscode.NotebookDocumentMetadata, metadata?: vscode.WorkspaceEditEntryMetadata): void {
		this._edits.push({ _type: FileEditType.Cell, metadata, uri, notebookMetadata: value });
	}
637

638
	replaceNotebookCells(uri: URI, start: number, end: number, cells: vscode.NotebookCellData[], metadata?: vscode.WorkspaceEditEntryMetadata): void {
639 640 641
		if (start !== end || cells.length > 0) {
			this._edits.push({ _type: FileEditType.Cell, metadata, uri, edit: { editType: CellEditType.Replace, index: start, count: end - start, cells: cells.map(cell => ({ ...cell, outputs: cell.outputs.map(output => addIdToOutput(output)) })) } });
		}
642 643
	}

644
	replaceNotebookCellOutput(uri: URI, index: number, outputs: vscode.CellOutput[], metadata?: vscode.WorkspaceEditEntryMetadata): void {
645 646 647
		this._edits.push({ _type: FileEditType.Cell, metadata, uri, edit: { editType: CellEditType.Output, index, outputs: outputs.map(output => addIdToOutput(output)) } });
	}

648
	replaceNotebookCellMetadata(uri: URI, index: number, cellMetadata: vscode.NotebookCellMetadata, metadata?: vscode.WorkspaceEditEntryMetadata): void {
649 650 651
		this._edits.push({ _type: FileEditType.Cell, metadata, uri, edit: { editType: CellEditType.Metadata, index, metadata: cellMetadata } });
	}

652 653
	// --- text

654
	replace(uri: URI, range: Range, newText: string, metadata?: vscode.WorkspaceEditEntryMetadata): void {
655
		this._edits.push({ _type: FileEditType.Text, uri, edit: new TextEdit(range, newText), metadata });
E
Erich Gamma 已提交
656 657
	}

658
	insert(resource: URI, position: Position, newText: string, metadata?: vscode.WorkspaceEditEntryMetadata): void {
659
		this.replace(resource, new Range(position, position), newText, metadata);
E
Erich Gamma 已提交
660 661
	}

662
	delete(resource: URI, range: Range, metadata?: vscode.WorkspaceEditEntryMetadata): void {
663
		this.replace(resource, range, '', metadata);
E
Erich Gamma 已提交
664 665
	}

666 667
	// --- text (Maplike)

668
	has(uri: URI): boolean {
669
		return this._edits.some(edit => edit._type === FileEditType.Text && edit.uri.toString() === uri.toString());
E
Erich Gamma 已提交
670 671
	}

672
	set(uri: URI, edits: TextEdit[]): void {
J
Johannes Rieken 已提交
673
		if (!edits) {
674 675 676
			// remove all text edits for `uri`
			for (let i = 0; i < this._edits.length; i++) {
				const element = this._edits[i];
677
				if (element._type === FileEditType.Text && element.uri.toString() === uri.toString()) {
678
					this._edits[i] = undefined!; // will be coalesced down below
679 680
				}
			}
681
			coalesceInPlace(this._edits);
E
Erich Gamma 已提交
682
		} else {
683 684 685
			// append edit to the end
			for (const edit of edits) {
				if (edit) {
686
					this._edits.push({ _type: FileEditType.Text, uri, edit });
687 688
				}
			}
E
Erich Gamma 已提交
689 690 691
		}
	}

692
	get(uri: URI): TextEdit[] {
693
		const res: TextEdit[] = [];
694
		for (let candidate of this._edits) {
695
			if (candidate._type === FileEditType.Text && candidate.uri.toString() === uri.toString()) {
696 697 698 699
				res.push(candidate.edit);
			}
		}
		return res;
E
Erich Gamma 已提交
700 701
	}

702
	entries(): [URI, TextEdit[]][] {
703
		const textEdits = new ResourceMap<[URI, TextEdit[]]>();
704
		for (let candidate of this._edits) {
705 706
			if (candidate._type === FileEditType.Text) {
				let textEdit = textEdits.get(candidate.uri);
707 708
				if (!textEdit) {
					textEdit = [candidate.uri, []];
709
					textEdits.set(candidate.uri, textEdit);
710 711 712 713
				}
				textEdit[1].push(candidate.edit);
			}
		}
714
		return [...textEdits.values()];
715 716
	}

E
Erich Gamma 已提交
717
	get size(): number {
718
		return this.entries().length;
E
Erich Gamma 已提交
719
	}
720 721

	toJSON(): any {
J
Johannes Rieken 已提交
722
		return this.entries();
723
	}
E
Erich Gamma 已提交
724 725
}

J
Johannes Rieken 已提交
726
@es5ClassCompat
727 728
export class SnippetString {

J
Joel Day 已提交
729 730 731 732 733 734 735 736 737 738
	static isSnippetString(thing: any): thing is SnippetString {
		if (thing instanceof SnippetString) {
			return true;
		}
		if (!thing) {
			return false;
		}
		return typeof (<SnippetString>thing).value === 'string';
	}

739 740 741 742
	private static _escape(value: string): string {
		return value.replace(/\$|}|\\/g, '\\$&');
	}

743 744
	private _tabstop: number = 1;

745 746
	value: string;

747 748 749 750 751
	constructor(value?: string) {
		this.value = value || '';
	}

	appendText(string: string): SnippetString {
752
		this.value += SnippetString._escape(string);
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
		return this;
	}

	appendTabstop(number: number = this._tabstop++): SnippetString {
		this.value += '$';
		this.value += number;
		return this;
	}

	appendPlaceholder(value: string | ((snippet: SnippetString) => any), number: number = this._tabstop++): SnippetString {

		if (typeof value === 'function') {
			const nested = new SnippetString();
			nested._tabstop = this._tabstop;
			value(nested);
			this._tabstop = nested._tabstop;
			value = nested.value;
		} else {
771
			value = SnippetString._escape(value);
772 773 774 775 776 777 778 779
		}

		this.value += '${';
		this.value += number;
		this.value += ':';
		this.value += value;
		this.value += '}';

780 781 782
		return this;
	}

O
okmttdhr 已提交
783 784 785 786 787 788 789 790 791
	appendChoice(values: string[], number: number = this._tabstop++): SnippetString {
		const value = SnippetString._escape(values.toString());

		this.value += '${';
		this.value += number;
		this.value += '|';
		this.value += value;
		this.value += '|}';

O
okmttdhr 已提交
792 793 794
		return this;
	}

795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816
	appendVariable(name: string, defaultValue?: string | ((snippet: SnippetString) => any)): SnippetString {

		if (typeof defaultValue === 'function') {
			const nested = new SnippetString();
			nested._tabstop = this._tabstop;
			defaultValue(nested);
			this._tabstop = nested._tabstop;
			defaultValue = nested.value;

		} else if (typeof defaultValue === 'string') {
			defaultValue = defaultValue.replace(/\$|}/g, '\\$&');
		}

		this.value += '${';
		this.value += name;
		if (defaultValue) {
			this.value += ':';
			this.value += defaultValue;
		}
		this.value += '}';


817
		return this;
818 819 820
	}
}

821 822
export enum DiagnosticTag {
	Unnecessary = 1,
823
	Deprecated = 2
824 825
}

E
Erich Gamma 已提交
826 827 828 829 830 831 832
export enum DiagnosticSeverity {
	Hint = 3,
	Information = 2,
	Warning = 1,
	Error = 0
}

J
Johannes Rieken 已提交
833
@es5ClassCompat
E
Erich Gamma 已提交
834 835
export class Location {

836 837 838 839 840 841 842 843 844 845 846
	static isLocation(thing: any): thing is Location {
		if (thing instanceof Location) {
			return true;
		}
		if (!thing) {
			return false;
		}
		return Range.isRange((<Location>thing).range)
			&& URI.isUri((<Location>thing).uri);
	}

E
Erich Gamma 已提交
847
	uri: URI;
J
Johannes Rieken 已提交
848
	range!: Range;
E
Erich Gamma 已提交
849

850
	constructor(uri: URI, rangeOrPosition: Range | Position) {
E
Erich Gamma 已提交
851 852
		this.uri = uri;

853 854 855 856 857 858
		if (!rangeOrPosition) {
			//that's OK
		} else if (rangeOrPosition instanceof Range) {
			this.range = rangeOrPosition;
		} else if (rangeOrPosition instanceof Position) {
			this.range = new Range(rangeOrPosition, rangeOrPosition);
E
Erich Gamma 已提交
859 860 861 862
		} else {
			throw new Error('Illegal argument');
		}
	}
863 864 865 866 867 868 869

	toJSON(): any {
		return {
			uri: this.uri,
			range: this.range
		};
	}
E
Erich Gamma 已提交
870 871
}

J
Johannes Rieken 已提交
872
@es5ClassCompat
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891
export class DiagnosticRelatedInformation {

	static is(thing: any): thing is DiagnosticRelatedInformation {
		if (!thing) {
			return false;
		}
		return typeof (<DiagnosticRelatedInformation>thing).message === 'string'
			&& (<DiagnosticRelatedInformation>thing).location
			&& Range.isRange((<DiagnosticRelatedInformation>thing).location.range)
			&& URI.isUri((<DiagnosticRelatedInformation>thing).location.uri);
	}

	location: Location;
	message: string;

	constructor(location: Location, message: string) {
		this.location = location;
		this.message = message;
	}
892 893 894 895 896 897 898 899 900 901 902 903

	static isEqual(a: DiagnosticRelatedInformation, b: DiagnosticRelatedInformation): boolean {
		if (a === b) {
			return true;
		}
		if (!a || !b) {
			return false;
		}
		return a.message === b.message
			&& a.location.range.isEqual(b.location.range)
			&& a.location.uri.toString() === b.location.uri.toString();
	}
904 905
}

J
Johannes Rieken 已提交
906
@es5ClassCompat
E
Erich Gamma 已提交
907 908 909 910 911
export class Diagnostic {

	range: Range;
	message: string;
	severity: DiagnosticSeverity;
J
Johannes Rieken 已提交
912 913 914
	source?: string;
	code?: string | number;
	relatedInformation?: DiagnosticRelatedInformation[];
915
	tags?: DiagnosticTag[];
E
Erich Gamma 已提交
916 917

	constructor(range: Range, message: string, severity: DiagnosticSeverity = DiagnosticSeverity.Error) {
918 919 920 921 922 923
		if (!Range.isRange(range)) {
			throw new TypeError('range must be set');
		}
		if (!message) {
			throw new TypeError('message must be set');
		}
E
Erich Gamma 已提交
924 925 926 927
		this.range = range;
		this.message = message;
		this.severity = severity;
	}
928 929 930 931 932 933 934 935

	toJSON(): any {
		return {
			severity: DiagnosticSeverity[this.severity],
			message: this.message,
			range: this.range,
			source: this.source,
			code: this.code,
B
Benjamin Pasero 已提交
936
		};
937
	}
938

939
	static isEqual(a: Diagnostic | undefined, b: Diagnostic | undefined): boolean {
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
		if (a === b) {
			return true;
		}
		if (!a || !b) {
			return false;
		}
		return a.message === b.message
			&& a.severity === b.severity
			&& a.code === b.code
			&& a.severity === b.severity
			&& a.source === b.source
			&& a.range.isEqual(b.range)
			&& equals(a.tags, b.tags)
			&& equals(a.relatedInformation, b.relatedInformation, DiagnosticRelatedInformation.isEqual);
	}
E
Erich Gamma 已提交
955 956
}

J
Johannes Rieken 已提交
957
@es5ClassCompat
E
Erich Gamma 已提交
958 959
export class Hover {

960
	public contents: vscode.MarkdownString[] | vscode.MarkedString[];
961
	public range: Range | undefined;
E
Erich Gamma 已提交
962

963 964 965 966
	constructor(
		contents: vscode.MarkdownString | vscode.MarkedString | vscode.MarkdownString[] | vscode.MarkedString[],
		range?: Range
	) {
E
Erich Gamma 已提交
967
		if (!contents) {
968
			throw new Error('Illegal argument, contents must be defined');
E
Erich Gamma 已提交
969 970
		}
		if (Array.isArray(contents)) {
971 972 973
			this.contents = <vscode.MarkdownString[] | vscode.MarkedString[]>contents;
		} else if (isMarkdownString(contents)) {
			this.contents = [contents];
E
Erich Gamma 已提交
974 975 976 977 978 979 980 981
		} else {
			this.contents = [contents];
		}
		this.range = range;
	}
}

export enum DocumentHighlightKind {
982 983 984
	Text = 0,
	Read = 1,
	Write = 2
E
Erich Gamma 已提交
985 986
}

J
Johannes Rieken 已提交
987
@es5ClassCompat
E
Erich Gamma 已提交
988 989 990 991 992 993 994 995 996
export class DocumentHighlight {

	range: Range;
	kind: DocumentHighlightKind;

	constructor(range: Range, kind: DocumentHighlightKind = DocumentHighlightKind.Text) {
		this.range = range;
		this.kind = kind;
	}
997 998 999 1000 1001

	toJSON(): any {
		return {
			range: this.range,
			kind: DocumentHighlightKind[this.kind]
B
Benjamin Pasero 已提交
1002
		};
1003
	}
E
Erich Gamma 已提交
1004 1005 1006
}

export enum SymbolKind {
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
	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,
1029 1030
	Struct = 22,
	Event = 23,
1031 1032
	Operator = 24,
	TypeParameter = 25
E
Erich Gamma 已提交
1033 1034
}

1035 1036 1037 1038
export enum SymbolTag {
	Deprecated = 1,
}

J
Johannes Rieken 已提交
1039
@es5ClassCompat
E
Erich Gamma 已提交
1040 1041
export class SymbolInformation {

J
Johannes Rieken 已提交
1042 1043 1044 1045 1046 1047
	static validate(candidate: SymbolInformation): void {
		if (!candidate.name) {
			throw new Error('name must not be falsy');
		}
	}

E
Erich Gamma 已提交
1048
	name: string;
J
Johannes Rieken 已提交
1049
	location!: Location;
E
Erich Gamma 已提交
1050
	kind: SymbolKind;
1051
	tags?: SymbolTag[];
1052
	containerName: string | undefined;
E
Erich Gamma 已提交
1053

M
Matt Bierner 已提交
1054
	constructor(name: string, kind: SymbolKind, containerName: string | undefined, location: Location);
1055
	constructor(name: string, kind: SymbolKind, range: Range, uri?: URI, containerName?: string);
M
Matt Bierner 已提交
1056
	constructor(name: string, kind: SymbolKind, rangeOrContainer: string | undefined | Range, locationOrUri?: Location | URI, containerName?: string) {
E
Erich Gamma 已提交
1057 1058 1059
		this.name = name;
		this.kind = kind;
		this.containerName = containerName;
1060 1061 1062 1063 1064 1065 1066

		if (typeof rangeOrContainer === 'string') {
			this.containerName = rangeOrContainer;
		}

		if (locationOrUri instanceof Location) {
			this.location = locationOrUri;
1067
		} else if (rangeOrContainer instanceof Range) {
1068
			this.location = new Location(locationOrUri!, rangeOrContainer);
1069
		}
J
Johannes Rieken 已提交
1070 1071

		SymbolInformation.validate(this);
E
Erich Gamma 已提交
1072
	}
1073 1074 1075 1076 1077 1078 1079

	toJSON(): any {
		return {
			name: this.name,
			kind: SymbolKind[this.kind],
			location: this.location,
			containerName: this.containerName
B
Benjamin Pasero 已提交
1080
		};
1081
	}
E
Erich Gamma 已提交
1082 1083
}

J
Johannes Rieken 已提交
1084
@es5ClassCompat
1085
export class DocumentSymbol {
J
Johannes Rieken 已提交
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098

	static validate(candidate: DocumentSymbol): void {
		if (!candidate.name) {
			throw new Error('name must not be falsy');
		}
		if (!candidate.range.contains(candidate.selectionRange)) {
			throw new Error('selectionRange must be contained in fullRange');
		}
		if (candidate.children) {
			candidate.children.forEach(DocumentSymbol.validate);
		}
	}

1099
	name: string;
1100
	detail: string;
1101
	kind: SymbolKind;
1102
	tags?: SymbolTag[];
1103 1104
	range: Range;
	selectionRange: Range;
1105
	children: DocumentSymbol[];
1106

1107
	constructor(name: string, detail: string, kind: SymbolKind, range: Range, selectionRange: Range) {
1108
		this.name = name;
1109
		this.detail = detail;
1110
		this.kind = kind;
1111 1112
		this.range = range;
		this.selectionRange = selectionRange;
1113
		this.children = [];
1114

J
Johannes Rieken 已提交
1115
		DocumentSymbol.validate(this);
1116 1117 1118
	}
}

1119

1120 1121 1122 1123 1124
export enum CodeActionTrigger {
	Automatic = 1,
	Manual = 2,
}

J
Johannes Rieken 已提交
1125
@es5ClassCompat
1126 1127 1128 1129 1130
export class CodeAction {
	title: string;

	command?: vscode.Command;

1131
	edit?: WorkspaceEdit;
1132

M
Matt Bierner 已提交
1133
	diagnostics?: Diagnostic[];
1134

1135
	kind?: CodeActionKind;
M
Matt Bierner 已提交
1136

1137 1138
	isPreferred?: boolean;

1139
	constructor(title: string, kind?: CodeActionKind) {
1140
		this.title = title;
1141
		this.kind = kind;
1142 1143 1144
	}
}

M
Matt Bierner 已提交
1145

J
Johannes Rieken 已提交
1146
@es5ClassCompat
M
Matt Bierner 已提交
1147 1148 1149
export class CodeActionKind {
	private static readonly sep = '.';

1150 1151 1152 1153 1154 1155 1156 1157 1158
	public static Empty: CodeActionKind;
	public static QuickFix: CodeActionKind;
	public static Refactor: CodeActionKind;
	public static RefactorExtract: CodeActionKind;
	public static RefactorInline: CodeActionKind;
	public static RefactorRewrite: CodeActionKind;
	public static Source: CodeActionKind;
	public static SourceOrganizeImports: CodeActionKind;
	public static SourceFixAll: CodeActionKind;
M
Matt Bierner 已提交
1159 1160 1161 1162 1163 1164 1165 1166 1167

	constructor(
		public readonly value: string
	) { }

	public append(parts: string): CodeActionKind {
		return new CodeActionKind(this.value ? this.value + CodeActionKind.sep + parts : parts);
	}

M
Matt Bierner 已提交
1168 1169 1170 1171
	public intersects(other: CodeActionKind): boolean {
		return this.contains(other) || other.contains(this);
	}

M
Matt Bierner 已提交
1172
	public contains(other: CodeActionKind): boolean {
1173
		return this.value === other.value || other.value.startsWith(this.value + CodeActionKind.sep);
M
Matt Bierner 已提交
1174 1175
	}
}
1176 1177 1178 1179 1180 1181 1182 1183 1184
CodeActionKind.Empty = new CodeActionKind('');
CodeActionKind.QuickFix = CodeActionKind.Empty.append('quickfix');
CodeActionKind.Refactor = CodeActionKind.Empty.append('refactor');
CodeActionKind.RefactorExtract = CodeActionKind.Refactor.append('extract');
CodeActionKind.RefactorInline = CodeActionKind.Refactor.append('inline');
CodeActionKind.RefactorRewrite = CodeActionKind.Refactor.append('rewrite');
CodeActionKind.Source = CodeActionKind.Empty.append('source');
CodeActionKind.SourceOrganizeImports = CodeActionKind.Source.append('organizeImports');
CodeActionKind.SourceFixAll = CodeActionKind.Source.append('fixAll');
M
Matt Bierner 已提交
1185

J
Johannes Rieken 已提交
1186
@es5ClassCompat
1187 1188 1189
export class SelectionRange {

	range: Range;
1190
	parent?: SelectionRange;
1191

1192
	constructor(range: Range, parent?: SelectionRange) {
1193
		this.range = range;
1194
		this.parent = parent;
1195 1196 1197 1198

		if (parent && !parent.range.contains(this.range)) {
			throw new Error('Invalid argument: parent must contain this range');
		}
1199 1200 1201
	}
}

1202
export class CallHierarchyItem {
1203

1204 1205
	_sessionId?: string;
	_itemId?: string;
1206

1207 1208 1209
	kind: SymbolKind;
	name: string;
	detail?: string;
1210
	uri: URI;
1211 1212 1213
	range: Range;
	selectionRange: Range;

1214
	constructor(kind: SymbolKind, name: string, detail: string, uri: URI, range: Range, selectionRange: Range) {
1215 1216 1217
		this.kind = kind;
		this.name = name;
		this.detail = detail;
1218
		this.uri = uri;
1219 1220 1221 1222 1223
		this.range = range;
		this.selectionRange = selectionRange;
	}
}

J
jrieken 已提交
1224
export class CallHierarchyIncomingCall {
J
jrieken 已提交
1225

1226 1227
	from: vscode.CallHierarchyItem;
	fromRanges: vscode.Range[];
J
jrieken 已提交
1228

1229 1230 1231
	constructor(item: vscode.CallHierarchyItem, fromRanges: vscode.Range[]) {
		this.fromRanges = fromRanges;
		this.from = item;
J
jrieken 已提交
1232 1233
	}
}
J
jrieken 已提交
1234
export class CallHierarchyOutgoingCall {
J
jrieken 已提交
1235

1236 1237
	to: vscode.CallHierarchyItem;
	fromRanges: vscode.Range[];
J
jrieken 已提交
1238

1239 1240 1241
	constructor(item: vscode.CallHierarchyItem, fromRanges: vscode.Range[]) {
		this.fromRanges = fromRanges;
		this.to = item;
J
jrieken 已提交
1242 1243 1244
	}
}

J
Johannes Rieken 已提交
1245
@es5ClassCompat
E
Erich Gamma 已提交
1246 1247 1248 1249
export class CodeLens {

	range: Range;

1250
	command: vscode.Command | undefined;
E
Erich Gamma 已提交
1251 1252 1253

	constructor(range: Range, command?: vscode.Command) {
		this.range = range;
1254
		this.command = command;
E
Erich Gamma 已提交
1255 1256 1257 1258 1259 1260 1261
	}

	get isResolved(): boolean {
		return !!this.command;
	}
}

R
Rob DeLine 已提交
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274

export class CodeInset {

	range: Range;
	height?: number;

	constructor(range: Range, height?: number) {
		this.range = range;
		this.height = height;
	}
}


J
Johannes Rieken 已提交
1275
@es5ClassCompat
1276 1277 1278 1279
export class MarkdownString {

	value: string;
	isTrusted?: boolean;
E
Eric Amodio 已提交
1280
	readonly supportThemeIcons?: boolean;
1281

E
Eric Amodio 已提交
1282
	constructor(value?: string, supportThemeIcons: boolean = false) {
E
Eric Amodio 已提交
1283
		this.value = value ?? '';
E
Eric Amodio 已提交
1284
		this.supportThemeIcons = supportThemeIcons;
1285 1286 1287 1288
	}

	appendText(value: string): MarkdownString {
		// escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
E
Eric Amodio 已提交
1289
		this.value += (this.supportThemeIcons ? escapeCodicons(value) : value)
P
Pine Wu 已提交
1290
			.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&')
J
João Moreno 已提交
1291
			.replace(/\n/, '\n\n');
E
Eric Amodio 已提交
1292

1293 1294 1295 1296 1297
		return this;
	}

	appendMarkdown(value: string): MarkdownString {
		this.value += value;
E
Eric Amodio 已提交
1298

1299 1300
		return this;
	}
J
Johannes Rieken 已提交
1301 1302 1303 1304 1305 1306 1307 1308 1309

	appendCodeblock(code: string, language: string = ''): MarkdownString {
		this.value += '\n```';
		this.value += language;
		this.value += '\n';
		this.value += code;
		this.value += '\n```\n';
		return this;
	}
1310 1311 1312 1313 1314

	static isMarkdownString(thing: any): thing is vscode.MarkdownString {
		if (thing instanceof MarkdownString) {
			return true;
		}
A
Alex Ross 已提交
1315
		return thing && thing.appendCodeblock && thing.appendMarkdown && thing.appendText && (thing.value !== undefined);
1316
	}
1317 1318
}

J
Johannes Rieken 已提交
1319
@es5ClassCompat
E
Erich Gamma 已提交
1320 1321
export class ParameterInformation {

1322
	label: string | [number, number];
1323
	documentation?: string | MarkdownString;
E
Erich Gamma 已提交
1324

1325
	constructor(label: string | [number, number], documentation?: string | MarkdownString) {
E
Erich Gamma 已提交
1326 1327 1328 1329 1330
		this.label = label;
		this.documentation = documentation;
	}
}

J
Johannes Rieken 已提交
1331
@es5ClassCompat
E
Erich Gamma 已提交
1332 1333 1334
export class SignatureInformation {

	label: string;
1335
	documentation?: string | MarkdownString;
E
Erich Gamma 已提交
1336
	parameters: ParameterInformation[];
1337
	activeParameter?: number;
E
Erich Gamma 已提交
1338

1339
	constructor(label: string, documentation?: string | MarkdownString) {
E
Erich Gamma 已提交
1340 1341 1342 1343 1344 1345
		this.label = label;
		this.documentation = documentation;
		this.parameters = [];
	}
}

J
Johannes Rieken 已提交
1346
@es5ClassCompat
E
Erich Gamma 已提交
1347 1348 1349
export class SignatureHelp {

	signatures: SignatureInformation[];
J
Johannes Rieken 已提交
1350 1351
	activeSignature: number = 0;
	activeParameter: number = 0;
E
Erich Gamma 已提交
1352 1353 1354 1355 1356 1357

	constructor() {
		this.signatures = [];
	}
}

M
Matt Bierner 已提交
1358
export enum SignatureHelpTriggerKind {
1359 1360
	Invoke = 1,
	TriggerCharacter = 2,
1361
	ContentChange = 3,
1362 1363
}

M
Matt Bierner 已提交
1364 1365
export enum CompletionTriggerKind {
	Invoke = 0,
1366 1367
	TriggerCharacter = 1,
	TriggerForIncompleteCompletions = 2
M
Matt Bierner 已提交
1368 1369 1370
}

export interface CompletionContext {
1371 1372
	readonly triggerKind: CompletionTriggerKind;
	readonly triggerCharacter?: string;
M
Matt Bierner 已提交
1373 1374
}

E
Erich Gamma 已提交
1375
export enum CompletionItemKind {
1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392
	Text = 0,
	Method = 1,
	Function = 2,
	Constructor = 3,
	Field = 4,
	Variable = 5,
	Class = 6,
	Interface = 7,
	Module = 8,
	Property = 9,
	Unit = 10,
	Value = 11,
	Enum = 12,
	Keyword = 13,
	Snippet = 14,
	Color = 15,
	File = 16,
1393
	Reference = 17,
1394 1395
	Folder = 18,
	EnumMember = 19,
1396
	Constant = 20,
1397 1398
	Struct = 21,
	Event = 22,
1399
	Operator = 23,
1400 1401 1402
	TypeParameter = 24,
	User = 25,
	Issue = 26
E
Erich Gamma 已提交
1403 1404
}

1405
export enum CompletionItemTag {
1406 1407 1408
	Deprecated = 1,
}

1409
export interface CompletionItemLabel {
P
Pine Wu 已提交
1410
	name: string;
1411
	parameters?: string;
P
Pine Wu 已提交
1412
	qualifier?: string;
P
Pine Wu 已提交
1413
	type?: string;
1414 1415 1416
}


J
Johannes Rieken 已提交
1417
@es5ClassCompat
1418
export class CompletionItem implements vscode.CompletionItem {
E
Erich Gamma 已提交
1419

P
label2  
Pine Wu 已提交
1420
	label: string;
P
Pine Wu 已提交
1421
	label2?: CompletionItemLabel;
J
Johannes Rieken 已提交
1422
	kind?: CompletionItemKind;
1423
	tags?: CompletionItemTag[];
1424 1425 1426 1427 1428
	detail?: string;
	documentation?: string | MarkdownString;
	sortText?: string;
	filterText?: string;
	preselect?: boolean;
J
Johannes Rieken 已提交
1429
	insertText?: string | SnippetString;
1430
	keepWhitespace?: boolean;
1431
	range?: Range | { inserting: Range; replacing: Range; };
1432
	commitCharacters?: string[];
J
Johannes Rieken 已提交
1433 1434 1435
	textEdit?: TextEdit;
	additionalTextEdits?: TextEdit[];
	command?: vscode.Command;
E
Erich Gamma 已提交
1436

P
label2  
Pine Wu 已提交
1437
	constructor(label: string, kind?: CompletionItemKind) {
E
Erich Gamma 已提交
1438
		this.label = label;
1439
		this.kind = kind;
E
Erich Gamma 已提交
1440
	}
1441 1442 1443 1444

	toJSON(): any {
		return {
			label: this.label,
P
label2  
Pine Wu 已提交
1445
			label2: this.label2,
1446
			kind: this.kind && CompletionItemKind[this.kind],
1447 1448 1449 1450
			detail: this.detail,
			documentation: this.documentation,
			sortText: this.sortText,
			filterText: this.filterText,
1451
			preselect: this.preselect,
1452 1453
			insertText: this.insertText,
			textEdit: this.textEdit
B
Benjamin Pasero 已提交
1454
		};
1455
	}
E
Erich Gamma 已提交
1456 1457
}

J
Johannes Rieken 已提交
1458
@es5ClassCompat
1459 1460
export class CompletionList {

1461
	isIncomplete?: boolean;
1462 1463 1464 1465 1466 1467 1468 1469
	items: vscode.CompletionItem[];

	constructor(items: vscode.CompletionItem[] = [], isIncomplete: boolean = false) {
		this.items = items;
		this.isIncomplete = isIncomplete;
	}
}

E
Erich Gamma 已提交
1470
export enum ViewColumn {
1471
	Active = -1,
1472
	Beside = -2,
E
Erich Gamma 已提交
1473 1474
	One = 1,
	Two = 2,
1475 1476 1477 1478 1479 1480 1481
	Three = 3,
	Four = 4,
	Five = 5,
	Six = 6,
	Seven = 7,
	Eight = 8,
	Nine = 9
E
Erich Gamma 已提交
1482 1483 1484 1485 1486
}

export enum StatusBarAlignment {
	Left = 1,
	Right = 2
J
Johannes Rieken 已提交
1487
}
1488

1489 1490 1491 1492 1493 1494
export enum TextEditorLineNumbersStyle {
	Off = 0,
	On = 1,
	Relative = 2
}

1495
export enum TextDocumentSaveReason {
1496 1497
	Manual = 1,
	AfterDelay = 2,
1498 1499 1500
	FocusOut = 3
}

1501 1502 1503
export enum TextEditorRevealType {
	Default = 0,
	InCenter = 1,
1504 1505
	InCenterIfOutsideViewport = 2,
	AtTop = 3
1506
}
J
Johannes Rieken 已提交
1507

1508 1509 1510 1511 1512 1513
export enum TextEditorSelectionChangeKind {
	Keyboard = 1,
	Mouse = 2,
	Command = 3
}

A
Alex Dima 已提交
1514 1515 1516
/**
 * These values match very carefully the values of `TrackedRangeStickiness`
 */
1517
export enum DecorationRangeBehavior {
A
Alex Dima 已提交
1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535
	/**
	 * TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges
	 */
	OpenOpen = 0,
	/**
	 * TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges
	 */
	ClosedClosed = 1,
	/**
	 * TrackedRangeStickiness.GrowsOnlyWhenTypingBefore
	 */
	OpenClosed = 2,
	/**
	 * TrackedRangeStickiness.GrowsOnlyWhenTypingAfter
	 */
	ClosedOpen = 3
}

1536
export namespace TextEditorSelectionChangeKind {
1537
	export function fromValue(s: string | undefined) {
1538 1539 1540 1541 1542
		switch (s) {
			case 'keyboard': return TextEditorSelectionChangeKind.Keyboard;
			case 'mouse': return TextEditorSelectionChangeKind.Mouse;
			case 'api': return TextEditorSelectionChangeKind.Command;
		}
M
Matt Bierner 已提交
1543
		return undefined;
1544 1545 1546
	}
}

J
Johannes Rieken 已提交
1547
@es5ClassCompat
J
Johannes Rieken 已提交
1548 1549 1550 1551
export class DocumentLink {

	range: Range;

1552
	target?: URI;
1553 1554

	tooltip?: string;
J
Johannes Rieken 已提交
1555

1556
	constructor(range: Range, target: URI | undefined) {
1557
		if (target && !(URI.isUri(target))) {
J
Johannes Rieken 已提交
1558 1559
			throw illegalArgument('target');
		}
1560
		if (!Range.isRange(range) || range.isEmpty) {
J
Johannes Rieken 已提交
1561 1562 1563 1564 1565
			throw illegalArgument('range');
		}
		this.range = range;
		this.target = target;
	}
1566
}
1567

J
Johannes Rieken 已提交
1568
@es5ClassCompat
1569
export class Color {
1570 1571 1572 1573
	readonly red: number;
	readonly green: number;
	readonly blue: number;
	readonly alpha: number;
1574

J
Joao Moreno 已提交
1575
	constructor(red: number, green: number, blue: number, alpha: number) {
1576 1577 1578 1579 1580
		this.red = red;
		this.green = green;
		this.blue = blue;
		this.alpha = alpha;
	}
1581 1582
}

1583
export type IColorFormat = string | { opaque: string, transparent: string; };
M
Michel Kaporin 已提交
1584

J
Johannes Rieken 已提交
1585
@es5ClassCompat
1586
export class ColorInformation {
1587 1588 1589 1590
	range: Range;

	color: Color;

1591
	constructor(range: Range, color: Color) {
1592
		if (color && !(color instanceof Color)) {
M
Michel Kaporin 已提交
1593 1594
			throw illegalArgument('color');
		}
1595 1596 1597 1598 1599 1600 1601 1602
		if (!Range.isRange(range) || range.isEmpty) {
			throw illegalArgument('range');
		}
		this.range = range;
		this.color = color;
	}
}

J
Johannes Rieken 已提交
1603
@es5ClassCompat
1604 1605 1606 1607
export class ColorPresentation {
	label: string;
	textEdit?: TextEdit;
	additionalTextEdits?: TextEdit[];
1608 1609 1610 1611 1612 1613 1614

	constructor(label: string) {
		if (!label || typeof label !== 'string') {
			throw illegalArgument('label');
		}
		this.label = label;
	}
1615 1616
}

1617 1618 1619 1620 1621 1622
export enum ColorFormat {
	RGB = 0,
	HEX = 1,
	HSL = 2
}

1623 1624 1625 1626 1627 1628
export enum SourceControlInputBoxValidationType {
	Error = 0,
	Warning = 1,
	Information = 2
}

1629
export enum TaskRevealKind {
1630 1631 1632 1633 1634 1635 1636
	Always = 1,

	Silent = 2,

	Never = 3
}

1637
export enum TaskPanelKind {
1638 1639
	Shared = 1,

1640
	Dedicated = 2,
1641 1642 1643 1644

	New = 3
}

J
Johannes Rieken 已提交
1645
@es5ClassCompat
D
Dirk Baeumer 已提交
1646
export class TaskGroup implements vscode.TaskGroup {
1647

D
Dirk Baeumer 已提交
1648
	private _id: string;
1649

D
Dirk Baeumer 已提交
1650
	public static Clean: TaskGroup = new TaskGroup('clean', 'Clean');
D
Dirk Baeumer 已提交
1651

D
Dirk Baeumer 已提交
1652
	public static Build: TaskGroup = new TaskGroup('build', 'Build');
D
Dirk Baeumer 已提交
1653

1654
	public static Rebuild: TaskGroup = new TaskGroup('rebuild', 'Rebuild');
1655

1656
	public static Test: TaskGroup = new TaskGroup('test', 'Test');
D
Dirk Baeumer 已提交
1657

1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672
	public static from(value: string) {
		switch (value) {
			case 'clean':
				return TaskGroup.Clean;
			case 'build':
				return TaskGroup.Build;
			case 'rebuild':
				return TaskGroup.Rebuild;
			case 'test':
				return TaskGroup.Test;
			default:
				return undefined;
		}
	}

D
Dirk Baeumer 已提交
1673
	constructor(id: string, _label: string) {
D
Dirk Baeumer 已提交
1674 1675 1676
		if (typeof id !== 'string') {
			throw illegalArgument('name');
		}
D
Dirk Baeumer 已提交
1677
		if (typeof _label !== 'string') {
D
Dirk Baeumer 已提交
1678
			throw illegalArgument('name');
1679
		}
D
Dirk Baeumer 已提交
1680
		this._id = id;
1681 1682
	}

D
Dirk Baeumer 已提交
1683 1684
	get id(): string {
		return this._id;
1685
	}
D
Dirk Baeumer 已提交
1686
}
1687

1688 1689 1690 1691 1692 1693 1694 1695
function computeTaskExecutionId(values: string[]): string {
	let id: string = '';
	for (let i = 0; i < values.length; i++) {
		id += values[i].replace(/,/g, ',,') + ',';
	}
	return id;
}

J
Johannes Rieken 已提交
1696
@es5ClassCompat
D
Dirk Baeumer 已提交
1697 1698 1699 1700
export class ProcessExecution implements vscode.ProcessExecution {

	private _process: string;
	private _args: string[];
1701
	private _options: vscode.ProcessExecutionOptions | undefined;
D
Dirk Baeumer 已提交
1702 1703 1704 1705 1706 1707 1708

	constructor(process: string, options?: vscode.ProcessExecutionOptions);
	constructor(process: string, args: string[], options?: vscode.ProcessExecutionOptions);
	constructor(process: string, varg1?: string[] | vscode.ProcessExecutionOptions, varg2?: vscode.ProcessExecutionOptions) {
		if (typeof process !== 'string') {
			throw illegalArgument('process');
		}
1709
		this._args = [];
D
Dirk Baeumer 已提交
1710
		this._process = process;
R
Rob Lourens 已提交
1711
		if (varg1 !== undefined) {
D
Dirk Baeumer 已提交
1712 1713 1714 1715 1716 1717 1718
			if (Array.isArray(varg1)) {
				this._args = varg1;
				this._options = varg2;
			} else {
				this._options = varg1;
			}
		}
1719 1720
	}

D
Dirk Baeumer 已提交
1721 1722 1723

	get process(): string {
		return this._process;
D
Dirk Baeumer 已提交
1724 1725
	}

D
Dirk Baeumer 已提交
1726 1727 1728
	set process(value: string) {
		if (typeof value !== 'string') {
			throw illegalArgument('process');
D
Dirk Baeumer 已提交
1729
		}
D
Dirk Baeumer 已提交
1730
		this._process = value;
D
Dirk Baeumer 已提交
1731 1732
	}

D
Dirk Baeumer 已提交
1733 1734
	get args(): string[] {
		return this._args;
1735 1736
	}

D
Dirk Baeumer 已提交
1737 1738 1739
	set args(value: string[]) {
		if (!Array.isArray(value)) {
			value = [];
1740
		}
D
Dirk Baeumer 已提交
1741
		this._args = value;
1742 1743
	}

1744
	get options(): vscode.ProcessExecutionOptions | undefined {
D
Dirk Baeumer 已提交
1745
		return this._options;
1746 1747
	}

1748
	set options(value: vscode.ProcessExecutionOptions | undefined) {
D
Dirk Baeumer 已提交
1749
		this._options = value;
1750
	}
D
Dirk Baeumer 已提交
1751 1752

	public computeId(): string {
1753 1754
		const props: string[] = [];
		props.push('process');
R
Rob Lourens 已提交
1755
		if (this._process !== undefined) {
1756
			props.push(this._process);
D
Dirk Baeumer 已提交
1757 1758 1759
		}
		if (this._args && this._args.length > 0) {
			for (let arg of this._args) {
1760
				props.push(arg);
D
Dirk Baeumer 已提交
1761 1762
			}
		}
1763
		return computeTaskExecutionId(props);
D
Dirk Baeumer 已提交
1764
	}
D
Dirk Baeumer 已提交
1765
}
1766

J
Johannes Rieken 已提交
1767
@es5ClassCompat
D
Dirk Baeumer 已提交
1768
export class ShellExecution implements vscode.ShellExecution {
D
Dirk Baeumer 已提交
1769

1770 1771 1772
	private _commandLine: string | undefined;
	private _command: string | vscode.ShellQuotedString | undefined;
	private _args: (string | vscode.ShellQuotedString)[] = [];
1773
	private _options: vscode.ShellExecutionOptions | undefined;
D
Dirk Baeumer 已提交
1774

1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793
	constructor(commandLine: string, options?: vscode.ShellExecutionOptions);
	constructor(command: string | vscode.ShellQuotedString, args: (string | vscode.ShellQuotedString)[], options?: vscode.ShellExecutionOptions);
	constructor(arg0: string | vscode.ShellQuotedString, arg1?: vscode.ShellExecutionOptions | (string | vscode.ShellQuotedString)[], arg2?: vscode.ShellExecutionOptions) {
		if (Array.isArray(arg1)) {
			if (!arg0) {
				throw illegalArgument('command can\'t be undefined or null');
			}
			if (typeof arg0 !== 'string' && typeof arg0.value !== 'string') {
				throw illegalArgument('command');
			}
			this._command = arg0;
			this._args = arg1 as (string | vscode.ShellQuotedString)[];
			this._options = arg2;
		} else {
			if (typeof arg0 !== 'string') {
				throw illegalArgument('commandLine');
			}
			this._commandLine = arg0;
			this._options = arg1;
D
Dirk Baeumer 已提交
1794 1795 1796
		}
	}

1797
	get commandLine(): string | undefined {
D
Dirk Baeumer 已提交
1798
		return this._commandLine;
1799
	}
D
Dirk Baeumer 已提交
1800

1801
	set commandLine(value: string | undefined) {
D
Dirk Baeumer 已提交
1802 1803
		if (typeof value !== 'string') {
			throw illegalArgument('commandLine');
D
Dirk Baeumer 已提交
1804
		}
D
Dirk Baeumer 已提交
1805
		this._commandLine = value;
D
Dirk Baeumer 已提交
1806
	}
1807

1808
	get command(): string | vscode.ShellQuotedString {
1809
		return this._command ? this._command : '';
1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826
	}

	set command(value: string | vscode.ShellQuotedString) {
		if (typeof value !== 'string' && typeof value.value !== 'string') {
			throw illegalArgument('command');
		}
		this._command = value;
	}

	get args(): (string | vscode.ShellQuotedString)[] {
		return this._args;
	}

	set args(value: (string | vscode.ShellQuotedString)[]) {
		this._args = value || [];
	}

1827
	get options(): vscode.ShellExecutionOptions | undefined {
D
Dirk Baeumer 已提交
1828
		return this._options;
1829 1830
	}

1831
	set options(value: vscode.ShellExecutionOptions | undefined) {
D
Dirk Baeumer 已提交
1832
		this._options = value;
1833
	}
D
Dirk Baeumer 已提交
1834 1835

	public computeId(): string {
1836 1837
		const props: string[] = [];
		props.push('shell');
R
Rob Lourens 已提交
1838
		if (this._commandLine !== undefined) {
1839
			props.push(this._commandLine);
D
Dirk Baeumer 已提交
1840
		}
R
Rob Lourens 已提交
1841
		if (this._command !== undefined) {
1842
			props.push(typeof this._command === 'string' ? this._command : this._command.value);
D
Dirk Baeumer 已提交
1843 1844 1845
		}
		if (this._args && this._args.length > 0) {
			for (let arg of this._args) {
1846
				props.push(typeof arg === 'string' ? arg : arg.value);
D
Dirk Baeumer 已提交
1847 1848
			}
		}
1849
		return computeTaskExecutionId(props);
D
Dirk Baeumer 已提交
1850
	}
1851 1852
}

1853 1854 1855 1856 1857 1858
export enum ShellQuoting {
	Escape = 1,
	Strong = 2,
	Weak = 3
}

D
Dirk Baeumer 已提交
1859 1860 1861 1862 1863
export enum TaskScope {
	Global = 1,
	Workspace = 2
}

1864 1865 1866
export class CustomExecution implements vscode.CustomExecution {
	private _callback: (resolvedDefintion: vscode.TaskDefinition) => Thenable<vscode.Pseudoterminal>;
	constructor(callback: (resolvedDefintion: vscode.TaskDefinition) => Thenable<vscode.Pseudoterminal>) {
1867 1868 1869 1870 1871 1872
		this._callback = callback;
	}
	public computeId(): string {
		return 'customExecution' + generateUuid();
	}

1873
	public set callback(value: (resolvedDefintion: vscode.TaskDefinition) => Thenable<vscode.Pseudoterminal>) {
1874 1875 1876
		this._callback = value;
	}

1877
	public get callback(): ((resolvedDefintion: vscode.TaskDefinition) => Thenable<vscode.Pseudoterminal>) {
1878 1879 1880 1881
		return this._callback;
	}
}

J
Johannes Rieken 已提交
1882
@es5ClassCompat
A
Alex Ross 已提交
1883
export class Task implements vscode.Task {
1884

G
Gabriel DeBacker 已提交
1885
	private static ExtensionCallbackType: string = 'customExecution';
1886 1887 1888 1889 1890
	private static ProcessType: string = 'process';
	private static ShellType: string = 'shell';
	private static EmptyType: string = '$empty';

	private __id: string | undefined;
1891
	private __deprecated: boolean = false;
1892

D
Dirk Baeumer 已提交
1893
	private _definition: vscode.TaskDefinition;
1894
	private _scope: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder | undefined;
D
Dirk Baeumer 已提交
1895
	private _name: string;
1896
	private _execution: ProcessExecution | ShellExecution | CustomExecution | undefined;
D
Dirk Baeumer 已提交
1897
	private _problemMatchers: string[];
1898
	private _hasDefinedMatchers: boolean;
D
Dirk Baeumer 已提交
1899 1900
	private _isBackground: boolean;
	private _source: string;
1901
	private _group: TaskGroup | undefined;
D
Dirk Baeumer 已提交
1902
	private _presentationOptions: vscode.TaskPresentationOptions;
A
Alex Ross 已提交
1903
	private _runOptions: vscode.RunOptions;
1904
	private _detail: string | undefined;
1905

1906 1907
	constructor(definition: vscode.TaskDefinition, name: string, source: string, execution?: ProcessExecution | ShellExecution | CustomExecution, problemMatchers?: string | string[]);
	constructor(definition: vscode.TaskDefinition, scope: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder, name: string, source: string, execution?: ProcessExecution | ShellExecution | CustomExecution, problemMatchers?: string | string[]);
D
Dirk Baeumer 已提交
1908
	constructor(definition: vscode.TaskDefinition, arg2: string | (vscode.TaskScope.Global | vscode.TaskScope.Workspace) | vscode.WorkspaceFolder, arg3: any, arg4?: any, arg5?: any, arg6?: any) {
1909
		this._definition = this.definition = definition;
D
Dirk Baeumer 已提交
1910 1911
		let problemMatchers: string | string[];
		if (typeof arg2 === 'string') {
1912 1913
			this._name = this.name = arg2;
			this._source = this.source = arg3;
D
Dirk Baeumer 已提交
1914 1915
			this.execution = arg4;
			problemMatchers = arg5;
1916
			this.__deprecated = true;
D
Dirk Baeumer 已提交
1917 1918
		} else if (arg2 === TaskScope.Global || arg2 === TaskScope.Workspace) {
			this.target = arg2;
1919 1920
			this._name = this.name = arg3;
			this._source = this.source = arg4;
D
Dirk Baeumer 已提交
1921 1922
			this.execution = arg5;
			problemMatchers = arg6;
D
Dirk Baeumer 已提交
1923
		} else {
D
Dirk Baeumer 已提交
1924
			this.target = arg2;
1925 1926
			this._name = this.name = arg3;
			this._source = this.source = arg4;
D
Dirk Baeumer 已提交
1927 1928 1929
			this.execution = arg5;
			problemMatchers = arg6;
		}
1930 1931
		if (typeof problemMatchers === 'string') {
			this._problemMatchers = [problemMatchers];
1932
			this._hasDefinedMatchers = true;
1933 1934
		} else if (Array.isArray(problemMatchers)) {
			this._problemMatchers = problemMatchers;
1935
			this._hasDefinedMatchers = true;
1936 1937
		} else {
			this._problemMatchers = [];
1938
			this._hasDefinedMatchers = false;
1939
		}
D
Dirk Baeumer 已提交
1940
		this._isBackground = false;
1941 1942
		this._presentationOptions = Object.create(null);
		this._runOptions = Object.create(null);
1943
	}
1944

1945
	get _id(): string | undefined {
1946 1947 1948
		return this.__id;
	}

1949
	set _id(value: string | undefined) {
1950 1951 1952
		this.__id = value;
	}

1953 1954 1955 1956
	get _deprecated(): boolean {
		return this.__deprecated;
	}

1957
	private clear(): void {
R
Rob Lourens 已提交
1958
		if (this.__id === undefined) {
D
Dirk Baeumer 已提交
1959 1960
			return;
		}
1961
		this.__id = undefined;
D
Dirk Baeumer 已提交
1962
		this._scope = undefined;
1963 1964 1965 1966
		this.computeDefinitionBasedOnExecution();
	}

	private computeDefinitionBasedOnExecution(): void {
D
Dirk Baeumer 已提交
1967 1968
		if (this._execution instanceof ProcessExecution) {
			this._definition = {
1969
				type: Task.ProcessType,
D
Dirk Baeumer 已提交
1970 1971 1972 1973
				id: this._execution.computeId()
			};
		} else if (this._execution instanceof ShellExecution) {
			this._definition = {
1974
				type: Task.ShellType,
D
Dirk Baeumer 已提交
1975 1976
				id: this._execution.computeId()
			};
1977
		} else if (this._execution instanceof CustomExecution) {
1978 1979 1980 1981
			this._definition = {
				type: Task.ExtensionCallbackType,
				id: this._execution.computeId()
			};
1982 1983 1984 1985 1986
		} else {
			this._definition = {
				type: Task.EmptyType,
				id: generateUuid()
			};
D
Dirk Baeumer 已提交
1987
		}
1988 1989
	}

D
Dirk Baeumer 已提交
1990 1991
	get definition(): vscode.TaskDefinition {
		return this._definition;
D
Dirk Baeumer 已提交
1992
	}
1993

D
Dirk Baeumer 已提交
1994
	set definition(value: vscode.TaskDefinition) {
R
Rob Lourens 已提交
1995
		if (value === undefined || value === null) {
D
Dirk Baeumer 已提交
1996
			throw illegalArgument('Kind can\'t be undefined or null');
1997
		}
1998
		this.clear();
D
Dirk Baeumer 已提交
1999
		this._definition = value;
D
Dirk Baeumer 已提交
2000
	}
2001

2002
	get scope(): vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder | undefined {
D
Dirk Baeumer 已提交
2003
		return this._scope;
D
Dirk Baeumer 已提交
2004 2005
	}

D
Dirk Baeumer 已提交
2006
	set target(value: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder) {
2007
		this.clear();
D
Dirk Baeumer 已提交
2008
		this._scope = value;
D
Dirk Baeumer 已提交
2009 2010
	}

D
Dirk Baeumer 已提交
2011 2012 2013 2014 2015 2016 2017
	get name(): string {
		return this._name;
	}

	set name(value: string) {
		if (typeof value !== 'string') {
			throw illegalArgument('name');
2018
		}
2019
		this.clear();
D
Dirk Baeumer 已提交
2020
		this._name = value;
2021 2022
	}

A
Alex Ross 已提交
2023
	get execution(): ProcessExecution | ShellExecution | CustomExecution | undefined {
D
Dirk Baeumer 已提交
2024
		return this._execution;
2025
	}
D
Dirk Baeumer 已提交
2026

A
Alex Ross 已提交
2027
	set execution(value: ProcessExecution | ShellExecution | CustomExecution | undefined) {
D
Dirk Baeumer 已提交
2028 2029 2030
		if (value === null) {
			value = undefined;
		}
2031
		this.clear();
D
Dirk Baeumer 已提交
2032
		this._execution = value;
2033
		const type = this._definition.type;
2034
		if (Task.EmptyType === type || Task.ProcessType === type || Task.ShellType === type || Task.ExtensionCallbackType === type) {
2035 2036
			this.computeDefinitionBasedOnExecution();
		}
D
Dirk Baeumer 已提交
2037 2038
	}

D
Dirk Baeumer 已提交
2039 2040 2041 2042 2043
	get problemMatchers(): string[] {
		return this._problemMatchers;
	}

	set problemMatchers(value: string[]) {
D
Dirk Baeumer 已提交
2044
		if (!Array.isArray(value)) {
2045
			this.clear();
2046 2047 2048
			this._problemMatchers = [];
			this._hasDefinedMatchers = false;
			return;
2049 2050 2051 2052
		} else {
			this.clear();
			this._problemMatchers = value;
			this._hasDefinedMatchers = true;
D
Dirk Baeumer 已提交
2053
		}
2054 2055 2056 2057
	}

	get hasDefinedMatchers(): boolean {
		return this._hasDefinedMatchers;
D
Dirk Baeumer 已提交
2058 2059
	}

D
Dirk Baeumer 已提交
2060 2061
	get isBackground(): boolean {
		return this._isBackground;
D
Dirk Baeumer 已提交
2062 2063
	}

D
Dirk Baeumer 已提交
2064 2065 2066
	set isBackground(value: boolean) {
		if (value !== true && value !== false) {
			value = false;
D
Dirk Baeumer 已提交
2067
		}
2068
		this.clear();
D
Dirk Baeumer 已提交
2069
		this._isBackground = value;
D
Dirk Baeumer 已提交
2070
	}
2071

D
Dirk Baeumer 已提交
2072 2073 2074
	get source(): string {
		return this._source;
	}
2075

D
Dirk Baeumer 已提交
2076 2077 2078
	set source(value: string) {
		if (typeof value !== 'string' || value.length === 0) {
			throw illegalArgument('source must be a string of length > 0');
2079
		}
2080
		this.clear();
D
Dirk Baeumer 已提交
2081
		this._source = value;
2082 2083
	}

2084
	get group(): TaskGroup | undefined {
D
Dirk Baeumer 已提交
2085
		return this._group;
2086
	}
D
Dirk Baeumer 已提交
2087

2088 2089 2090
	set group(value: TaskGroup | undefined) {
		if (value === null) {
			value = undefined;
D
Dirk Baeumer 已提交
2091
		}
2092
		this.clear();
D
Dirk Baeumer 已提交
2093
		this._group = value;
D
Dirk Baeumer 已提交
2094 2095
	}

2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106
	get detail(): string | undefined {
		return this._detail;
	}

	set detail(value: string | undefined) {
		if (value === null) {
			value = undefined;
		}
		this._detail = value;
	}

D
Dirk Baeumer 已提交
2107 2108 2109 2110 2111
	get presentationOptions(): vscode.TaskPresentationOptions {
		return this._presentationOptions;
	}

	set presentationOptions(value: vscode.TaskPresentationOptions) {
2112 2113
		if (value === null || value === undefined) {
			value = Object.create(null);
D
Dirk Baeumer 已提交
2114
		}
2115
		this.clear();
D
Dirk Baeumer 已提交
2116
		this._presentationOptions = value;
D
Dirk Baeumer 已提交
2117
	}
A
Alex Ross 已提交
2118 2119 2120 2121 2122 2123

	get runOptions(): vscode.RunOptions {
		return this._runOptions;
	}

	set runOptions(value: vscode.RunOptions) {
2124 2125
		if (value === null || value === undefined) {
			value = Object.create(null);
A
Alex Ross 已提交
2126 2127 2128 2129
		}
		this.clear();
		this._runOptions = value;
	}
2130
}
J
Johannes Rieken 已提交
2131

D
Dirk Baeumer 已提交
2132

J
Johannes Rieken 已提交
2133
export enum ProgressLocation {
2134
	SourceControl = 1,
J
Johannes Rieken 已提交
2135
	Window = 10,
2136
	Notification = 15
J
Johannes Rieken 已提交
2137
}
S
Sandeep Somavarapu 已提交
2138

J
Johannes Rieken 已提交
2139
@es5ClassCompat
S
Sandeep Somavarapu 已提交
2140 2141
export class TreeItem {

S
Sandeep Somavarapu 已提交
2142
	label?: string | vscode.TreeItemLabel;
2143
	resourceUri?: URI;
2144
	iconPath?: string | URI | { light: string | URI; dark: string | URI; };
S
Sandeep Somavarapu 已提交
2145 2146
	command?: vscode.Command;
	contextValue?: string;
2147
	tooltip?: string | vscode.MarkdownString;
S
Sandeep Somavarapu 已提交
2148

2149 2150
	constructor(label: string | vscode.TreeItemLabel, collapsibleState?: vscode.TreeItemCollapsibleState);
	constructor(resourceUri: URI, collapsibleState?: vscode.TreeItemCollapsibleState);
S
Sandeep Somavarapu 已提交
2151
	constructor(arg1: string | vscode.TreeItemLabel | URI, public collapsibleState: vscode.TreeItemCollapsibleState = TreeItemCollapsibleState.None) {
2152
		if (URI.isUri(arg1)) {
2153 2154 2155 2156
			this.resourceUri = arg1;
		} else {
			this.label = arg1;
		}
S
Sandeep Somavarapu 已提交
2157 2158 2159 2160
	}

}

S
Sandeep Somavarapu 已提交
2161
export enum TreeItemCollapsibleState {
2162
	None = 0,
S
Sandeep Somavarapu 已提交
2163 2164 2165
	Collapsed = 1,
	Expanded = 2
}
2166

2167
@es5ClassCompat
2168
export class ThemeIcon {
2169

2170 2171
	static File: ThemeIcon;
	static Folder: ThemeIcon;
2172 2173

	readonly id: string;
A
Alex Ross 已提交
2174
	readonly themeColor?: ThemeColor;
2175

A
Alex Ross 已提交
2176
	constructor(id: string, color?: ThemeColor) {
2177
		this.id = id;
A
Alex Ross 已提交
2178 2179 2180 2181 2182
		this.themeColor = color;
	}

	with(color: ThemeColor): ThemeIcon {
		return new ThemeIcon(this.id, color);
2183 2184
	}
}
2185 2186 2187
ThemeIcon.File = new ThemeIcon('file');
ThemeIcon.Folder = new ThemeIcon('folder');

2188

J
Johannes Rieken 已提交
2189
@es5ClassCompat
2190 2191 2192 2193 2194
export class ThemeColor {
	id: string;
	constructor(id: string) {
		this.id = id;
	}
2195
}
S
Sandeep Somavarapu 已提交
2196 2197 2198 2199 2200 2201 2202

export enum ConfigurationTarget {
	Global = 1,

	Workspace = 2,

	WorkspaceFolder = 3
2203
}
2204

J
Johannes Rieken 已提交
2205
@es5ClassCompat
2206 2207
export class RelativePattern implements IRelativePattern {
	base: string;
2208 2209
	baseFolder?: URI;

2210 2211
	pattern: string;

2212
	constructor(base: vscode.WorkspaceFolder | string, pattern: string) {
2213 2214 2215 2216 2217 2218 2219 2220 2221 2222
		if (typeof base !== 'string') {
			if (!base || !URI.isUri(base.uri)) {
				throw illegalArgument('base');
			}
		}

		if (typeof pattern !== 'string') {
			throw illegalArgument('pattern');
		}

2223 2224 2225 2226 2227 2228 2229
		if (typeof base === 'string') {
			this.base = base;
		} else {
			this.baseFolder = base.uri;
			this.base = base.uri.fsPath;
		}

2230
		this.pattern = pattern;
2231
	}
J
Johannes Rieken 已提交
2232
}
2233

J
Johannes Rieken 已提交
2234
@es5ClassCompat
2235 2236
export class Breakpoint {

2237 2238
	private _id: string | undefined;

2239 2240 2241
	readonly enabled: boolean;
	readonly condition?: string;
	readonly hitCondition?: string;
2242
	readonly logMessage?: string;
2243

2244
	protected constructor(enabled?: boolean, condition?: string, hitCondition?: string, logMessage?: string) {
2245 2246 2247 2248 2249 2250 2251
		this.enabled = typeof enabled === 'boolean' ? enabled : true;
		if (typeof condition === 'string') {
			this.condition = condition;
		}
		if (typeof hitCondition === 'string') {
			this.hitCondition = hitCondition;
		}
2252 2253 2254
		if (typeof logMessage === 'string') {
			this.logMessage = logMessage;
		}
2255
	}
2256 2257 2258 2259 2260 2261 2262

	get id(): string {
		if (!this._id) {
			this._id = generateUuid();
		}
		return this._id;
	}
2263 2264
}

J
Johannes Rieken 已提交
2265
@es5ClassCompat
2266 2267 2268
export class SourceBreakpoint extends Breakpoint {
	readonly location: Location;

2269 2270
	constructor(location: Location, enabled?: boolean, condition?: string, hitCondition?: string, logMessage?: string) {
		super(enabled, condition, hitCondition, logMessage);
2271 2272 2273
		if (location === null) {
			throw illegalArgument('location');
		}
2274 2275 2276 2277
		this.location = location;
	}
}

J
Johannes Rieken 已提交
2278
@es5ClassCompat
2279 2280 2281
export class FunctionBreakpoint extends Breakpoint {
	readonly functionName: string;

2282 2283
	constructor(functionName: string, enabled?: boolean, condition?: string, hitCondition?: string, logMessage?: string) {
		super(enabled, condition, hitCondition, logMessage);
2284 2285 2286
		if (!functionName) {
			throw illegalArgument('functionName');
		}
2287 2288 2289
		this.functionName = functionName;
	}
}
2290

I
isidor 已提交
2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308
@es5ClassCompat
export class DataBreakpoint extends Breakpoint {
	readonly label: string;
	readonly dataId: string;
	readonly canPersist: boolean;

	constructor(label: string, dataId: string, canPersist: boolean, enabled?: boolean, condition?: string, hitCondition?: string, logMessage?: string) {
		super(enabled, condition, hitCondition, logMessage);
		if (!dataId) {
			throw illegalArgument('dataId');
		}
		this.label = label;
		this.dataId = dataId;
		this.canPersist = canPersist;
	}
}


J
Johannes Rieken 已提交
2309
@es5ClassCompat
2310 2311 2312
export class DebugAdapterExecutable implements vscode.DebugAdapterExecutable {
	readonly command: string;
	readonly args: string[];
2313
	readonly options?: vscode.DebugAdapterExecutableOptions;
2314

2315
	constructor(command: string, args: string[], options?: vscode.DebugAdapterExecutableOptions) {
2316
		this.command = command;
2317 2318
		this.args = args || [];
		this.options = options;
2319 2320 2321
	}
}

J
Johannes Rieken 已提交
2322
@es5ClassCompat
2323 2324
export class DebugAdapterServer implements vscode.DebugAdapterServer {
	readonly port: number;
A
Andre Weinand 已提交
2325
	readonly host?: string;
2326

2327
	constructor(port: number, host?: string) {
2328
		this.port = port;
2329
		this.host = host;
2330 2331 2332
	}
}

2333 2334 2335 2336 2337 2338
@es5ClassCompat
export class DebugAdapterNamedPipeServer implements vscode.DebugAdapterNamedPipeServer {
	constructor(public readonly path: string) {
	}
}

J
Johannes Rieken 已提交
2339
@es5ClassCompat
2340 2341
export class DebugAdapterInlineImplementation implements vscode.DebugAdapterInlineImplementation {
	readonly implementation: vscode.DebugAdapter;
A
Andre Weinand 已提交
2342

2343 2344
	constructor(impl: vscode.DebugAdapter) {
		this.implementation = impl;
A
Andre Weinand 已提交
2345 2346 2347
	}
}

2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358
@es5ClassCompat
export class EvaluatableExpression implements vscode.EvaluatableExpression {
	readonly range: vscode.Range;
	readonly expression?: string;

	constructor(range: vscode.Range, expression?: string) {
		this.range = range;
		this.expression = expression;
	}
}

2359 2360 2361 2362 2363 2364 2365 2366 2367
export enum LogLevel {
	Trace = 1,
	Debug = 2,
	Info = 3,
	Warning = 4,
	Error = 5,
	Critical = 6,
	Off = 7
}
J
Johannes Rieken 已提交
2368 2369 2370

//#region file api

2371
export enum FileChangeType {
2372 2373 2374 2375 2376
	Changed = 1,
	Created = 2,
	Deleted = 3,
}

J
Johannes Rieken 已提交
2377
@es5ClassCompat
2378
export class FileSystemError extends Error {
2379

2380
	static FileExists(messageOrUri?: string | URI): FileSystemError {
2381
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.FileExists, FileSystemError.FileExists);
J
Johannes Rieken 已提交
2382
	}
2383
	static FileNotFound(messageOrUri?: string | URI): FileSystemError {
2384
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.FileNotFound, FileSystemError.FileNotFound);
J
Johannes Rieken 已提交
2385
	}
2386
	static FileNotADirectory(messageOrUri?: string | URI): FileSystemError {
2387
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.FileNotADirectory, FileSystemError.FileNotADirectory);
J
Johannes Rieken 已提交
2388
	}
2389
	static FileIsADirectory(messageOrUri?: string | URI): FileSystemError {
2390
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.FileIsADirectory, FileSystemError.FileIsADirectory);
J
Johannes Rieken 已提交
2391
	}
2392
	static NoPermissions(messageOrUri?: string | URI): FileSystemError {
2393
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.NoPermissions, FileSystemError.NoPermissions);
2394
	}
2395
	static Unavailable(messageOrUri?: string | URI): FileSystemError {
2396
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.Unavailable, FileSystemError.Unavailable);
2397
	}
2398

2399
	readonly code: string;
2400

B
Benjamin Pasero 已提交
2401
	constructor(uriOrMessage?: string | URI, code: FileSystemProviderErrorCode = FileSystemProviderErrorCode.Unknown, terminator?: Function) {
J
Johannes Rieken 已提交
2402
		super(URI.isUri(uriOrMessage) ? uriOrMessage.toString(true) : uriOrMessage);
2403

2404
		this.code = terminator?.name ?? 'Unknown';
2405

2406 2407
		// mark the error as file system provider error so that
		// we can extract the error code on the receiving side
B
Benjamin Pasero 已提交
2408
		markAsFileSystemProviderError(this, code);
2409

2410
		// workaround when extending builtin objects and when compiling to ES5, see:
C
ChaseKnowlden 已提交
2411
		// https://github.com/microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
2412 2413 2414 2415
		if (typeof (<any>Object).setPrototypeOf === 'function') {
			(<any>Object).setPrototypeOf(this, FileSystemError.prototype);
		}

J
Johannes Rieken 已提交
2416
		if (typeof Error.captureStackTrace === 'function' && typeof terminator === 'function') {
J
Johannes Rieken 已提交
2417
			// nice stack traces
J
Johannes Rieken 已提交
2418
			Error.captureStackTrace(this, terminator);
J
Johannes Rieken 已提交
2419
		}
2420 2421 2422
	}
}

J
Johannes Rieken 已提交
2423
//#endregion
2424 2425 2426

//#region folding api

J
Johannes Rieken 已提交
2427
@es5ClassCompat
2428 2429
export class FoldingRange {

2430
	start: number;
2431

2432
	end: number;
2433

2434
	kind?: FoldingRangeKind;
2435

2436 2437 2438 2439
	constructor(start: number, end: number, kind?: FoldingRangeKind) {
		this.start = start;
		this.end = end;
		this.kind = kind;
2440 2441 2442
	}
}

2443 2444 2445 2446
export enum FoldingRangeKind {
	Comment = 1,
	Imports = 2,
	Region = 3
2447 2448
}

2449
//#endregion
2450

P
Peng Lyu 已提交
2451
//#region Comment
2452 2453 2454 2455 2456 2457 2458 2459 2460
export enum CommentThreadCollapsibleState {
	/**
	 * Determines an item is collapsed
	 */
	Collapsed = 0,
	/**
	 * Determines an item is expanded
	 */
	Expanded = 1
2461
}
P
Peng Lyu 已提交
2462 2463 2464 2465 2466 2467

export enum CommentMode {
	Editing = 0,
	Preview = 1
}

P
Peng Lyu 已提交
2468
//#endregion
2469

A
WIP  
Alexandru Dima 已提交
2470 2471
//#region Semantic Coloring

2472
export class SemanticTokensLegend {
A
WIP  
Alexandru Dima 已提交
2473 2474 2475
	public readonly tokenTypes: string[];
	public readonly tokenModifiers: string[];

A
Alex Dima 已提交
2476
	constructor(tokenTypes: string[], tokenModifiers: string[] = []) {
A
WIP  
Alexandru Dima 已提交
2477 2478 2479 2480 2481
		this.tokenTypes = tokenTypes;
		this.tokenModifiers = tokenModifiers;
	}
}

2482
function isStrArrayOrUndefined(arg: any): arg is string[] | undefined {
2483
	return ((typeof arg === 'undefined') || isStringArray(arg));
2484 2485
}

2486
export class SemanticTokensBuilder {
A
WIP  
Alexandru Dima 已提交
2487

2488 2489
	private _prevLine: number;
	private _prevChar: number;
2490
	private _dataIsSortedAndDeltaEncoded: boolean;
2491 2492
	private _data: number[];
	private _dataLen: number;
2493 2494 2495
	private _tokenTypeStrToInt: Map<string, number>;
	private _tokenModifierStrToInt: Map<string, number>;
	private _hasLegend: boolean;
2496

2497
	constructor(legend?: vscode.SemanticTokensLegend) {
2498 2499
		this._prevLine = 0;
		this._prevChar = 0;
2500
		this._dataIsSortedAndDeltaEncoded = true;
2501 2502
		this._data = [];
		this._dataLen = 0;
2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514
		this._tokenTypeStrToInt = new Map<string, number>();
		this._tokenModifierStrToInt = new Map<string, number>();
		this._hasLegend = false;
		if (legend) {
			this._hasLegend = true;
			for (let i = 0, len = legend.tokenTypes.length; i < len; i++) {
				this._tokenTypeStrToInt.set(legend.tokenTypes[i], i);
			}
			for (let i = 0, len = legend.tokenModifiers.length; i < len; i++) {
				this._tokenModifierStrToInt.set(legend.tokenModifiers[i], i);
			}
		}
2515 2516
	}

A
Alex Dima 已提交
2517
	public push(line: number, char: number, length: number, tokenType: number, tokenModifiers?: number): void;
2518 2519
	public push(range: Range, tokenType: string, tokenModifiers?: string[]): void;
	public push(arg0: any, arg1: any, arg2: any, arg3?: any, arg4?: any): void {
A
Alex Dima 已提交
2520 2521 2522 2523
		if (typeof arg0 === 'number' && typeof arg1 === 'number' && typeof arg2 === 'number' && typeof arg3 === 'number' && (typeof arg4 === 'number' || typeof arg4 === 'undefined')) {
			if (typeof arg4 === 'undefined') {
				arg4 = 0;
			}
2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590
			// 1st overload
			return this._pushEncoded(arg0, arg1, arg2, arg3, arg4);
		}
		if (Range.isRange(arg0) && typeof arg1 === 'string' && isStrArrayOrUndefined(arg2)) {
			// 2nd overload
			return this._push(arg0, arg1, arg2);
		}
		throw illegalArgument();
	}

	private _push(range: vscode.Range, tokenType: string, tokenModifiers?: string[]): void {
		if (!this._hasLegend) {
			throw new Error('Legend must be provided in constructor');
		}
		if (range.start.line !== range.end.line) {
			throw new Error('`range` cannot span multiple lines');
		}
		if (!this._tokenTypeStrToInt.has(tokenType)) {
			throw new Error('`tokenType` is not in the provided legend');
		}
		const line = range.start.line;
		const char = range.start.character;
		const length = range.end.character - range.start.character;
		const nTokenType = this._tokenTypeStrToInt.get(tokenType)!;
		let nTokenModifiers = 0;
		if (tokenModifiers) {
			for (const tokenModifier of tokenModifiers) {
				if (!this._tokenModifierStrToInt.has(tokenModifier)) {
					throw new Error('`tokenModifier` is not in the provided legend');
				}
				const nTokenModifier = this._tokenModifierStrToInt.get(tokenModifier)!;
				nTokenModifiers |= (1 << nTokenModifier) >>> 0;
			}
		}
		this._pushEncoded(line, char, length, nTokenType, nTokenModifiers);
	}

	private _pushEncoded(line: number, char: number, length: number, tokenType: number, tokenModifiers: number): void {
		if (this._dataIsSortedAndDeltaEncoded && (line < this._prevLine || (line === this._prevLine && char < this._prevChar))) {
			// push calls were ordered and are no longer ordered
			this._dataIsSortedAndDeltaEncoded = false;

			// Remove delta encoding from data
			const tokenCount = (this._data.length / 5) | 0;
			let prevLine = 0;
			let prevChar = 0;
			for (let i = 0; i < tokenCount; i++) {
				let line = this._data[5 * i];
				let char = this._data[5 * i + 1];

				if (line === 0) {
					// on the same line as previous token
					line = prevLine;
					char += prevChar;
				} else {
					// on a different line than previous token
					line += prevLine;
				}

				this._data[5 * i] = line;
				this._data[5 * i + 1] = char;

				prevLine = line;
				prevChar = char;
			}
		}

2591 2592
		let pushLine = line;
		let pushChar = char;
2593
		if (this._dataIsSortedAndDeltaEncoded && this._dataLen > 0) {
2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609
			pushLine -= this._prevLine;
			if (pushLine === 0) {
				pushChar -= this._prevChar;
			}
		}

		this._data[this._dataLen++] = pushLine;
		this._data[this._dataLen++] = pushChar;
		this._data[this._dataLen++] = length;
		this._data[this._dataLen++] = tokenType;
		this._data[this._dataLen++] = tokenModifiers;

		this._prevLine = line;
		this._prevChar = char;
	}

2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653
	private static _sortAndDeltaEncode(data: number[]): Uint32Array {
		let pos: number[] = [];
		const tokenCount = (data.length / 5) | 0;
		for (let i = 0; i < tokenCount; i++) {
			pos[i] = i;
		}
		pos.sort((a, b) => {
			const aLine = data[5 * a];
			const bLine = data[5 * b];
			if (aLine === bLine) {
				const aChar = data[5 * a + 1];
				const bChar = data[5 * b + 1];
				return aChar - bChar;
			}
			return aLine - bLine;
		});
		const result = new Uint32Array(data.length);
		let prevLine = 0;
		let prevChar = 0;
		for (let i = 0; i < tokenCount; i++) {
			const srcOffset = 5 * pos[i];
			const line = data[srcOffset + 0];
			const char = data[srcOffset + 1];
			const length = data[srcOffset + 2];
			const tokenType = data[srcOffset + 3];
			const tokenModifiers = data[srcOffset + 4];

			const pushLine = line - prevLine;
			const pushChar = (pushLine === 0 ? char - prevChar : char);

			const dstOffset = 5 * i;
			result[dstOffset + 0] = pushLine;
			result[dstOffset + 1] = pushChar;
			result[dstOffset + 2] = length;
			result[dstOffset + 3] = tokenType;
			result[dstOffset + 4] = tokenModifiers;

			prevLine = line;
			prevChar = char;
		}

		return result;
	}

2654
	public build(resultId?: string): SemanticTokens {
2655 2656 2657
		if (!this._dataIsSortedAndDeltaEncoded) {
			return new SemanticTokens(SemanticTokensBuilder._sortAndDeltaEncode(this._data), resultId);
		}
2658
		return new SemanticTokens(new Uint32Array(this._data), resultId);
2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679
	}
}

export class SemanticTokens {
	readonly resultId?: string;
	readonly data: Uint32Array;

	constructor(data: Uint32Array, resultId?: string) {
		this.resultId = resultId;
		this.data = data;
	}
}

export class SemanticTokensEdit {
	readonly start: number;
	readonly deleteCount: number;
	readonly data?: Uint32Array;

	constructor(start: number, deleteCount: number, data?: Uint32Array) {
		this.start = start;
		this.deleteCount = deleteCount;
A
WIP  
Alexandru Dima 已提交
2680 2681 2682 2683
		this.data = data;
	}
}

2684 2685 2686
export class SemanticTokensEdits {
	readonly resultId?: string;
	readonly edits: SemanticTokensEdit[];
A
WIP  
Alexandru Dima 已提交
2687

2688 2689 2690
	constructor(edits: SemanticTokensEdit[], resultId?: string) {
		this.resultId = resultId;
		this.edits = edits;
A
WIP  
Alexandru Dima 已提交
2691 2692 2693 2694 2695
	}
}

//#endregion

2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709
//#region debug
export enum DebugConsoleMode {
	/**
	 * Debug session should have a separate debug console.
	 */
	Separate = 0,

	/**
	 * Debug session should share debug console with its parent session.
	 * This value has no effect for sessions which do not have a parent session.
	 */
	MergeWithParent = 1
}

2710
export enum DebugConfigurationProviderTriggerKind {
A
Andre Weinand 已提交
2711
	/**
2712
	 *	`DebugConfigurationProvider.provideDebugConfigurations` is called to provide the initial debug configurations for a newly created launch.json.
A
Andre Weinand 已提交
2713 2714 2715
	 */
	Initial = 1,
	/**
2716
	 * `DebugConfigurationProvider.provideDebugConfigurations` is called to provide dynamically generated debug configurations when the user asks for them through the UI (e.g. via the "Select and Start Debugging" command).
A
Andre Weinand 已提交
2717 2718 2719 2720
	 */
	Dynamic = 2
}

2721 2722
//#endregion

J
Johannes Rieken 已提交
2723
@es5ClassCompat
2724 2725 2726 2727 2728 2729
export class QuickInputButtons {

	static readonly Back: vscode.QuickInputButton = { iconPath: 'back.svg' };

	private constructor() { }
}
2730

2731 2732 2733 2734
export enum ExtensionKind {
	UI = 1,
	Workspace = 2
}
2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752

export class Decoration {

	static validate(d: Decoration): void {
		if (d.letter && d.letter.length !== 1) {
			throw new Error(`The 'letter'-property must be undefined or a single character`);
		}
		if (!d.bubble && !d.color && !d.letter && !d.priority && !d.title) {
			throw new Error(`The decoration is empty`);
		}
	}

	letter?: string;
	title?: string;
	color?: vscode.ThemeColor;
	priority?: number;
	bubble?: boolean;
}
2753

M
Martin Aeschlimann 已提交
2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768
//#region Theming

@es5ClassCompat
export class ColorTheme implements vscode.ColorTheme {
	constructor(public readonly kind: ColorThemeKind) {
	}
}

export enum ColorThemeKind {
	Light = 1,
	Dark = 2,
	HighContrast = 3
}

//#endregion Theming
2769

R
rebornix 已提交
2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782
//#region Notebook

export enum CellKind {
	Markdown = 1,
	Code = 2
}

export enum CellOutputKind {
	Text = 1,
	Error = 2,
	Rich = 3
}

R
Rob Lourens 已提交
2783 2784 2785 2786 2787 2788 2789
export enum NotebookCellRunState {
	Running = 1,
	Idle = 2,
	Success = 3,
	Error = 4
}

R
Rob Lourens 已提交
2790 2791 2792 2793 2794
export enum NotebookRunState {
	Running = 1,
	Idle = 2
}

2795 2796 2797 2798 2799
export enum NotebookCellStatusBarAlignment {
	Left = 1,
	Right = 2
}

R
rebornix 已提交
2800 2801 2802 2803 2804 2805
export enum NotebookEditorRevealType {
	Default = 0,
	InCenter = 1,
	InCenterIfOutsideViewport = 2
}

2806

R
rebornix 已提交
2807 2808
//#endregion

2809 2810 2811 2812
//#region Timeline

@es5ClassCompat
export class TimelineItem implements vscode.TimelineItem {
E
Eric Amodio 已提交
2813
	constructor(public label: string, public timestamp: number) { }
2814 2815 2816
}

//#endregion Timeline
2817 2818 2819 2820 2821 2822 2823 2824

//#region ExtensionContext

export enum ExtensionMode {
	/**
	 * The extension is installed normally (for example, from the marketplace
	 * or VSIX) in VS Code.
	 */
C
Connor Peet 已提交
2825
	Production = 1,
2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839

	/**
	 * The extension is running from an `--extensionDevelopmentPath` provided
	 * when launching VS Code.
	 */
	Development = 2,

	/**
	 * The extension is running from an `--extensionDevelopmentPath` and
	 * the extension host is running unit tests.
	 */
	Test = 3,
}

2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850
export enum ExtensionRuntime {
	/**
	 * The extension is running in a NodeJS extension host. Runtime access to NodeJS APIs is available.
	 */
	Node = 1,
	/**
	 * The extension is running in a Webworker extension host. Runtime access is limited to Webworker APIs.
	 */
	Webworker = 2
}

2851
//#endregion ExtensionContext
2852

2853 2854 2855 2856 2857 2858
export enum StandardTokenType {
	Other = 0,
	Comment = 1,
	String = 2,
	RegEx = 4
}