extHostTypes.ts 56.0 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 { coalesce, equals } from 'vs/base/common/arrays';
7
import { illegalArgument } from 'vs/base/common/errors';
8
import { IRelativePattern } from 'vs/base/common/glob';
9
import { isMarkdownString } from 'vs/base/common/htmlContent';
10
import { values } from 'vs/base/common/map';
11 12
import { startsWith } from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
13
import { generateUuid } from 'vs/base/common/uuid';
14
import * as vscode from 'vscode';
15
import { FileSystemProviderErrorCode, markAsFileSystemProviderError } from 'vs/platform/files/common/files';
A
Tweaks  
Alex Dima 已提交
16
import { RemoteAuthorityResolverErrorCode } from 'vs/platform/remote/common/remoteAuthorityResolver';
E
Erich Gamma 已提交
17

J
Johannes Rieken 已提交
18 19 20
function es5ClassCompat(target: Function): any {
	///@ts-ignore
	function _() { return Reflect.construct(target, arguments, this.constructor); }
J
Johannes Rieken 已提交
21
	Object.defineProperty(_, 'name', Object.getOwnPropertyDescriptor(target, 'name')!);
J
Johannes Rieken 已提交
22 23 24 25 26 27 28 29
	///@ts-ignore
	Object.setPrototypeOf(_, target);
	///@ts-ignore
	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
	private _callOnDispose?: () => any;
E
Erich Gamma 已提交
47

48
	constructor(callOnDispose: () => any) {
E
Erich Gamma 已提交
49 50 51 52 53 54 55 56 57 58 59
		this._callOnDispose = callOnDispose;
	}

	dispose(): any {
		if (typeof this._callOnDispose === 'function') {
			this._callOnDispose();
			this._callOnDispose = undefined;
		}
	}
}

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 337
	with(change: { start?: Position, end?: Position }): Range;
	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 471 472 473 474 475 476 477
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:
		// https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
		if (typeof (<any>Object).setPrototypeOf === 'function') {
			(<any>Object).setPrototypeOf(this, RemoteAuthorityResolverError.prototype);
		}
	}
}

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

J
Johannes Rieken 已提交
483
@es5ClassCompat
E
Erich Gamma 已提交
484 485
export class TextEdit {

486 487 488 489 490 491 492 493 494 495 496
	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 已提交
497 498 499 500 501 502 503 504 505 506 507 508
	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, '');
	}

509
	static setEndOfLine(eol: EndOfLine): TextEdit {
510
		const ret = new TextEdit(new Range(new Position(0, 0), new Position(0, 0)), '');
511 512 513
		ret.newEol = eol;
		return ret;
	}
E
Erich Gamma 已提交
514

515
	protected _range: Range;
516
	protected _newText: string | null;
J
Johannes Rieken 已提交
517
	protected _newEol?: EndOfLine;
E
Erich Gamma 已提交
518 519 520 521 522 523

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

	set range(value: Range) {
524
		if (value && !Range.isRange(value)) {
B
Benjamin Pasero 已提交
525
			throw illegalArgument('range');
E
Erich Gamma 已提交
526 527 528 529 530 531 532 533
		}
		this._range = value;
	}

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

534 535 536 537
	set newText(value: string) {
		if (value && typeof value !== 'string') {
			throw illegalArgument('newText');
		}
E
Erich Gamma 已提交
538 539 540
		this._newText = value;
	}

J
Johannes Rieken 已提交
541
	get newEol(): EndOfLine | undefined {
542 543 544
		return this._newEol;
	}

J
Johannes Rieken 已提交
545
	set newEol(value: EndOfLine | undefined) {
546 547 548 549 550 551
		if (value && typeof value !== 'number') {
			throw illegalArgument('newEol');
		}
		this._newEol = value;
	}

552
	constructor(range: Range, newText: string | null) {
J
Johannes Rieken 已提交
553
		this._range = range;
554
		this._newText = newText;
E
Erich Gamma 已提交
555
	}
556 557 558 559

	toJSON(): any {
		return {
			range: this.range,
560 561
			newText: this.newText,
			newEol: this._newEol
562 563
		};
	}
E
Erich Gamma 已提交
564 565 566
}


567 568 569
export interface IFileOperationOptions {
	overwrite?: boolean;
	ignoreIfExists?: boolean;
J
Johannes Rieken 已提交
570
	ignoreIfNotExists?: boolean;
571 572 573
	recursive?: boolean;
}

574 575
export interface IFileOperation {
	_type: 1;
576 577
	from?: URI;
	to?: URI;
578
	options?: IFileOperationOptions;
579 580 581 582 583 584 585
}

export interface IFileTextEdit {
	_type: 2;
	uri: URI;
	edit: TextEdit;
}
E
Erich Gamma 已提交
586

J
Johannes Rieken 已提交
587
@es5ClassCompat
588 589
export class WorkspaceEdit implements vscode.WorkspaceEdit {

590
	private _edits = new Array<IFileOperation | IFileTextEdit>();
591

J
Johannes Rieken 已提交
592
	renameFile(from: vscode.Uri, to: vscode.Uri, options?: { overwrite?: boolean, ignoreIfExists?: boolean }): void {
593
		this._edits.push({ _type: 1, from, to, options });
J
Johannes Rieken 已提交
594
	}
595

596 597
	createFile(uri: vscode.Uri, options?: { overwrite?: boolean, ignoreIfExists?: boolean }): void {
		this._edits.push({ _type: 1, from: undefined, to: uri, options });
J
Johannes Rieken 已提交
598
	}
599

J
Johannes Rieken 已提交
600
	deleteFile(uri: vscode.Uri, options?: { recursive?: boolean, ignoreIfNotExists?: boolean }): void {
601
		this._edits.push({ _type: 1, from: uri, to: undefined, options });
J
Johannes Rieken 已提交
602
	}
603

604
	replace(uri: URI, range: Range, newText: string): void {
605
		this._edits.push({ _type: 2, uri, edit: new TextEdit(range, newText) });
E
Erich Gamma 已提交
606 607
	}

608
	insert(resource: URI, position: Position, newText: string): void {
E
Erich Gamma 已提交
609 610 611
		this.replace(resource, new Range(position, position), newText);
	}

612
	delete(resource: URI, range: Range): void {
E
Erich Gamma 已提交
613 614 615
		this.replace(resource, range, '');
	}

616
	has(uri: URI): boolean {
617 618 619 620 621 622
		for (const edit of this._edits) {
			if (edit._type === 2 && edit.uri.toString() === uri.toString()) {
				return true;
			}
		}
		return false;
E
Erich Gamma 已提交
623 624
	}

625
	set(uri: URI, edits: TextEdit[]): void {
J
Johannes Rieken 已提交
626
		if (!edits) {
627 628 629 630
			// remove all text edits for `uri`
			for (let i = 0; i < this._edits.length; i++) {
				const element = this._edits[i];
				if (element._type === 2 && element.uri.toString() === uri.toString()) {
631
					this._edits[i] = undefined!; // will be coalesced down below
632 633 634
				}
			}
			this._edits = coalesce(this._edits);
E
Erich Gamma 已提交
635
		} else {
636 637 638 639 640 641
			// append edit to the end
			for (const edit of edits) {
				if (edit) {
					this._edits.push({ _type: 2, uri, edit });
				}
			}
E
Erich Gamma 已提交
642 643 644
		}
	}

645
	get(uri: URI): TextEdit[] {
646
		const res: TextEdit[] = [];
647 648 649 650 651 652
		for (let candidate of this._edits) {
			if (candidate._type === 2 && candidate.uri.toString() === uri.toString()) {
				res.push(candidate.edit);
			}
		}
		return res;
E
Erich Gamma 已提交
653 654
	}

655
	entries(): [URI, TextEdit[]][] {
656
		const textEdits = new Map<string, [URI, TextEdit[]]>();
657 658 659 660 661 662 663 664 665 666 667
		for (let candidate of this._edits) {
			if (candidate._type === 2) {
				let textEdit = textEdits.get(candidate.uri.toString());
				if (!textEdit) {
					textEdit = [candidate.uri, []];
					textEdits.set(candidate.uri.toString(), textEdit);
				}
				textEdit[1].push(candidate.edit);
			}
		}
		return values(textEdits);
668 669
	}

670
	_allEntries(): ([URI, TextEdit[]] | [URI?, URI?, IFileOperationOptions?])[] {
671
		const res: ([URI, TextEdit[]] | [URI?, URI?, IFileOperationOptions?])[] = [];
672 673
		for (let edit of this._edits) {
			if (edit._type === 1) {
674
				res.push([edit.from, edit.to, edit.options]);
675 676 677 678
			} else {
				res.push([edit.uri, [edit.edit]]);
			}
		}
J
Johannes Rieken 已提交
679
		return res;
680 681
	}

E
Erich Gamma 已提交
682
	get size(): number {
683
		return this.entries().length;
E
Erich Gamma 已提交
684
	}
685 686

