extHostTypes.ts 54.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;
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;
	}

541 542 543 544 545 546 547 548 549 550 551
	get newEol(): EndOfLine {
		return this._newEol;
	}

	set newEol(value: EndOfLine) {
		if (value && typeof value !== 'number') {
			throw illegalArgument('newEol');
		}
		this._newEol = value;
	}

552
	constructor(range: Range, newText: string | null) {
E
Erich Gamma 已提交
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 776 777
export enum DiagnosticTag {
	Unnecessary = 1,
}

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

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

788 789 790 791 792 793 794 795 796 797 798
	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 已提交
799 800 801
	uri: URI;
	range: Range;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	range: Range;
	kind: DocumentHighlightKind;

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

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

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

J
Johannes Rieken 已提交
981
@es5ClassCompat
E
Erich Gamma 已提交
982 983
export class SymbolInformation {

J
Johannes Rieken 已提交
984 985 986 987 988 989
	static validate(candidate: SymbolInformation): void {
		if (!candidate.name) {
			throw new Error('name must not be falsy');
		}
	}

E
Erich Gamma 已提交
990 991 992
	name: string;
	location: Location;
	kind: SymbolKind;
993
	containerName: string | undefined;
E
Erich Gamma 已提交
994

M
Matt Bierner 已提交
995
	constructor(name: string, kind: SymbolKind, containerName: string | undefined, location: Location);
996
	constructor(name: string, kind: SymbolKind, range: Range, uri?: URI, containerName?: string);
M
Matt Bierner 已提交
997
	constructor(name: string, kind: SymbolKind, rangeOrContainer: string | undefined | Range, locationOrUri?: Location | URI, containerName?: string) {
E
Erich Gamma 已提交
998 999 1000
		this.name = name;
		this.kind = kind;
		this.containerName = containerName;
1001 1002 1003 1004 1005 1006 1007

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

		if (locationOrUri instanceof Location) {
			this.location = locationOrUri;
1008
		} else if (rangeOrContainer instanceof Range) {
1009
			this.location = new Location(locationOrUri!, rangeOrContainer);
1010
		}
J
Johannes Rieken 已提交
1011 1012

		SymbolInformation.validate(this);
E
Erich Gamma 已提交
1013
	}
1014 1015 1016 1017 1018 1019 1020

	toJSON(): any {
		return {
			name: this.name,
			kind: SymbolKind[this.kind],
			location: this.location,
			containerName: this.containerName
B
Benjamin Pasero 已提交
1021
		};
1022
	}
E
Erich Gamma 已提交
1023 1024
}

J
Johannes Rieken 已提交
1025
@es5ClassCompat
1026
export class DocumentSymbol {
J
Johannes Rieken 已提交
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039

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

1040
	name: string;
1041
	detail: string;
1042
	kind: SymbolKind;
1043 1044
	range: Range;
	selectionRange: Range;
1045
	children: DocumentSymbol[];
1046

1047
	constructor(name: string, detail: string, kind: SymbolKind, range: Range, selectionRange: Range) {
1048
		this.name = name;
1049
		this.detail = detail;
1050
		this.kind = kind;
1051 1052
		this.range = range;
		this.selectionRange = selectionRange;
1053
		this.children = [];
1054

J
Johannes Rieken 已提交
1055
		DocumentSymbol.validate(this);
1056 1057 1058
	}
}

1059

1060 1061 1062 1063 1064
export enum CodeActionTrigger {
	Automatic = 1,
	Manual = 2,
}

J
Johannes Rieken 已提交
1065
@es5ClassCompat
1066 1067 1068 1069 1070
export class CodeAction {
	title: string;

	command?: vscode.Command;

1071
	edit?: WorkspaceEdit;
1072

M
Matt Bierner 已提交
1073
	diagnostics?: Diagnostic[];
1074

1075
	kind?: CodeActionKind;
M
Matt Bierner 已提交
1076

1077
	constructor(title: string, kind?: CodeActionKind) {
1078
		this.title = title;
1079
		this.kind = kind;
1080 1081 1082
	}
}

M
Matt Bierner 已提交
1083

J
Johannes Rieken 已提交
1084
@es5ClassCompat
M
Matt Bierner 已提交
1085 1086 1087
export class CodeActionKind {
	private static readonly sep = '.';

1088 1089 1090 1091 1092 1093 1094 1095 1096
	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 已提交
1097 1098 1099 1100 1101 1102 1103 1104 1105

	constructor(
		public readonly value: string
	) { }

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

M
Matt Bierner 已提交
1106 1107 1108 1109
	public intersects(other: CodeActionKind): boolean {
		return this.contains(other) || other.contains(this);
	}

M
Matt Bierner 已提交
1110 1111 1112 1113
	public contains(other: CodeActionKind): boolean {
		return this.value === other.value || startsWith(other.value, this.value + CodeActionKind.sep);
	}
}
1114 1115 1116 1117 1118 1119 1120 1121 1122
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 已提交
1123

J
Johannes Rieken 已提交
1124
@es5ClassCompat
1125 1126 1127
export class SelectionRange {

	range: Range;
1128
	parent?: SelectionRange;
1129

1130
	constructor(range: Range, parent?: SelectionRange) {
1131
		this.range = range;
1132
		this.parent = parent;
1133 1134 1135 1136

		if (parent && !parent.range.contains(this.range)) {
			throw new Error('Invalid argument: parent must contain this range');
		}
1137 1138 1139
	}
}

M
Matt Bierner 已提交
1140

1141 1142 1143 1144 1145 1146 1147 1148 1149
export enum CallHierarchyDirection {
	CallsFrom = 1,
	CallsTo = 2,
}

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

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

J
Johannes Rieken 已提交
1164
@es5ClassCompat
E
Erich Gamma 已提交
1165 1166 1167 1168
export class CodeLens {

	range: Range;

1169
	command: vscode.Command | undefined;
E
Erich Gamma 已提交
1170 1171 1172

	constructor(range: Range, command?: vscode.Command) {
		this.range = range;
1173
		this.command = command;
E
Erich Gamma 已提交
1174 1175 1176 1177 1178 1179 1180
	}

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

R
Rob DeLine 已提交
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193

export class CodeInset {

	range: Range;
	height?: number;

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


J
Johannes Rieken 已提交
1194
@es5ClassCompat
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
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
		this.value += value.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&');
		return this;
	}

	appendMarkdown(value: string): MarkdownString {
		this.value += value;
		return this;
	}
J
Johannes Rieken 已提交
1214 1215 1216 1217 1218 1219 1220 1221 1222

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

J
Johannes Rieken 已提交
1225
@es5ClassCompat
E
Erich Gamma 已提交
1226 1227
export class ParameterInformation {

1228
	label: string | [number, number];
1229
	documentation?: string | MarkdownString;
E
Erich Gamma 已提交
1230

1231
	constructor(label: string | [number, number], documentation?: string | MarkdownString) {
E
Erich Gamma 已提交
1232 1233 1234 1235 1236
		this.label = label;
		this.documentation = documentation;
	}
}

J
Johannes Rieken 已提交
1237
@es5ClassCompat
E
Erich Gamma 已提交
1238 1239 1240
export class SignatureInformation {

	label: string;
1241
	documentation?: string | MarkdownString;
E
Erich Gamma 已提交
1242 1243
	parameters: ParameterInformation[];

1244
	constructor(label: string, documentation?: string | MarkdownString) {
E
Erich Gamma 已提交
1245 1246 1247 1248 1249 1250
		this.label = label;
		this.documentation = documentation;
		this.parameters = [];
	}
}

J
Johannes Rieken 已提交
1251
@es5ClassCompat
E
Erich Gamma 已提交
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262
export class SignatureHelp {

	signatures: SignatureInformation[];
	activeSignature: number;
	activeParameter: number;

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

M
Matt Bierner 已提交
1263
export enum SignatureHelpTriggerKind {
1264 1265
	Invoke = 1,
	TriggerCharacter = 2,
1266
	ContentChange = 3,
1267 1268
}

M
Matt Bierner 已提交
1269 1270
export enum CompletionTriggerKind {
	Invoke = 0,
1271 1272
	TriggerCharacter = 1,
	TriggerForIncompleteCompletions = 2
M
Matt Bierner 已提交
1273 1274 1275
}

export interface CompletionContext {
1276 1277
	readonly triggerKind: CompletionTriggerKind;
	readonly triggerCharacter?: string;
M
Matt Bierner 已提交
1278 1279
}

E
Erich Gamma 已提交
1280
export enum CompletionItemKind {
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
	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,
1298
	Reference = 17,
1299 1300
	Folder = 18,
	EnumMember = 19,
1301
	Constant = 20,
1302 1303
	Struct = 21,
	Event = 22,
1304 1305
	Operator = 23,
	TypeParameter = 24
E
Erich Gamma 已提交
1306 1307
}

J
Johannes Rieken 已提交
1308
@es5ClassCompat
1309
export class CompletionItem implements vscode.CompletionItem {
E
Erich Gamma 已提交
1310 1311

	label: string;
1312
	kind: CompletionItemKind | undefined;
1313 1314 1315 1316 1317
	detail?: string;
	documentation?: string | MarkdownString;
	sortText?: string;
	filterText?: string;
	preselect?: boolean;
1318
	insertText: string | SnippetString;
1319
	keepWhitespace?: boolean;
1320
	range: Range;
1321
	commitCharacters?: string[];
E
Erich Gamma 已提交
1322
	textEdit: TextEdit;
1323 1324
	additionalTextEdits: TextEdit[];
	command: vscode.Command;
E
Erich Gamma 已提交
1325

1326
	constructor(label: string, kind?: CompletionItemKind) {
E
Erich Gamma 已提交
1327
		this.label = label;
1328
		this.kind = kind;
E
Erich Gamma 已提交
1329
	}
1330 1331 1332 1333

	toJSON(): any {
		return {
			label: this.label,
1334
			kind: this.kind && CompletionItemKind[this.kind],
1335 1336 1337 1338
			detail: this.detail,
			documentation: this.documentation,
			sortText: this.sortText,
			filterText: this.filterText,
1339
			preselect: this.preselect,
1340 1341
			insertText: this.insertText,
			textEdit: this.textEdit
B
Benjamin Pasero 已提交
1342
		};
1343
	}
E
Erich Gamma 已提交
1344 1345
}

J
Johannes Rieken 已提交
1346
@es5ClassCompat
1347 1348
export class CompletionList {

1349
	isIncomplete?: boolean;
1350 1351 1352 1353 1354 1355 1356 1357 1358

	items: vscode.CompletionItem[];

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

E
Erich Gamma 已提交
1359
export enum ViewColumn {
1360
	Active = -1,
1361
	Beside = -2,
E
Erich Gamma 已提交
1362 1363
	One = 1,
	Two = 2,
1364 1365 1366 1367 1368 1369 1370
	Three = 3,
	Four = 4,
	Five = 5,
	Six = 6,
	Seven = 7,
	Eight = 8,
	Nine = 9
E
Erich Gamma 已提交
1371 1372 1373 1374 1375
}

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

1378 1379 1380 1381 1382 1383
export enum TextEditorLineNumbersStyle {
	Off = 0,
	On = 1,
	Relative = 2
}

1384
export enum TextDocumentSaveReason {
1385 1386
	Manual = 1,
	AfterDelay = 2,
1387 1388 1389
	FocusOut = 3
}

1390 1391 1392
export enum TextEditorRevealType {
	Default = 0,
	InCenter = 1,
1393 1394
	InCenterIfOutsideViewport = 2,
	AtTop = 3
1395
}
J
Johannes Rieken 已提交
1396

1397 1398 1399 1400 1401 1402
export enum TextEditorSelectionChangeKind {
	Keyboard = 1,
	Mouse = 2,
	Command = 3
}

A
Alex Dima 已提交
1403 1404 1405
/**
 * These values match very carefully the values of `TrackedRangeStickiness`
 */
1406
export enum DecorationRangeBehavior {
A
Alex Dima 已提交
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424
	/**
	 * TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges
	 */
	OpenOpen = 0,
	/**
	 * TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges
	 */
	ClosedClosed = 1,
	/**
	 * TrackedRangeStickiness.GrowsOnlyWhenTypingBefore
	 */
	OpenClosed = 2,
	/**
	 * TrackedRangeStickiness.GrowsOnlyWhenTypingAfter
	 */
	ClosedOpen = 3
}

1425
export namespace TextEditorSelectionChangeKind {
1426
	export function fromValue(s: string | undefined) {
1427 1428 1429 1430 1431
		switch (s) {
			case 'keyboard': return TextEditorSelectionChangeKind.Keyboard;
			case 'mouse': return TextEditorSelectionChangeKind.Mouse;
			case 'api': return TextEditorSelectionChangeKind.Command;
		}
M
Matt Bierner 已提交
1432
		return undefined;
1433 1434 1435
	}
}

J
Johannes Rieken 已提交
1436
@es5ClassCompat
J
Johannes Rieken 已提交
1437 1438 1439 1440
export class DocumentLink {

	range: Range;

1441
	target?: URI;
J
Johannes Rieken 已提交
1442

1443
	constructor(range: Range, target: URI | undefined) {
1444
		if (target && !(target instanceof URI)) {
J
Johannes Rieken 已提交
1445 1446
			throw illegalArgument('target');
		}
1447
		if (!Range.isRange(range) || range.isEmpty) {
J
Johannes Rieken 已提交
1448 1449 1450 1451 1452
			throw illegalArgument('range');
		}
		this.range = range;
		this.target = target;
	}
1453
}
1454

J
Johannes Rieken 已提交
1455
@es5ClassCompat
1456
export class Color {
1457 1458 1459 1460
	readonly red: number;
	readonly green: number;
	readonly blue: number;
	readonly alpha: number;
1461

J
Joao Moreno 已提交
1462
	constructor(red: number, green: number, blue: number, alpha: number) {
1463 1464 1465 1466 1467
		this.red = red;
		this.green = green;
		this.blue = blue;
		this.alpha = alpha;
	}
1468 1469
}

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

J
Johannes Rieken 已提交
1472
@es5ClassCompat
1473
export class ColorInformation {
1474 1475 1476 1477
	range: Range;

	color: Color;

1478
	constructor(range: Range, color: Color) {
1479
		if (color && !(color instanceof Color)) {
M
Michel Kaporin 已提交
1480 1481
			throw illegalArgument('color');
		}
1482 1483 1484 1485 1486 1487 1488 1489
		if (!Range.isRange(range) || range.isEmpty) {
			throw illegalArgument('range');
		}
		this.range = range;
		this.color = color;
	}
}

J
Johannes Rieken 已提交
1490
@es5ClassCompat
1491 1492 1493 1494
export class ColorPresentation {
	label: string;
	textEdit?: TextEdit;
	additionalTextEdits?: TextEdit[];
1495 1496 1497 1498 1499 1500 1501

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

1504 1505 1506 1507 1508 1509
export enum ColorFormat {
	RGB = 0,
	HEX = 1,
	HSL = 2
}

1510 1511 1512 1513 1514 1515
export enum SourceControlInputBoxValidationType {
	Error = 0,
	Warning = 1,
	Information = 2
}

1516
export enum TaskRevealKind {
1517 1518 1519 1520 1521 1522 1523
	Always = 1,

	Silent = 2,

	Never = 3
}

1524
export enum TaskPanelKind {
1525 1526
	Shared = 1,

1527
	Dedicated = 2,
1528 1529 1530 1531

	New = 3
}

J
Johannes Rieken 已提交
1532
@es5ClassCompat
D
Dirk Baeumer 已提交
1533
export class TaskGroup implements vscode.TaskGroup {
1534

D
Dirk Baeumer 已提交
1535
	private _id: string;
1536

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

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

1541
	public static Rebuild: TaskGroup = new TaskGroup('rebuild', 'Rebuild');
1542

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

1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559
	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 已提交
1560
	constructor(id: string, _label: string) {
D
Dirk Baeumer 已提交
1561 1562 1563
		if (typeof id !== 'string') {
			throw illegalArgument('name');
		}
D
Dirk Baeumer 已提交
1564
		if (typeof _label !== 'string') {
D
Dirk Baeumer 已提交
1565
			throw illegalArgument('name');
1566
		}
D
Dirk Baeumer 已提交
1567
		this._id = id;
1568 1569
	}

D
Dirk Baeumer 已提交
1570 1571
	get id(): string {
		return this._id;
1572
	}
D
Dirk Baeumer 已提交
1573
}
1574

1575 1576 1577 1578 1579 1580 1581 1582
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 已提交
1583
@es5ClassCompat
D
Dirk Baeumer 已提交
1584 1585 1586 1587
export class ProcessExecution implements vscode.ProcessExecution {

	private _process: string;
	private _args: string[];
1588
	private _options: vscode.ProcessExecutionOptions | undefined;
D
Dirk Baeumer 已提交
1589 1590 1591 1592 1593 1594 1595 1596

	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');
		}
		this._process = process;
R
Rob Lourens 已提交
1597
		if (varg1 !== undefined) {
D
Dirk Baeumer 已提交
1598 1599 1600 1601 1602 1603 1604
			if (Array.isArray(varg1)) {
				this._args = varg1;
				this._options = varg2;
			} else {
				this._options = varg1;
			}
		}
R
Rob Lourens 已提交
1605
		if (this._args === undefined) {
D
Dirk Baeumer 已提交
1606
			this._args = [];
1607 1608 1609
		}
	}

D
Dirk Baeumer 已提交
1610 1611 1612

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

D
Dirk Baeumer 已提交
1615 1616 1617
	set process(value: string) {
		if (typeof value !== 'string') {
			throw illegalArgument('process');
D
Dirk Baeumer 已提交
1618
		}
D
Dirk Baeumer 已提交
1619
		this._process = value;
D
Dirk Baeumer 已提交
1620 1621
	}

D
Dirk Baeumer 已提交
1622 1623
	get args(): string[] {
		return this._args;
1624 1625
	}

D
Dirk Baeumer 已提交
1626 1627 1628
	set args(value: string[]) {
		if (!Array.isArray(value)) {
			value = [];
1629
		}
D
Dirk Baeumer 已提交
1630
		this._args = value;
1631 1632
	}

1633
	get options(): vscode.ProcessExecutionOptions | undefined {
D
Dirk Baeumer 已提交
1634
		return this._options;
1635 1636
	}

1637
	set options(value: vscode.ProcessExecutionOptions | undefined) {
D
Dirk Baeumer 已提交
1638
		this._options = value;
1639
	}
D
Dirk Baeumer 已提交
1640 1641

	public computeId(): string {
1642 1643
		const props: string[] = [];
		props.push('process');
R
Rob Lourens 已提交
1644
		if (this._process !== undefined) {
1645
			props.push(this._process);
D
Dirk Baeumer 已提交
1646 1647 1648
		}
		if (this._args && this._args.length > 0) {
			for (let arg of this._args) {
1649
				props.push(arg);
D
Dirk Baeumer 已提交
1650 1651
			}
		}
1652
		return computeTaskExecutionId(props);
D
Dirk Baeumer 已提交
1653
	}
D
Dirk Baeumer 已提交
1654
}
1655

J
Johannes Rieken 已提交
1656
@es5ClassCompat
D
Dirk Baeumer 已提交
1657
export class ShellExecution implements vscode.ShellExecution {
D
Dirk Baeumer 已提交
1658

D
Dirk Baeumer 已提交
1659
	private _commandLine: string;
1660 1661
	private _command: string | vscode.ShellQuotedString;
	private _args: (string | vscode.ShellQuotedString)[];
1662
	private _options: vscode.ShellExecutionOptions | undefined;
D
Dirk Baeumer 已提交
1663

1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682
	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 已提交
1683 1684 1685
		}
	}

D
Dirk Baeumer 已提交
1686 1687
	get commandLine(): string {
		return this._commandLine;
1688
	}
D
Dirk Baeumer 已提交
1689

D
Dirk Baeumer 已提交
1690 1691 1692
	set commandLine(value: string) {
		if (typeof value !== 'string') {
			throw illegalArgument('commandLine');
D
Dirk Baeumer 已提交
1693
		}
D
Dirk Baeumer 已提交
1694
		this._commandLine = value;
D
Dirk Baeumer 已提交
1695
	}
1696

1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715
	get command(): string | vscode.ShellQuotedString {
		return this._command;
	}

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

1716
	get options(): vscode.ShellExecutionOptions | undefined {
D
Dirk Baeumer 已提交
1717
		return this._options;
1718 1719
	}

1720
	set options(value: vscode.ShellExecutionOptions | undefined) {
D
Dirk Baeumer 已提交
1721
		this._options = value;
1722
	}
D
Dirk Baeumer 已提交
1723 1724

	public computeId(): string {
1725 1726
		const props: string[] = [];
		props.push('shell');
R
Rob Lourens 已提交
1727
		if (this._commandLine !== undefined) {
1728
			props.push(this._commandLine);
D
Dirk Baeumer 已提交
1729
		}
R
Rob Lourens 已提交
1730
		if (this._command !== undefined) {
1731
			props.push(typeof this._command === 'string' ? this._command : this._command.value);
D
Dirk Baeumer 已提交
1732 1733 1734
		}
		if (this._args && this._args.length > 0) {
			for (let arg of this._args) {
1735
				props.push(typeof arg === 'string' ? arg : arg.value);
D
Dirk Baeumer 已提交
1736 1737
			}
		}
1738
		return computeTaskExecutionId(props);
D
Dirk Baeumer 已提交
1739
	}
1740 1741
}

1742 1743 1744 1745 1746 1747
export enum ShellQuoting {
	Escape = 1,
	Strong = 2,
	Weak = 3
}

D
Dirk Baeumer 已提交
1748 1749 1750 1751 1752
export enum TaskScope {
	Global = 1,
	Workspace = 2
}

G
Gabriel DeBacker 已提交
1753
export class CustomExecution implements vscode.CustomExecution {
G
Gabriel DeBacker 已提交
1754
	private _callback: (args: vscode.TerminalRenderer, cancellationToken: vscode.CancellationToken) => Thenable<number>;
1755

G
Gabriel DeBacker 已提交
1756
	constructor(callback: (args: vscode.TerminalRenderer, cancellationToken: vscode.CancellationToken) => Thenable<number>) {
1757 1758 1759 1760
		this._callback = callback;
	}

	public computeId(): string {
1761
		return 'customExecution' + generateUuid();
1762 1763
	}

G
Gabriel DeBacker 已提交
1764
	public set callback(value: (args: vscode.TerminalRenderer, cancellationToken: vscode.CancellationToken) => Thenable<number>) {
1765 1766 1767
		this._callback = value;
	}

G
Gabriel DeBacker 已提交
1768
	public get callback(): (args: vscode.TerminalRenderer, cancellationToken: vscode.CancellationToken) => Thenable<number> {
1769 1770 1771 1772
		return this._callback;
	}
}

J
Johannes Rieken 已提交
1773
@es5ClassCompat
G
Gabriel DeBacker 已提交
1774
export class Task implements vscode.Task2 {
1775

G
Gabriel DeBacker 已提交
1776
	private static ExtensionCallbackType: string = 'customExecution';
1777 1778 1779 1780 1781
	private static ProcessType: string = 'process';
	private static ShellType: string = 'shell';
	private static EmptyType: string = '$empty';

	private __id: string | undefined;
1782

D
Dirk Baeumer 已提交
1783
	private _definition: vscode.TaskDefinition;
1784
	private _scope: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder | undefined;
D
Dirk Baeumer 已提交
1785
	private _name: string;
G
Gabriel DeBacker 已提交
1786
	private _execution: ProcessExecution | ShellExecution | CustomExecution | undefined;
D
Dirk Baeumer 已提交
1787
	private _problemMatchers: string[];
1788
	private _hasDefinedMatchers: boolean;
D
Dirk Baeumer 已提交
1789 1790
	private _isBackground: boolean;
	private _source: string;
1791
	private _group: TaskGroup | undefined;
D
Dirk Baeumer 已提交
1792
	private _presentationOptions: vscode.TaskPresentationOptions;
A
Alex Ross 已提交
1793
	private _runOptions: vscode.RunOptions;
1794

G
Gabriel DeBacker 已提交
1795 1796
	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 已提交
1797
	constructor(definition: vscode.TaskDefinition, arg2: string | (vscode.TaskScope.Global | vscode.TaskScope.Workspace) | vscode.WorkspaceFolder, arg3: any, arg4?: any, arg5?: any, arg6?: any) {
D
Dirk Baeumer 已提交
1798
		this.definition = definition;
D
Dirk Baeumer 已提交
1799 1800 1801 1802 1803 1804
		let problemMatchers: string | string[];
		if (typeof arg2 === 'string') {
			this.name = arg2;
			this.source = arg3;
			this.execution = arg4;
			problemMatchers = arg5;
D
Dirk Baeumer 已提交
1805 1806 1807 1808 1809 1810
		} else if (arg2 === TaskScope.Global || arg2 === TaskScope.Workspace) {
			this.target = arg2;
			this.name = arg3;
			this.source = arg4;
			this.execution = arg5;
			problemMatchers = arg6;
D
Dirk Baeumer 已提交
1811
		} else {
D
Dirk Baeumer 已提交
1812
			this.target = arg2;
D
Dirk Baeumer 已提交
1813 1814 1815 1816 1817
			this.name = arg3;
			this.source = arg4;
			this.execution = arg5;
			problemMatchers = arg6;
		}
1818 1819
		if (typeof problemMatchers === 'string') {
			this._problemMatchers = [problemMatchers];
1820
			this._hasDefinedMatchers = true;
1821 1822
		} else if (Array.isArray(problemMatchers)) {
			this._problemMatchers = problemMatchers;
1823
			this._hasDefinedMatchers = true;
1824 1825
		} else {
			this._problemMatchers = [];
1826
			this._hasDefinedMatchers = false;
1827
		}
D
Dirk Baeumer 已提交
1828
		this._isBackground = false;
1829 1830
		this._presentationOptions = Object.create(null);
		this._runOptions = Object.create(null);
1831
	}
1832

1833
	get _id(): string | undefined {
1834 1835 1836
		return this.__id;
	}

1837
	set _id(value: string | undefined) {
1838 1839 1840 1841
		this.__id = value;
	}

	private clear(): void {
R
Rob Lourens 已提交
1842
		if (this.__id === undefined) {
D
Dirk Baeumer 已提交
1843 1844
			return;
		}
1845
		this.__id = undefined;
D
Dirk Baeumer 已提交
1846
		this._scope = undefined;
1847 1848 1849 1850
		this.computeDefinitionBasedOnExecution();
	}

	private computeDefinitionBasedOnExecution(): void {
D
Dirk Baeumer 已提交
1851 1852
		if (this._execution instanceof ProcessExecution) {
			this._definition = {
1853
				type: Task.ProcessType,
D
Dirk Baeumer 已提交
1854 1855 1856 1857
				id: this._execution.computeId()
			};
		} else if (this._execution instanceof ShellExecution) {
			this._definition = {
1858
				type: Task.ShellType,
D
Dirk Baeumer 已提交
1859 1860
				id: this._execution.computeId()
			};
G
Gabriel DeBacker 已提交
1861
		} else if (this._execution instanceof CustomExecution) {
1862 1863 1864 1865
			this._definition = {
				type: Task.ExtensionCallbackType,
				id: this._execution.computeId()
			};
1866 1867 1868 1869 1870
		} else {
			this._definition = {
				type: Task.EmptyType,
				id: generateUuid()
			};
D
Dirk Baeumer 已提交
1871
		}
1872 1873
	}

D
Dirk Baeumer 已提交
1874 1875
	get definition(): vscode.TaskDefinition {
		return this._definition;
D
Dirk Baeumer 已提交
1876
	}
1877

D
Dirk Baeumer 已提交
1878
	set definition(value: vscode.TaskDefinition) {
R
Rob Lourens 已提交
1879
		if (value === undefined || value === null) {
D
Dirk Baeumer 已提交
1880
			throw illegalArgument('Kind can\'t be undefined or null');
1881
		}
1882
		this.clear();
D
Dirk Baeumer 已提交
1883
		this._definition = value;
D
Dirk Baeumer 已提交
1884
	}
1885

1886
	get scope(): vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder | undefined {
D
Dirk Baeumer 已提交
1887
		return this._scope;
D
Dirk Baeumer 已提交
1888 1889
	}

D
Dirk Baeumer 已提交
1890
	set target(value: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder) {
1891
		this.clear();
D
Dirk Baeumer 已提交
1892
		this._scope = value;
D
Dirk Baeumer 已提交
1893 1894
	}

D
Dirk Baeumer 已提交
1895 1896 1897 1898 1899 1900 1901
	get name(): string {
		return this._name;
	}

	set name(value: string) {
		if (typeof value !== 'string') {
			throw illegalArgument('name');
1902
		}
1903
		this.clear();
D
Dirk Baeumer 已提交
1904
		this._name = value;
1905 1906
	}

1907
	get execution(): ProcessExecution | ShellExecution | undefined {
G
Gabriel DeBacker 已提交
1908
		return (this._execution instanceof CustomExecution) ? undefined : this._execution;
1909 1910 1911
	}

	set execution(value: ProcessExecution | ShellExecution | undefined) {
G
Gabriel DeBacker 已提交
1912
		this.execution2 = value;
1913 1914
	}

G
Gabriel DeBacker 已提交
1915
	get execution2(): ProcessExecution | ShellExecution | CustomExecution | undefined {
D
Dirk Baeumer 已提交
1916
		return this._execution;
1917
	}
D
Dirk Baeumer 已提交
1918

G
Gabriel DeBacker 已提交
1919
	set execution2(value: ProcessExecution | ShellExecution | CustomExecution | undefined) {
D
Dirk Baeumer 已提交
1920 1921 1922
		if (value === null) {
			value = undefined;
		}
1923
		this.clear();
D
Dirk Baeumer 已提交
1924
		this._execution = value;
1925
		const type = this._definition.type;
1926
		if (Task.EmptyType === type || Task.ProcessType === type || Task.ShellType === type || Task.ExtensionCallbackType === type) {
1927 1928
			this.computeDefinitionBasedOnExecution();
		}
D
Dirk Baeumer 已提交
1929 1930
	}

D
Dirk Baeumer 已提交
1931 1932 1933 1934 1935
	get problemMatchers(): string[] {
		return this._problemMatchers;
	}

	set problemMatchers(value: string[]) {
D
Dirk Baeumer 已提交
1936
		if (!Array.isArray(value)) {
1937
			this.clear();
1938 1939 1940
			this._problemMatchers = [];
			this._hasDefinedMatchers = false;
			return;
1941 1942 1943 1944
		} else {
			this.clear();
			this._problemMatchers = value;
			this._hasDefinedMatchers = true;
D
Dirk Baeumer 已提交
1945
		}
1946 1947 1948 1949
	}

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

D
Dirk Baeumer 已提交
1952 1953
	get isBackground(): boolean {
		return this._isBackground;
D
Dirk Baeumer 已提交
1954 1955
	}

D
Dirk Baeumer 已提交
1956 1957 1958
	set isBackground(value: boolean) {
		if (value !== true && value !== false) {
			value = false;
D
Dirk Baeumer 已提交
1959
		}
1960
		this.clear();
D
Dirk Baeumer 已提交
1961
		this._isBackground = value;
D
Dirk Baeumer 已提交
1962
	}
1963

D
Dirk Baeumer 已提交
1964 1965 1966
	get source(): string {
		return this._source;
	}
1967

D
Dirk Baeumer 已提交
1968 1969 1970
	set source(value: string) {
		if (typeof value !== 'string' || value.length === 0) {
			throw illegalArgument('source must be a string of length > 0');
1971
		}
1972
		this.clear();
D
Dirk Baeumer 已提交
1973
		this._source = value;
1974 1975
	}

1976
	get group(): TaskGroup | undefined {
D
Dirk Baeumer 已提交
1977
		return this._group;
1978
	}
D
Dirk Baeumer 已提交
1979

1980 1981 1982
	set group(value: TaskGroup | undefined) {
		if (value === null) {
			value = undefined;
D
Dirk Baeumer 已提交
1983
		}
1984
		this.clear();
D
Dirk Baeumer 已提交
1985
		this._group = value;
D
Dirk Baeumer 已提交
1986 1987
	}

D
Dirk Baeumer 已提交
1988 1989 1990 1991 1992
	get presentationOptions(): vscode.TaskPresentationOptions {
		return this._presentationOptions;
	}

	set presentationOptions(value: vscode.TaskPresentationOptions) {
1993 1994
		if (value === null || value === undefined) {
			value = Object.create(null);
D
Dirk Baeumer 已提交
1995
		}
1996
		this.clear();
D
Dirk Baeumer 已提交
1997
		this._presentationOptions = value;
D
Dirk Baeumer 已提交
1998
	}
A
Alex Ross 已提交
1999 2000 2001 2002 2003 2004

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

	set runOptions(value: vscode.RunOptions) {
2005 2006
		if (value === null || value === undefined) {
			value = Object.create(null);
A
Alex Ross 已提交
2007 2008 2009 2010
		}
		this.clear();
		this._runOptions = value;
	}
2011
}
J
Johannes Rieken 已提交
2012

D
Dirk Baeumer 已提交
2013

J
Johannes Rieken 已提交
2014
export enum ProgressLocation {
2015
	SourceControl = 1,
J
Johannes Rieken 已提交
2016
	Window = 10,
2017
	Notification = 15
J
Johannes Rieken 已提交
2018
}
S
Sandeep Somavarapu 已提交
2019

J
Johannes Rieken 已提交
2020
@es5ClassCompat
S
Sandeep Somavarapu 已提交
2021 2022
export class TreeItem {

S
Sandeep Somavarapu 已提交
2023
	label?: string | vscode.TreeItemLabel;
2024
	resourceUri?: URI;
2025
	iconPath?: string | URI | { light: string | URI; dark: string | URI };
S
Sandeep Somavarapu 已提交
2026 2027
	command?: vscode.Command;
	contextValue?: string;
S
Sandeep Somavarapu 已提交
2028
	tooltip?: string;
S
Sandeep Somavarapu 已提交
2029

S
Sandeep Somavarapu 已提交
2030
	constructor(label: string | vscode.TreeItemLabel, collapsibleState?: vscode.TreeItemCollapsibleState)
2031
	constructor(resourceUri: URI, collapsibleState?: vscode.TreeItemCollapsibleState)
S
Sandeep Somavarapu 已提交
2032
	constructor(arg1: string | vscode.TreeItemLabel | URI, public collapsibleState: vscode.TreeItemCollapsibleState = TreeItemCollapsibleState.None) {
2033 2034 2035 2036 2037
		if (arg1 instanceof URI) {
			this.resourceUri = arg1;
		} else {
			this.label = arg1;
		}
S
Sandeep Somavarapu 已提交
2038 2039 2040 2041
	}

}

S
Sandeep Somavarapu 已提交
2042
export enum TreeItemCollapsibleState {
2043
	None = 0,
S
Sandeep Somavarapu 已提交
2044 2045 2046
	Collapsed = 1,
	Expanded = 2
}
2047

2048
@es5ClassCompat
2049
export class ThemeIcon {
2050

2051 2052
	static File: ThemeIcon;
	static Folder: ThemeIcon;
2053 2054 2055

	readonly id: string;

2056
	constructor(id: string) {
2057 2058 2059
		this.id = id;
	}
}
2060 2061 2062
ThemeIcon.File = new ThemeIcon('file');
ThemeIcon.Folder = new ThemeIcon('folder');

2063

J
Johannes Rieken 已提交
2064
@es5ClassCompat
2065 2066 2067 2068 2069
export class ThemeColor {
	id: string;
	constructor(id: string) {
		this.id = id;
	}
2070
}
S
Sandeep Somavarapu 已提交
2071 2072 2073 2074 2075 2076 2077

export enum ConfigurationTarget {
	Global = 1,

	Workspace = 2,

	WorkspaceFolder = 3
2078
}
2079

J
Johannes Rieken 已提交
2080
@es5ClassCompat
2081 2082
export class RelativePattern implements IRelativePattern {
	base: string;
2083 2084
	baseFolder?: URI;

2085 2086
	pattern: string;

2087
	constructor(base: vscode.WorkspaceFolder | string, pattern: string) {
2088 2089 2090 2091 2092 2093 2094 2095 2096 2097
		if (typeof base !== 'string') {
			if (!base || !URI.isUri(base.uri)) {
				throw illegalArgument('base');
			}
		}

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

2098 2099 2100 2101 2102 2103 2104
		if (typeof base === 'string') {
			this.base = base;
		} else {
			this.baseFolder = base.uri;
			this.base = base.uri.fsPath;
		}

2105
		this.pattern = pattern;
2106
	}
J
Johannes Rieken 已提交
2107
}
2108

J
Johannes Rieken 已提交
2109
@es5ClassCompat
2110 2111
export class Breakpoint {

2112 2113
	private _id: string | undefined;

2114 2115 2116
	readonly enabled: boolean;
	readonly condition?: string;
	readonly hitCondition?: string;
2117
	readonly logMessage?: string;
2118

2119
	protected constructor(enabled?: boolean, condition?: string, hitCondition?: string, logMessage?: string) {
2120 2121 2122 2123 2124 2125 2126
		this.enabled = typeof enabled === 'boolean' ? enabled : true;
		if (typeof condition === 'string') {
			this.condition = condition;
		}
		if (typeof hitCondition === 'string') {
			this.hitCondition = hitCondition;
		}
2127 2128 2129
		if (typeof logMessage === 'string') {
			this.logMessage = logMessage;
		}
2130
	}
2131 2132 2133 2134 2135 2136 2137

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

J
Johannes Rieken 已提交
2140
@es5ClassCompat
2141 2142 2143
export class SourceBreakpoint extends Breakpoint {
	readonly location: Location;

2144 2145
	constructor(location: Location, enabled?: boolean, condition?: string, hitCondition?: string, logMessage?: string) {
		super(enabled, condition, hitCondition, logMessage);
2146 2147 2148
		if (location === null) {
			throw illegalArgument('location');
		}
2149 2150 2151 2152
		this.location = location;
	}
}

J
Johannes Rieken 已提交
2153
@es5ClassCompat
2154 2155 2156
export class FunctionBreakpoint extends Breakpoint {
	readonly functionName: string;

2157 2158
	constructor(functionName: string, enabled?: boolean, condition?: string, hitCondition?: string, logMessage?: string) {
		super(enabled, condition, hitCondition, logMessage);
2159 2160 2161
		if (!functionName) {
			throw illegalArgument('functionName');
		}
2162 2163 2164
		this.functionName = functionName;
	}
}
2165

J
Johannes Rieken 已提交
2166
@es5ClassCompat
2167 2168 2169
export class DebugAdapterExecutable implements vscode.DebugAdapterExecutable {
	readonly command: string;
	readonly args: string[];
2170
	readonly options?: vscode.DebugAdapterExecutableOptions;
2171

2172
	constructor(command: string, args: string[], options?: vscode.DebugAdapterExecutableOptions) {
2173
		this.command = command;
2174 2175
		this.args = args || [];
		this.options = options;
2176 2177 2178
	}
}

J
Johannes Rieken 已提交
2179
@es5ClassCompat
2180 2181
export class DebugAdapterServer implements vscode.DebugAdapterServer {
	readonly port: number;
A
Andre Weinand 已提交
2182
	readonly host?: string;
2183

2184
	constructor(port: number, host?: string) {
2185
		this.port = port;
2186
		this.host = host;
2187 2188 2189
	}
}

2190
/*
J
Johannes Rieken 已提交
2191
@es5ClassCompat
A
Andre Weinand 已提交
2192 2193 2194 2195 2196 2197 2198
export class DebugAdapterImplementation implements vscode.DebugAdapterImplementation {
	readonly implementation: any;

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

2201 2202 2203 2204 2205 2206 2207 2208 2209
export enum LogLevel {
	Trace = 1,
	Debug = 2,
	Info = 3,
	Warning = 4,
	Error = 5,
	Critical = 6,
	Off = 7
}
J
Johannes Rieken 已提交
2210 2211 2212

//#region file api

2213
export enum FileChangeType {
2214 2215 2216 2217 2218
	Changed = 1,
	Created = 2,
	Deleted = 3,
}

J
Johannes Rieken 已提交
2219
@es5ClassCompat
2220
export class FileSystemError extends Error {
2221

2222
	static FileExists(messageOrUri?: string | URI): FileSystemError {
2223
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.FileExists, FileSystemError.FileExists);
J
Johannes Rieken 已提交
2224
	}
2225
	static FileNotFound(messageOrUri?: string | URI): FileSystemError {
2226
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.FileNotFound, FileSystemError.FileNotFound);
J
Johannes Rieken 已提交
2227
	}
2228
	static FileNotADirectory(messageOrUri?: string | URI): FileSystemError {
2229
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.FileNotADirectory, FileSystemError.FileNotADirectory);
J
Johannes Rieken 已提交
2230
	}
2231
	static FileIsADirectory(messageOrUri?: string | URI): FileSystemError {
2232
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.FileIsADirectory, FileSystemError.FileIsADirectory);
J
Johannes Rieken 已提交
2233
	}
2234
	static NoPermissions(messageOrUri?: string | URI): FileSystemError {
2235
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.NoPermissions, FileSystemError.NoPermissions);
2236
	}
2237
	static Unavailable(messageOrUri?: string | URI): FileSystemError {
2238
		return new FileSystemError(messageOrUri, FileSystemProviderErrorCode.Unavailable, FileSystemError.Unavailable);
2239
	}
2240

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

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

2248 2249 2250 2251 2252 2253
		// 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 已提交
2254
		if (typeof Error.captureStackTrace === 'function' && typeof terminator === 'function') {
J
Johannes Rieken 已提交
2255
			// nice stack traces
J
Johannes Rieken 已提交
2256
			Error.captureStackTrace(this, terminator);
J
Johannes Rieken 已提交
2257
		}
2258 2259 2260
	}
}

J
Johannes Rieken 已提交
2261
//#endregion
2262 2263 2264

//#region folding api

J
Johannes Rieken 已提交
2265
@es5ClassCompat
2266 2267
export class FoldingRange {

2268
	start: number;
2269

2270
	end: number;
2271

2272
	kind?: FoldingRangeKind;
2273

2274 2275 2276 2277
	constructor(start: number, end: number, kind?: FoldingRangeKind) {
		this.start = start;
		this.end = end;
		this.kind = kind;
2278 2279 2280
	}
}

2281 2282 2283 2284
export enum FoldingRangeKind {
	Comment = 1,
	Imports = 2,
	Region = 3
2285 2286
}

2287
//#endregion
2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298


export enum CommentThreadCollapsibleState {
	/**
	 * Determines an item is collapsed
	 */
	Collapsed = 0,
	/**
	 * Determines an item is expanded
	 */
	Expanded = 1
2299
}
2300

J
Johannes Rieken 已提交
2301
@es5ClassCompat
2302 2303 2304 2305 2306 2307
export class QuickInputButtons {

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

	private constructor() { }
}