	toJSON(): any {
J
Johannes Rieken 已提交
687
		return this.entries();
688
	}
E
Erich Gamma 已提交
689 690
}

J
Johannes Rieken 已提交
691
@es5ClassCompat
692 693
export class SnippetString {

J
Joel Day 已提交
694 695 696 697 698 699 700 701 702 703
	static isSnippetString(thing: any): thing is SnippetString {
		if (thing instanceof SnippetString) {
			return true;
		}
		if (!thing) {
			return false;
		}
		return typeof (<SnippetString>thing).value === 'string';
	}

704 705 706 707
	private static _escape(value: string): string {
		return value.replace(/\$|}|\\/g, '\\$&');
	}

708 709
	private _tabstop: number = 1;

710 711
	value: string;

712 713 714 715 716
	constructor(value?: string) {
		this.value = value || '';
	}

	appendText(string: string): SnippetString {
717
		this.value += SnippetString._escape(string);
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
		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 {
736
			value = SnippetString._escape(value);
737 738 739 740 741 742 743 744
		}

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

745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
		return this;
	}

	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 += '}';


770
		return this;
771 772 773
	}
}

774 775
export enum DiagnosticTag {
	Unnecessary = 1,
776
	Deprecated = 2
777 778
}

E
Erich Gamma 已提交
779 780 781 782 783 784 785
export enum DiagnosticSeverity {
	Hint = 3,
	Information = 2,
	Warning = 1,
	Error = 0
}

J
Johannes Rieken 已提交
786
@es5ClassCompat
E
Erich Gamma 已提交
787 788
export class Location {

789 790 791 792 793 794 795 796 797 798 799
	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 已提交
800
	uri: URI;
J
Johannes Rieken 已提交
801
	range!: Range;
E
Erich Gamma 已提交
802

803
	constructor(uri: URI, rangeOrPosition: Range | Position) {
E
Erich Gamma 已提交
804 805
		this.uri = uri;

806 807 808 809 810 811
		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 已提交
812 813 814 815
		} else {
			throw new Error('Illegal argument');
		}
	}
816 817 818 819 820 821 822

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

J
Johannes Rieken 已提交
825
@es5ClassCompat
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
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;
	}
845 846 847 848 849 850 851 852 853 854 855 856

	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();
	}
857 858
}

J
Johannes Rieken 已提交
859
@es5ClassCompat
E
Erich Gamma 已提交
860 861 862 863 864
export class Diagnostic {

	range: Range;
	message: string;
	severity: DiagnosticSeverity;
J
Johannes Rieken 已提交
865 866 867
	source?: string;
	code?: string | number;
	relatedInformation?: DiagnosticRelatedInformation[];
868
	tags?: DiagnosticTag[];
E
Erich Gamma 已提交
869 870 871 872 873 874

	constructor(range: Range, message: string, severity: DiagnosticSeverity = DiagnosticSeverity.Error) {
		this.range = range;
		this.message = message;
		this.severity = severity;
	}
875 876 877 878 879 880 881 882

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

886
	static isEqual(a: Diagnostic | undefined, b: Diagnostic | undefined): boolean {
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901
		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 已提交
902 903
}

J
Johannes Rieken 已提交
904
@es5ClassCompat
E
Erich Gamma 已提交
905 906
export class Hover {

907
	public contents: vscode.MarkdownString[] | vscode.MarkedString[];
908
	public range: Range | undefined;
E
Erich Gamma 已提交
909

910 911 912 913
	constructor(
		contents: vscode.MarkdownString | vscode.MarkedString | vscode.MarkdownString[] | vscode.MarkedString[],
		range?: Range
	) {
E
Erich Gamma 已提交
914
		if (!contents) {
915
			throw new Error('Illegal argument, contents must be defined');
E
Erich Gamma 已提交
916 917
		}
		if (Array.isArray(contents)) {
918 919 920
			this.contents = <vscode.MarkdownString[] | vscode.MarkedString[]>contents;
		} else if (isMarkdownString(contents)) {
			this.contents = [contents];
E
Erich Gamma 已提交
921 922 923 924 925 926 927 928
		} else {
			this.contents = [contents];
		}
		this.range = range;
	}
}

export enum DocumentHighlightKind {
929 930 931
	Text = 0,
	Read = 1,
	Write = 2
E
Erich Gamma 已提交
932 933
}

J
Johannes Rieken 已提交
934
@es5ClassCompat
E
Erich Gamma 已提交
935 936 937 938 939 940 941 942 943
export class DocumentHighlight {

	range: Range;
	kind: DocumentHighlightKind;

	constructor(range: Range, kind: DocumentHighlightKind = DocumentHighlightKind.Text) {
		this.range = range;
		this.kind = kind;
	}
944 945 946 947 948

	toJSON(): any {
		return {
			range: this.range,
			kind: DocumentHighlightKind[this.kind]
B
Benjamin Pasero 已提交
949
		};
950
	}
E
Erich Gamma 已提交
951 952 953
}

export enum SymbolKind {
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
	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,
976 977
	Struct = 22,
	Event = 23,
978 979
	Operator = 24,
	TypeParameter = 25
E
Erich Gamma 已提交
980 981
}

982 983 984 985
export enum SymbolTag {
	Deprecated = 1,
}

J
Johannes Rieken 已提交
986
@es5ClassCompat
E
Erich Gamma 已提交
987 988
export class SymbolInformation {

J
Johannes Rieken 已提交
989 990 991 992 993 994
	static validate(candidate: SymbolInformation): void {
		if (!candidate.name) {
			throw new Error('name must not be falsy');
		}
	}

E
Erich Gamma 已提交
995
	name: string;
J
Johannes Rieken 已提交
996
	location!: Location;
E
Erich Gamma 已提交
997
	kind: SymbolKind;
998
	tags?: SymbolTag[];
999
	containerName: string | undefined;
E
Erich Gamma 已提交
1000

M
Matt Bierner 已提交
1001
	constructor(name: string, kind: SymbolKind, containerName: string | undefined, location: Location);
1002
	constructor(name: string, kind: SymbolKind, range: Range, uri?: URI, containerName?: string);
M
Matt Bierner 已提交
1003
	constructor(name: string, kind: SymbolKind, rangeOrContainer: string | undefined | Range, locationOrUri?: Location | URI, containerName?: string) {
E
Erich Gamma 已提交
1004 1005 1006
		this.name = name;
		this.kind = kind;
		this.containerName = containerName;
1007 1008 1009 1010 1011 1012 1013

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

		if (locationOrUri instanceof Location) {
			this.location = locationOrUri;
1014
		} else if (rangeOrContainer instanceof Range) {
1015
			this.location = new Location(locationOrUri!, rangeOrContainer);
1016
		}
J
Johannes Rieken 已提交
1017 1018

		SymbolInformation.validate(this);
E
Erich Gamma 已提交
1019
	}
1020 1021 1022 1023 1024 1025 1026

	toJSON(): any {
		return {
			name: this.name,
			kind: SymbolKind[this.kind],
			location: this.location,
			containerName: this.containerName
B
Benjamin Pasero 已提交
1027
		};
1028
	}
E
Erich Gamma 已提交
1029 1030
}

J
Johannes Rieken 已提交
1031
@es5ClassCompat
1032
export class DocumentSymbol {
J
Johannes Rieken 已提交
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045

	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);
		}
	}

1046
	name: string;
1047
	detail: string;
1048
	kind: SymbolKind;
1049
	tags?: SymbolTag[];
1050 1051
	range: Range;
	selectionRange: Range;
1052
	children: DocumentSymbol[];
1053

1054
	constructor(name: string, detail: string, kind: SymbolKind, range: Range, selectionRange: Range) {
1055
		this.name = name;
1056
		this.detail = detail;
1057
		this.kind = kind;
1058 1059
		this.range = range;
		this.selectionRange = selectionRange;
1060
		this.children = [];
1061

J
Johannes Rieken 已提交
1062
		DocumentSymbol.validate(this);
1063 1064 1065
	}
}

1066

1067 1068 1069 1070 1071
export enum CodeActionTrigger {
	Automatic = 1,
	Manual = 2,
}

J
Johannes Rieken 已提交
1072
@es5ClassCompat
1073 1074 1075 1076 1077
export class CodeAction {
	title: string;

	command?: vscode.Command;

1078
	edit?: WorkspaceEdit;
1079

M
Matt Bierner 已提交
1080
	diagnostics?: Diagnostic[];
1081

1082
	kind?: CodeActionKind;
M
Matt Bierner 已提交
1083

1084 1085
	isPreferred?: boolean;

1086
	constructor(title: string, kind?: CodeActionKind) {
1087
		this.title = title;
1088
		this.kind = kind;
1089 1090 1091
	}
}

M
Matt Bierner 已提交
1092

J
Johannes Rieken 已提交
1093
@es5ClassCompat
M
Matt Bierner 已提交
1094 1095 1096
export class CodeActionKind {
	private static readonly sep = '.';

1097 1098 1099 1100 1101 1102 1103 1104 1105
	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 已提交
1106 1107 1108 1109 1110 1111 1112 1113 1114

	constructor(
		public readonly value: string
	) { }

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

M
Matt Bierner 已提交
1115 1116 1117 1118
	public intersects(other: CodeActionKind): boolean {
		return this.contains(other) || other.contains(this);
	}

M
Matt Bierner 已提交
1119 1120 1121 1122
	public contains(other: CodeActionKind): boolean {
		return this.value === other.value || startsWith(other.value, this.value + CodeActionKind.sep);
	}
}
1123 1124 1125 1126 1127 1128 1129 1130 1131
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 已提交
1132

J
Johannes Rieken 已提交
1133
@es5ClassCompat
1134 1135 1136
export class SelectionRange {

	range: Range;
1137
	parent?: SelectionRange;
1138

1139
	constructor(range: Range, parent?: SelectionRange) {
1140
		this.range = range;
1141
		this.parent = parent;
1142 1143 1144 1145

		if (parent && !parent.range.contains(this.range)) {
			throw new Error('Invalid argument: parent must contain this range');
		}
1146 1147 1148
	}
}

1149 1150 1151 1152
export class CallHierarchyItem {
	kind: SymbolKind;
	name: string;
	detail?: string;
1153
	uri: URI;
1154 1155 1156
	range: Range;
	selectionRange: Range;

1157
	constructor(kind: SymbolKind, name: string, detail: string, uri: URI, range: Range, selectionRange: Range) {
1158 1159 1160
		this.kind = kind;
		this.name = name;
		this.detail = detail;
1161
		this.uri = uri;
1162 1163 1164 1165 1166
		this.range = range;
		this.selectionRange = selectionRange;
	}
}

J
jrieken 已提交
1167
export class CallHierarchyIncomingCall {
J
jrieken 已提交
1168

J
jrieken 已提交
1169 1170
	source: vscode.CallHierarchyItem;
	sourceRanges: vscode.Range[];
J
jrieken 已提交
1171

J
jrieken 已提交
1172
	constructor(item: vscode.CallHierarchyItem, sourceRanges: vscode.Range[]) {
J
jrieken 已提交
1173 1174 1175 1176
		this.sourceRanges = sourceRanges;
		this.source = item;
	}
}
J
jrieken 已提交
1177
export class CallHierarchyOutgoingCall {
J
jrieken 已提交
1178

J
jrieken 已提交
1179 1180
	target: vscode.CallHierarchyItem;
	sourceRanges: vscode.Range[];
J
jrieken 已提交
1181

J
jrieken 已提交
1182
	constructor(item: vscode.CallHierarchyItem, sourceRanges: vscode.Range[]) {
J
jrieken 已提交
1183 1184 1185 1186 1187
		this.sourceRanges = sourceRanges;
		this.target = item;
	}
}

J
Johannes Rieken 已提交
1188
@es5ClassCompat
E
Erich Gamma 已提交
1189 1190 1191 1192
export class CodeLens {

	range: Range;

1193
	command: vscode.Command | undefined;
E
Erich Gamma 已提交
1194 1195 1196

	constructor(range: Range, command?: vscode.Command) {
		this.range = range;
1197
		this.command = command;
E
Erich Gamma 已提交
1198 1199 1200 1201 1202 1203 1204
	}

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

R
Rob DeLine 已提交
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217

export class CodeInset {

	range: Range;
	height?: number;

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


J
Johannes Rieken 已提交
1218
@es5ClassCompat
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
export class MarkdownString {

	value: string;
	isTrusted?: boolean;

	constructor(value?: string) {
		this.value = value || '';
	}

	appendText(value: string): MarkdownString {
		// escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
P
Pine Wu 已提交
1230 1231 1232
		this.value += value
			.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&')
			.replace('\n', '\n\n');
1233 1234 1235 1236 1237 1238 1239
		return this;
	}

	appendMarkdown(value: string): MarkdownString {
		this.value += value;
		return this;
	}
J
Johannes Rieken 已提交
1240 1241 1242 1243 1244 1245 1246 1247 1248

	appendCodeblock(code: string, language: string = ''): MarkdownString {
		this.value += '\n```';
		this.value += language;
		this.value += '\n';
		this.value += code;
		this.value += '\n```\n';
		return this;
	}
1249 1250
}

J
Johannes Rieken 已提交
1251
@es5ClassCompat
E
Erich Gamma 已提交
1252 1253
export class ParameterInformation {

1254
	label: string | [number, number];
1255
	documentation?: string | MarkdownString;
E
Erich Gamma 已提交
1256

1257
	constructor(label: string | [number, number], documentation?: string | MarkdownString) {
E
Erich Gamma 已提交
1258 1259 1260 1261 1262
		this.label = label;
		this.documentation = documentation;
	}
}

J
Johannes Rieken 已提交
1263
@es5ClassCompat
E
Erich Gamma 已提交
1264 1265 1266
export class SignatureInformation {

	label: string;
1267
	documentation?: string | MarkdownString;
E
Erich Gamma 已提交
1268 1269
	parameters: ParameterInformation[];

1270
	constructor(label: string, documentation?: string | MarkdownString) {
E
Erich Gamma 已提交
1271 1272 1273 1274 1275 1276
		this.label = label;
		this.documentation = documentation;
		this.parameters = [];
	}
}

J
Johannes Rieken 已提交
1277
@es5ClassCompat
E
Erich Gamma 已提交
1278 1279 1280
export class SignatureHelp {

	signatures: SignatureInformation[];
J
Johannes Rieken 已提交
1281 1282
	activeSignature: number = 0;
	activeParameter: number = 0;
E
Erich Gamma 已提交
1283 1284 1285 1286 1287 1288

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

M
Matt Bierner 已提交
1289
export enum SignatureHelpTriggerKind {
1290 1291
	Invoke = 1,
	TriggerCharacter = 2,
1292
	ContentChange = 3,
1293 1294
}

M
Matt Bierner 已提交
1295 1296
export enum CompletionTriggerKind {
	Invoke = 0,
1297 1298
	TriggerCharacter = 1,
	TriggerForIncompleteCompletions = 2
M
Matt Bierner 已提交
1299 1300 1301
}

export interface CompletionContext {
1302 1303
	readonly triggerKind: CompletionTriggerKind;
	readonly triggerCharacter?: string;
M
Matt Bierner 已提交
1304 1305
}

E
Erich Gamma 已提交
1306
export enum CompletionItemKind {
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
	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,
1324
	Reference = 17,
1325 1326
	Folder = 18,
	EnumMember = 19,
1327
	Constant = 20,
1328 1329
	Struct = 21,
	Event = 22,
1330 1331
	Operator = 23,
	TypeParameter = 24
E
Erich Gamma 已提交
1332 1333
}

1334
export enum CompletionItemTag {
1335 1336 1337
	Deprecated = 1,
}

J
Johannes Rieken 已提交
1338
@es5ClassCompat
1339
export class CompletionItem implements vscode.CompletionItem {
E
Erich Gamma 已提交
1340 1341

	label: string;
J
Johannes Rieken 已提交
1342
	kind?: CompletionItemKind;
1343
	tags?: CompletionItemTag[];
1344 1345 1346 1347 1348
	detail?: string;
	documentation?: string | MarkdownString;
	sortText?: string;
	filterText?: string;
	preselect?: boolean;
J
Johannes Rieken 已提交
1349
	insertText?: string | SnippetString;
1350
	keepWhitespace?: boolean;
J
Johannes Rieken 已提交
1351
	range?: Range;
1352
	commitCharacters?: string[];
J
Johannes Rieken 已提交
1353 1354 1355
	textEdit?: TextEdit;
	additionalTextEdits?: TextEdit[];
	command?: vscode.Command;
E
Erich Gamma 已提交
1356

1357
	constructor(label: string, kind?: CompletionItemKind) {
E
Erich Gamma 已提交
1358
		this.label = label;
1359
		this.kind = kind;
E
Erich Gamma 已提交
1360
	}
1361 1362 1363 1364

	toJSON(): any {
		return {
			label: this.label,
1365
			kind: this.kind && CompletionItemKind[this.kind],
1366 1367 1368 1369
			detail: this.detail,
			documentation: this.documentation,
			sortText: this.sortText,
			filterText: this.filterText,
1370
			preselect: this.preselect,
1371 1372
			insertText: this.insertText,
			textEdit: this.textEdit
B
Benjamin Pasero 已提交
1373
		};
1374
	}
E
Erich Gamma 已提交
1375 1376
}

J
Johannes Rieken 已提交
1377
@es5ClassCompat
1378 1379
export class CompletionList {

1380
	isIncomplete?: boolean;
1381 1382 1383 1384 1385 1386 1387 1388 1389

	items: vscode.CompletionItem[];

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

E
Erich Gamma 已提交
1390
export enum ViewColumn {
1391
	Active = -1,
1392
	Beside = -2,
E
Erich Gamma 已提交
1393 1394
	One = 1,
	Two = 2,
1395 1396 1397 1398 1399 1400 1401
	Three = 3,
	Four = 4,
	Five = 5,
	Six = 6,
	Seven = 7,
	Eight = 8,
	Nine = 9
E
Erich Gamma 已提交
1402 1403 1404 1405 1406
}

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

1409 1410 1411 1412 1413 1414
export enum TextEditorLineNumbersStyle {
	Off = 0,
	On = 1,
	Relative = 2
}

1415
export enum TextDocumentSaveReason {
1416 1417
	Manual = 1,
	AfterDelay = 2,
1418 1419 1420
	FocusOut = 3
}

1421 1422 1423
export enum TextEditorRevealType {
	Default = 0,
	InCenter = 1,
1424 1425
	InCenterIfOutsideViewport = 2,
	AtTop = 3
1426
}
J
Johannes Rieken 已提交
1427

1428 1429 1430 1431 1432 1433
export enum TextEditorSelectionChangeKind {
	Keyboard = 1,
	Mouse = 2,
	Command = 3
}

A
Alex Dima 已提交
1434 1435 1436
/**
 * These values match very carefully the values of `TrackedRangeStickiness`
 */
1437
export enum DecorationRangeBehavior {
A
Alex Dima 已提交
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
	/**
	 * TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges
	 */
	OpenOpen = 0,
	/**
	 * TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges
	 */
	ClosedClosed = 1,
	/**
	 * TrackedRangeStickiness.GrowsOnlyWhenTypingBefore
	 */
	OpenClosed = 2,
	/**
	 * TrackedRangeStickiness.GrowsOnlyWhenTypingAfter
	 */
	ClosedOpen = 3
}

1456
export namespace TextEditorSelectionChangeKind {
1457
	export function fromValue(s: string | undefined) {
1458 1459 1460 1461 1462
		switch (s) {
			case 'keyboard': return TextEditorSelectionChangeKind.Keyboard;
			case 'mouse': return TextEditorSelectionChangeKind.Mouse;
			case 'api': return TextEditorSelectionChangeKind.Command;
		}
M
Matt Bierner 已提交
1463
		return undefined;
1464 1465 1466
	}
}

J
Johannes Rieken 已提交
1467
@es5ClassCompat
J
Johannes Rieken 已提交
1468 1469 1470 1471
export class DocumentLink {

	range: Range;

1472
	target?: URI;
1473 1474

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

1476
	constructor(range: Range, target: URI | undefined) {
1477
		if (target && !(URI.isUri(target))) {
J
Johannes Rieken 已提交
1478 1479
			throw illegalArgument('target');
		}
1480
		if (!Range.isRange(range) || range.isEmpty) {
J
Johannes Rieken 已提交
1481 1482 1483 1484 1485
			throw illegalArgument('range');
		}
		this.range = range;
		this.target = target;
	}
1486
}
1487

J
Johannes Rieken 已提交
1488
@es5ClassCompat
1489
export class Color {
1490 1491 1492 1493
	readonly red: number;
	readonly green: number;
	readonly blue: number;
	readonly alpha: number;
1494

J
Joao Moreno 已提交
1495
	constructor(red: number, green: number, blue: number, alpha: number) {
1496 1497 1498 1499 1500
		this.red = red;
		this.green = green;
		this.blue = blue;
		this.alpha = alpha;
	}
1501 1502
}

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

J
Johannes Rieken 已提交
1505
@es5ClassCompat
1506
export class ColorInformation {
1507 1508 1509 1510
	range: Range;

	color: Color;

1511
	constructor(range: Range, color: Color) {
1512
		if (color && !(color instanceof Color)) {
M
Michel Kaporin 已提交
1513 1514
			throw illegalArgument('color');
		}
1515 1516 1517 1518 1519 1520 1521 1522
		if (!Range.isRange(range) || range.isEmpty) {
			throw illegalArgument('range');
		}
		this.range = range;
		this.color = color;
	}
}

J
Johannes Rieken 已提交
1523
@es5ClassCompat
1524 1525 1526 1527
export class ColorPresentation {
	label: string;
	textEdit?: TextEdit;
	additionalTextEdits?: TextEdit[];
1528 1529 1530 1531 1532 1533 1534

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

1537 1538 1539 1540 1541 1542
export enum ColorFormat {
	RGB = 0,
	HEX = 1,
	HSL = 2
}

1543 1544 1545 1546 1547 1548
export enum SourceControlInputBoxValidationType {
	Error = 0,
	Warning = 1,
	Information = 2
}

1549
export enum TaskRevealKind {
1550 1551 1552 1553 1554 1555 1556
	Always = 1,

	Silent = 2,

	Never = 3
}

1557
export enum TaskPanelKind {
1558 1559
	Shared = 1,

1560
	Dedicated = 2,
1561 1562 1563 1564

	New = 3
}

J
Johannes Rieken 已提交
1565
@es5ClassCompat
D
Dirk Baeumer 已提交
1566
export class TaskGroup implements vscode.TaskGroup {
1567

D
Dirk Baeumer 已提交
1568
	private _id: string;
1569

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

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

1574
	public static Rebuild: TaskGroup = new TaskGroup('rebuild', 'Rebuild');
1575

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

1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592
	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 已提交
1593
	constructor(id: string, _label: string) {
D
Dirk Baeumer 已提交
1594 1595 1596
		if (typeof id !== 'string') {
			throw illegalArgument('name');
		}
D
Dirk Baeumer 已提交
1597
		if (typeof _label !== 'string') {
D
Dirk Baeumer 已提交
1598
			throw illegalArgument('name');
1599
		}
D
Dirk Baeumer 已提交
1600
		this._id = id;
1601 1602
	}

D
Dirk Baeumer 已提交
1603 1604
	get id(): string {
		return this._id;
1605
	}
D
Dirk Baeumer 已提交
1606
}
1607

1608 1609 1610 1611 1612 1613 1614 1615
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 已提交
1616
@es5ClassCompat
D
Dirk Baeumer 已提交
1617 1618 1619 1620
export class ProcessExecution implements vscode.ProcessExecution {

	private _process: string;
	private _args: string[];
1621
	private _options: vscode.ProcessExecutionOptions | undefined;
D
Dirk Baeumer 已提交
1622 1623 1624 1625 1626 1627 1628

	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');
		}
1629
		this._args = [];
D
Dirk Baeumer 已提交
1630
		this._process = process;
R
Rob Lourens 已提交
1631
		if (varg1 !== undefined) {
D
Dirk Baeumer 已提交
1632 1633 1634 1635 1636 1637 1638
			if (Array.isArray(varg1)) {
				this._args = varg1;
				this._options = varg2;
			} else {
				this._options = varg1;
			}
		}
1639 1640
	}

D
Dirk Baeumer 已提交
1641 1642 1643

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

D
Dirk Baeumer 已提交
1646 1647 1648
	set process(value: string) {
		if (typeof value !== 'string') {
			throw illegalArgument('process');
D
Dirk Baeumer 已提交
1649
		}
D
Dirk Baeumer 已提交
1650
		this._process = value;
D
Dirk Baeumer 已提交
1651 1652
	}

D
Dirk Baeumer 已提交
1653 1654
	get args(): string[] {
		return this._args;
1655 1656
	}

D
Dirk Baeumer 已提交
1657 1658 1659
	set args(value: string[]) {
		if (!Array.isArray(value)) {
			value = [];
1660
		}
D
Dirk Baeumer 已提交
1661
		this._args = value;
1662 1663
	}

1664
	get options(): vscode.ProcessExecutionOptions | undefined {
D
Dirk Baeumer 已提交
1665
		return this._options;
1666 1667
	}

1668
	set options(value: vscode.ProcessExecutionOptions | undefined) {
D
Dirk Baeumer 已提交
1669
		this._options = value;
1670
	}
D
Dirk Baeumer 已提交
1671 1672

	public computeId(): string {
1673 1674
		const props: string[] = [];
		props.push('process');
R
Rob Lourens 已提交
1675
		if (this._process !== undefined) {
1676
			props.push(this._process);
D
Dirk Baeumer 已提交
1677 1678 1679
		}
		if (this._args && this._args.length > 0) {
			for (let arg of this._args) {
1680
				props.push(arg);
D
Dirk Baeumer 已提交
1681 1682
			}
		}
1683
		return computeTaskExecutionId(props);
D
Dirk Baeumer 已提交
1684
	}
D
Dirk Baeumer 已提交
1685
}
1686

J
Johannes Rieken 已提交
1687
@es5ClassCompat
D
Dirk Baeumer 已提交
1688
export class ShellExecution implements vscode.ShellExecution {
D
Dirk Baeumer 已提交
1689

1690 1691 1692
	private _commandLine: string | undefined;
	private _command: string | vscode.ShellQuotedString | undefined;
	private _args: (string | vscode.ShellQuotedString)[] = [];
1693
	private _options: vscode.ShellExecutionOptions | undefined;
D
Dirk Baeumer 已提交
1694

1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713
	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 已提交
1714 1715 1716
		}
	}

D
Dirk Baeumer 已提交
1717
	get commandLine(): string {
1718
		return this._commandLine ? this._commandLine : '';
1719
	}
D
Dirk Baeumer 已提交
1720

D
Dirk Baeumer 已提交
1721 1722 1723
	set commandLine(value: string) {
		if (typeof value !== 'string') {
			throw illegalArgument('commandLine');
D
Dirk Baeumer 已提交
1724
		}
D
Dirk Baeumer 已提交
1725
		this._commandLine = value;
D
Dirk Baeumer 已提交
1726
	}
1727

1728
	get command(): string | vscode.ShellQuotedString {
1729
		return this._command ? this._command : '';
1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746
	}

	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 || [];
	}

1747
	get options(): vscode.ShellExecutionOptions | undefined {
D
Dirk Baeumer 已提交
1748
		return this._options;
1749 1750
	}

1751
	set options(value: vscode.ShellExecutionOptions | undefined) {
D
Dirk Baeumer 已提交
1752
		this._options = value;
1753
	}
D
Dirk Baeumer 已提交
1754 1755

	public computeId(): string {
1756 1757
		const props: string[] = [];
		props.push('shell');
R
Rob Lourens 已提交
1758
		if (this._commandLine !== undefined) {
1759
			props.push(this._commandLine);
D
Dirk Baeumer 已提交
1760
		}
R
Rob Lourens 已提交
1761
		if (this._command !== undefined) {
1762
			props.push(typeof this._command === 'string' ? this._command : this._command.value);
D
Dirk Baeumer 已提交
1763 1764 1765
		}
		if (this._args && this._args.length > 0) {
			for (let arg of this._args) {
1766
				props.push(typeof arg === 'string' ? arg : arg.value);
D
Dirk Baeumer 已提交
1767 1768
			}
		}
1769
		return computeTaskExecutionId(props);
D
Dirk Baeumer 已提交
1770
	}
1771 1772
}

1773 1774 1775 1776 1777 1778
export enum ShellQuoting {
	Escape = 1,
	Strong = 2,
	Weak = 3
}

D
Dirk Baeumer 已提交
1779 1780 1781 1782 1783
export enum TaskScope {
	Global = 1,
	Workspace = 2
}

1784
export class CustomExecution2 implements vscode.CustomExecution2 {
1785 1786
	private _callback: () => Thenable<vscode.Pseudoterminal>;
	constructor(callback: () => Thenable<vscode.Pseudoterminal>) {
1787 1788 1789 1790 1791 1792
		this._callback = callback;
	}
	public computeId(): string {
		return 'customExecution' + generateUuid();
	}

1793
	public set callback(value: () => Thenable<vscode.Pseudoterminal>) {
1794 1795 1796
		this._callback = value;
	}

1797
	public get callback(): (() => Thenable<vscode.Pseudoterminal>) {
1798 1799 1800 1801
		return this._callback;
	}
}

J
Johannes Rieken 已提交
1802
@es5ClassCompat
G
Gabriel DeBacker 已提交
1803
export class Task implements vscode.Task2 {
1804

G
Gabriel DeBacker 已提交
1805
	private static ExtensionCallbackType: string = 'customExecution';
1806 1807 1808 1809 1810
	private static ProcessType: string = 'process';
	private static ShellType: string = 'shell';
	private static EmptyType: string = '$empty';

	private __id: string | undefined;
1811

D
Dirk Baeumer 已提交
1812
	private _definition: vscode.TaskDefinition;
1813
	private _scope: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder | undefined;
D
Dirk Baeumer 已提交
1814
	private _name: string;
A
Alex Ross 已提交
1815
	private _execution: ProcessExecution | ShellExecution | CustomExecution2 | undefined;
D
Dirk Baeumer 已提交
1816
	private _problemMatchers: string[];
1817
	private _hasDefinedMatchers: boolean;
D
Dirk Baeumer 已提交
1818 1819
	private _isBackground: boolean;
	private _source: string;
1820
	private _group: TaskGroup | undefined;
D
Dirk Baeumer 已提交
1821
	private _presentationOptions: vscode.TaskPresentationOptions;
A
Alex Ross 已提交
1822
	private _runOptions: vscode.RunOptions;
1823

A
Alex Ross 已提交
1824 1825
	constructor(definition: vscode.TaskDefinition, name: string, source: string, execution?: ProcessExecution | ShellExecution | CustomExecution2, problemMatchers?: string | string[]);
	constructor(definition: vscode.TaskDefinition, scope: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder, name: string, source: string, execution?: ProcessExecution | ShellExecution | CustomExecution2, problemMatchers?: string | string[]);
D
Dirk Baeumer 已提交
1826
	constructor(definition: vscode.TaskDefinition, arg2: string | (vscode.TaskScope.Global | vscode.TaskScope.Workspace) | vscode.WorkspaceFolder, arg3: any, arg4?: any, arg5?: any, arg6?: any) {
1827
		this._definition = this.definition = definition;
D
Dirk Baeumer 已提交
1828 1829
		let problemMatchers: string | string[];
		if (typeof arg2 === 'string') {
1830 1831
			this._name = this.name = arg2;
			this._source = this.source = arg3;
D
Dirk Baeumer 已提交
1832 1833
			this.execution = arg4;
			problemMatchers = arg5;
D
Dirk Baeumer 已提交
1834 1835
		} else if (arg2 === TaskScope.Global || arg2 === TaskScope.Workspace) {
			this.target = arg2;
1836 1837
			this._name = this.name = arg3;
			this._source = this.source = arg4;
D
Dirk Baeumer 已提交
1838 1839
			this.execution = arg5;
			problemMatchers = arg6;
D
Dirk Baeumer 已提交
1840
		} else {
D
Dirk Baeumer 已提交
1841
			this.target = arg2;
1842 1843
			this._name = this.name = arg3;
			this._source = this.source = arg4;
D
Dirk Baeumer 已提交
1844 1845 1846
			this.execution = arg5;
			problemMatchers = arg6;
		}
1847 1848
		if (typeof problemMatchers === 'string') {
			this._problemMatchers = [problemMatchers];
1849
			this._hasDefinedMatchers = true;
1850 1851
		} else if (Array.isArray(problemMatchers)) {
			this._problemMatchers = problemMatchers;
1852
			this._hasDefinedMatchers = true;
1853 1854
		} else {
			this._problemMatchers = [];
1855
			this._hasDefinedMatchers = false;
1856
		}
D
Dirk Baeumer 已提交
1857
		this._isBackground = false;
1858 1859
		this._presentationOptions = Object.create(null);
		this._runOptions = Object.create(null);
1860
	}
1861

1862
	get _id(): string | undefined {
1863 1864 1865
		return this.__id;
	}

1866
	set _id(value: string | undefined) {
1867 1868 1869 1870
		this.__id = value;
	}

	private clear(): void {
R
Rob Lourens 已提交
1871
		if (this.__id === undefined) {
D
Dirk Baeumer 已提交
1872 1873
			return;
		}
1874
		this.__id = undefined;
D
Dirk Baeumer 已提交
1875
		this._scope = undefined;
1876 1877 1878 1879
		this.computeDefinitionBasedOnExecution();
	}

	private computeDefinitionBasedOnExecution(): void {
D
Dirk Baeumer 已提交
1880 1881
		if (this._execution instanceof ProcessExecution) {
			this._definition = {
1882
				type: Task.ProcessType,
D
Dirk Baeumer 已提交
1883 1884 1885 1886
				id: this._execution.computeId()
			};
		} else if (this._execution instanceof ShellExecution) {
			this._definition = {
1887
				type: Task.ShellType,
D
Dirk Baeumer 已提交
1888 1889
				id: this._execution.computeId()
			};
A
Alex Ross 已提交
1890
		} else if (this._execution instanceof CustomExecution2) {
1891 1892 1893 1894
			this._definition = {
				type: Task.ExtensionCallbackType,
				id: this._execution.computeId()
			};
1895 1896 1897 1898 1899
		} else {
			this._definition = {
				type: Task.EmptyType,
				id: generateUuid()
			};
D
Dirk Baeumer 已提交
1900
		}
1901 1902
	}

D
Dirk Baeumer 已提交
1903 1904
	get definition(): vscode.TaskDefinition {
		return this._definition;
D
Dirk Baeumer 已提交
1905
	}
1906

D
Dirk Baeumer 已提交
1907
	set definition(value: vscode.TaskDefinition) {
R
Rob Lourens 已提交
1908
		if (value === undefined || value === null) {
D
Dirk Baeumer 已提交
1909
			throw illegalArgument('Kind can\'t be undefined or null');
1910
		}
1911
		this.clear();
D
Dirk Baeumer 已提交
1912
		this._definition = value;
D
Dirk Baeumer 已提交
1913
	}
1914

1915
	get scope(): vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder | undefined {
D
Dirk Baeumer 已提交
1916
		return this._scope;
D
Dirk Baeumer 已提交
1917 1918
	}

D
Dirk Baeumer 已提交
1919
	set target(value: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder) {
1920
		this.clear();
D
Dirk Baeumer 已提交
1921
		this._scope = value;
D
Dirk Baeumer 已提交
1922 1923
	}

D
Dirk Baeumer 已提交
1924 1925 1926 1927 1928 1929 1930
	get name(): string {
		return this._name;
	}

	set name(value: string) {
		if (typeof value !== 'string') {
			throw illegalArgument('name');
1931
		}
1932
		this.clear();
D
Dirk Baeumer 已提交
1933
		this._name = value;
1934 1935
	}

1936
	get execution(): ProcessExecution | ShellExecution | undefined {
A
Alex Ross 已提交
1937
		return (this._execution instanceof CustomExecution2) ? undefined : this._execution;
1938 1939 1940
	}

	set execution(value: ProcessExecution | ShellExecution | undefined) {
G
Gabriel DeBacker 已提交
1941
		this.execution2 = value;
1942 1943
	}

A
Alex Ross 已提交
1944
	get execution2(): ProcessExecution | ShellExecution | CustomExecution2 | undefined {
D
Dirk Baeumer 已提交
1945
		return this._execution;
1946
	}
D
Dirk Baeumer 已提交
1947

A
Alex Ross 已提交
1948
	set execution2(value: ProcessExecution | ShellExecution | CustomExecution2 | undefined) {
D
Dirk Baeumer 已提交
1949 1950 1951
		if (value === null) {
			value = undefined;
		}
1952
		this.clear();
D
Dirk Baeumer 已提交
1953
		this._execution = value;
1954
		const type = this._definition.type;
1955
		if (Task.EmptyType === type || Task.ProcessType === type || Task.ShellType === type || Task.ExtensionCallbackType === type) {
1956 1957
			this.computeDefinitionBasedOnExecution();
		}
D
Dirk Baeumer 已提交
1958 1959
	}

D
Dirk Baeumer 已提交
1960 1961 1962 1963 1964
	get problemMatchers(): string[] {
		return this._problemMatchers;
	}

	set problemMatchers(value: string[]) {
D
Dirk Baeumer 已提交
1965
		if (!Array.isArray(value)) {
1966
			this.clear();
1967 1968 1969
			this._problemMatchers = [];
			this._hasDefinedMatchers = false;
			return;
1970 1971 1972 1973
		} else {
			this.clear();
			this._problemMatchers = value;
			this._hasDefinedMatchers = true;
D
Dirk Baeumer 已提交
1974
		}
1975 1976 1977 1978
	}

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

D
Dirk Baeumer 已提交
1981 1982
	get isBackground(): boolean {
		return this._isBackground;
D
Dirk Baeumer 已提交
1983 1984
	}

D
Dirk Baeumer 已提交
1985 1986 1987
	set isBackground(value: boolean) {
		if (value !== true && value !== false) {
			value = false;
D
Dirk Baeumer 已提交
1988
		}
1989
		this.clear();
D
Dirk Baeumer 已提交
1990
		this._isBackground = value;
D
Dirk Baeumer 已提交
1991
	}
1992

D
Dirk Baeumer 已提交
1993 1994 1995
	get source(): string {
		return this._source;
	}
1996

D
Dirk Baeumer 已提交
1997 1998 1999
	set source(value: string) {
		if (typeof value !== 'string' || value.length === 0) {
			throw illegalArgument('source must be a string of length > 0');
2000
		}
2001
		this.clear();
D
Dirk Baeumer 已提交
2002
		this._source = value;
2003 2004
	}

2005
	get group(): TaskGroup | undefined {
D
Dirk Baeumer 已提交
2006
		return this._group;
2007
	}
D
Dirk Baeumer 已提交
2008

2009 2010 2011
	set group(value: TaskGroup | undefined) {
		if (value === null) {
			value = undefined;
D
Dirk Baeumer 已提交
2012
		}
2013
		this.clear();
D
Dirk Baeumer 已提交
2014
		this._group = value;
D
Dirk Baeumer 已提交
2015 2016
	}

D
Dirk Baeumer 已提交
2017 2018 2019 2020 2021
	get presentationOptions(): vscode.TaskPresentationOptions {
		return this._presentationOptions;
	}

	set presentationOptions(value: vscode.TaskPresentationOptions) {
2022 2023
		if (value === null || value === undefined) {
			value = Object.create(null);
D
Dirk Baeumer 已提交
2024
		}
2025
		this.clear();
D
Dirk Baeumer 已提交
2026
		this._presentationOptions = value;
D
Dirk Baeumer 已提交
2027
	}
A
Alex Ross 已提交
2028 2029 2030 2031 2032 2033

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

	set runOptions(value: vscode.RunOptions) {
2034 2035
		if (value === null || value === undefined) {
			value = Object.create(null);
A
Alex Ross 已提交
2036 2037 2038 2039
		}
		this.clear();
		this._runOptions = value;
	}
2040
}
J
Johannes Rieken 已提交
2041

D
Dirk Baeumer 已提交
2042

J
Johannes Rieken 已提交
2043
export enum ProgressLocation {
2044
	SourceControl = 1,
J
Johannes Rieken 已提交
2045
	Window = 10,
2046
	Notification = 15
J
Johannes Rieken 已提交
2047
}
S
Sandeep Somavarapu 已提交
2048

J
Johannes Rieken 已提交
2049
@es5ClassCompat
S
Sandeep Somavarapu 已提交
2050 2051
export class TreeItem {

S
Sandeep Somavarapu 已提交
2052
	label?: string | vscode.TreeItemLabel;
2053
	resourceUri?: URI;
2054
	iconPath?: string | URI | { light: string | URI; dark: string | URI };
S
Sandeep Somavarapu 已提交
2055 2056
	command?: vscode.Command;
	contextValue?: string;
S
Sandeep Somavarapu 已提交
2057
	tooltip?: string;
S
Sandeep Somavarapu 已提交
2058

S
Sandeep Somavarapu 已提交
2059
	constructor(label: string | vscode.TreeItemLabel, collapsibleState?: vscode.TreeItemCollapsibleState)
2060
	constructor(resourceUri: URI, collapsibleState?: vscode.TreeItemCollapsibleState)
S
Sandeep Somavarapu 已提交
2061
	constructor(arg1: string | vscode.TreeItemLabel | URI, public collapsibleState: vscode.TreeItemCollapsibleState = TreeItemCollapsibleState.None) {
2062
		if (URI.isUri(arg1)) {
2063 2064 2065 2066
			this.resourceUri = arg1;
		} else {
			this.label = arg1;
		}
S
Sandeep Somavarapu 已提交
2067 2068 2069 2070
	}

}

S
Sandeep Somavarapu 已提交
2071
export enum TreeItemCollapsibleState {
2072
	None = 0,
S
Sandeep Somavarapu 已提交
2073 2074 2075
	Collapsed = 1,
	Expanded = 2
}
2076

2077
@es5ClassCompat
2078
export class ThemeIcon {
2079

2080 2081
	static File: ThemeIcon;
	static Folder: ThemeIcon;
2082 2083 2084

	readonly id: string;

2085
	constructor(id: string) {
2086 2087 2088
		this.id = id;
	}
}
2089 2090 2091
ThemeIcon.File = new ThemeIcon('file');
ThemeIcon.Folder = new ThemeIcon('folder');

2092

J
Johannes Rieken 已提交
2093
@es5ClassCompat
2094 2095 2096 2097 2098
export class ThemeColor {
	id: string;
	constructor(id: string) {
		this.id = id;
	}
2099
}
S
Sandeep Somavarapu 已提交
2100 2101 2102 2103 2104 2105 2106

export enum ConfigurationTarget {
	Global = 1,

	Workspace = 2,

	WorkspaceFolder = 3
2107
}
2108

J
Johannes Rieken 已提交
2109
@es5ClassCompat
2110 2111
export class RelativePattern implements IRelativePattern {
	base: string;
2112 2113
	baseFolder?: URI;

2114 2115
	pattern: string;

2116
	constructor(base: vscode.WorkspaceFolder | string, pattern: string) {
2117 2118 2119 2120 2121 2122 2123 2124 2125 2126
		if (typeof base !== 'string') {
			if (!base || !URI.isUri(base.uri)) {
				throw illegalArgument('base');
			}
		}

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

2127 2128 2129 2130 2131 2132 2133
		if (typeof base === 'string') {
			this.base = base;
		} else {
			this.baseFolder = base.uri;
			this.base = base.uri.fsPath;
		}

2134
		this.pattern = pattern;
2135
	}
J
Johannes Rieken 已提交
2136
}
2137

J
Johannes Rieken 已提交
2138
@es5ClassCompat
2139 2140
export class Breakpoint {

2141 2142
	private _id: string | undefined;

2143 2144 2145
	readonly enabled: boolean;
	readonly condition?: string;
	readonly hitCondition?: string;
2146
	readonly logMessage?: string;
2147

2148
	protected constructor(enabled?: boolean, condition?: string, hitCondition?: string, logMessage?: string) {
2149 2150 2151 2152 2153 2154 2155
		this.enabled = typeof enabled === 'boolean' ? enabled : true;
		if (typeof condition === 'string') {
			this.condition = condition;
		}
		if (typeof hitCondition === 'string') {
			this.hitCondition = hitCondition;
		}
2156 2157 2158
		if (typeof logMessage === 'string') {
			this.logMessage = logMessage;
		}
2159
	}
2160 2161 2162 2163 2164 2165 2166

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

J
Johannes Rieken 已提交
2169
@es5ClassCompat
2170 2171 2172
export class SourceBreakpoint extends Breakpoint {
	readonly location: Location;

2173 2174
	constructor(location: Location, enabled?: boolean, condition?: string, hitCondition?: string, logMessage?: string) {
		super(enabled, condition, hitCondition, logMessage);
2175 2176 2177
		if (location === null) {
			throw illegalArgument('location');
		}
2178 2179 2180 2181
		this.location = location;
	}
}

J
Johannes Rieken 已提交
2182
@es5ClassCompat
2183 2184 2185
export class FunctionBreakpoint extends Breakpoint {
	readonly functionName: string;

2186 2187
	constructor(functionName: string, enabled?: boolean, condition?: string, hitCondition?: string, logMessage?: string) {
		super(enabled, condition, hitCondition, logMessage);
2188 2189 2190
		if (!functionName) {
			throw illegalArgument('functionName');
		}
2191 2192 2193
		this.functionName = functionName;
	}
}
2194

I
isidor 已提交
2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212
@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 已提交
2213
@es5ClassCompat
2214 2215 2216
export class DebugAdapterExecutable implements vscode.DebugAdapterExecutable {
	readonly command: string;
	readonly args: string[];
2217
	readonly options?: vscode.DebugAdapterExecutableOptions;
2218

2219
	constructor(command: string, args: string[], options?: vscode.DebugAdapterExecutableOptions) {
2220
		this.command = command;
2221 2222
		this.args = args || [];
		this.options = options;
2223 2224 2225
	}
}

J
Johannes Rieken 已提交
2226
@es5ClassCompat
2227 2228
export class DebugAdapterServer implements vscode.DebugAdapterServer {
	readonly port: number;
A
Andre Weinand 已提交
2229
	readonly host?: string;
2230

2231
	constructor(port: number, host?: string) {
2232
		this.port = port;
2233
		this.host = host;
2234 2235 2236
	}
}

2237
/*
J
Johannes Rieken 已提交
2238
@es5ClassCompat
A
Andre Weinand 已提交
2239 2240 2241 2242 2243 2244 2245
export class DebugAdapterImplementation implements vscode.DebugAdapterImplementation {
	readonly implementation: any;

	constructor(transport: any) {
		this.implementation = transport;
	}
}
2246
*/
A
Andre Weinand 已提交
2247

2248 2249 2250 2251 2252 2253 2254 2255 2256
export enum LogLevel {
	Trace = 1,
	Debug = 2,
	Info = 3,
	Warning = 4,
	Error = 5,
	Critical = 6,
	Off = 7
}
J
Johannes Rieken 已提交
2257 2258 2259

//#region file api

2260
export enum FileChangeType {
2261 2262 2263 2264 2265
	Changed = 1,
	Created = 2,
	Deleted = 3,
}

J
Johannes Rieken 已提交
2266
@es5ClassCompat
2267
export class FileSystemError extends Error {
2268

2269
	static FileExists(messageOrUri?: string | URI): FileSystemError {
2270
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.FileExists, FileSystemError.FileExists);
J
Johannes Rieken 已提交
2271
	}
2272
	static FileNotFound(messageOrUri?: string | URI): FileSystemError {
2273
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.FileNotFound, FileSystemError.FileNotFound);
J
Johannes Rieken 已提交
2274
	}
2275
	static FileNotADirectory(messageOrUri?: string | URI): FileSystemError {
2276
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.FileNotADirectory, FileSystemError.FileNotADirectory);
J
Johannes Rieken 已提交
2277
	}
2278
	static FileIsADirectory(messageOrUri?: string | URI): FileSystemError {
2279
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.FileIsADirectory, FileSystemError.FileIsADirectory);
J
Johannes Rieken 已提交
2280
	}
2281
	static NoPermissions(messageOrUri?: string | URI): FileSystemError {
2282
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.NoPermissions, FileSystemError.NoPermissions);
2283
	}
2284
	static Unavailable(messageOrUri?: string | URI): FileSystemError {
2285
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.Unavailable, FileSystemError.Unavailable);
2286
	}
2287

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

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

2295 2296 2297 2298 2299 2300
		// workaround when extending builtin objects and when compiling to ES5, see:
		// https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
		if (typeof (<any>Object).setPrototypeOf === 'function') {
			(<any>Object).setPrototypeOf(this, FileSystemError.prototype);
		}

J
Johannes Rieken 已提交
2301
		if (typeof Error.captureStackTrace === 'function' && typeof terminator === 'function') {
J
Johannes Rieken 已提交
2302
			// nice stack traces
J
Johannes Rieken 已提交
2303
			Error.captureStackTrace(this, terminator);
J
Johannes Rieken 已提交
2304
		}
2305 2306 2307
	}
}

J
Johannes Rieken 已提交
2308
//#endregion
2309 2310 2311

//#region folding api

J
Johannes Rieken 已提交
2312
@es5ClassCompat
2313 2314
export class FoldingRange {

2315
	start: number;
2316

2317
	end: number;
2318

2319
	kind?: FoldingRangeKind;
2320

2321 2322 2323 2324
	constructor(start: number, end: number, kind?: FoldingRangeKind) {
		this.start = start;
		this.end = end;
		this.kind = kind;
2325 2326 2327
	}
}

2328 2329 2330 2331
export enum FoldingRangeKind {
	Comment = 1,
	Imports = 2,
	Region = 3
2332 2333
}

2334
//#endregion
2335

P
Peng Lyu 已提交
2336
//#region Comment
2337 2338 2339 2340 2341 2342 2343 2344 2345
export enum CommentThreadCollapsibleState {
	/**
	 * Determines an item is collapsed
	 */
	Collapsed = 0,
	/**
	 * Determines an item is expanded
	 */
	Expanded = 1
2346
}
P
Peng Lyu 已提交
2347 2348 2349 2350 2351 2352

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

P
Peng Lyu 已提交
2353
//#endregion
2354

2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370
//#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
}

//#endregion

J
Johannes Rieken 已提交
2371
@es5ClassCompat
2372 2373 2374 2375 2376 2377
export class QuickInputButtons {

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

	private constructor() { }
}
2378

2379 2380 2381 2382
export enum ExtensionKind {
	UI = 1,
	Workspace = 2
}
2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400

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;
}
2401

2402
export enum WebviewContentState {
2403 2404 2405 2406
	Readonly = 1,
	Unchanged = 2,
	Dirty = 3,
}