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

import URI from 'vs/base/common/uri';
8
import { illegalArgument } from 'vs/base/common/errors';
9
import * as vscode from 'vscode';
E
Erich Gamma 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

export class Disposable {

	static from(...disposables: { dispose(): any }[]): Disposable {
		return new Disposable(function () {
			if (disposables) {
				for (let disposable of disposables) {
					if (disposable && typeof disposable.dispose === 'function') {
						disposable.dispose();
					}
				}
				disposables = undefined;
			}
		});
	}

	private _callOnDispose: Function;

	constructor(callOnDispose: Function) {
		this._callOnDispose = callOnDispose;
	}

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

export class Position {

	static Min(...positions: Position[]): Position {
		let result = positions.pop();
		for (let p of positions) {
			if (p.isBefore(result)) {
				result = p;
			}
		}
		return result;
	}

	static Max(...positions: Position[]): Position {
		let result = positions.pop();
		for (let p of positions) {
			if (p.isAfter(result)) {
				result = p;
			}
		}
		return result;
	}

62
	static isPosition(other: any): other is Position {
63 64 65 66 67 68
		if (!other) {
			return false;
		}
		if (other instanceof Position) {
			return true;
		}
69
		let { line, character } = <Position>other;
70 71 72 73 74 75
		if (typeof line === 'number' && typeof character === 'number') {
			return true;
		}
		return false;
	}

E
Erich Gamma 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 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
	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) {
			throw illegalArgument('line must be positive');
		}
		if (character < 0) {
			throw illegalArgument('character must be positive');
		}
		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;
			}
		}
	}

148
	translate(change: { lineDelta?: number; characterDelta?: number; }): Position;
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
	translate(lineDelta?: number, characterDelta?: number): Position;
	translate(lineDeltaOrChange: number | { lineDelta?: number; characterDelta?: number; }, characterDelta: number = 0): Position {

		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 已提交
166 167 168 169 170 171
		if (lineDelta === 0 && characterDelta === 0) {
			return this;
		}
		return new Position(this.line + lineDelta, this.character + characterDelta);
	}

172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
	with(change: { line?: number; character?: number; }): Position;
	with(line?: number, character?: number): Position;
	with(lineOrChange: number | { line?: number; character?: number; }, character: number = this.character): Position {

		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 已提交
192 193 194 195 196
		if (line === this.line && character === this.character) {
			return this;
		}
		return new Position(line, character);
	}
197 198

	toJSON(): any {
J
Johannes Rieken 已提交
199
		return { line: this.line, character: this.character };
200
	}
E
Erich Gamma 已提交
201 202 203 204
}

export class Range {

205
	static isRange(thing: any): thing is Range {
J
Johannes Rieken 已提交
206 207 208 209 210 211
		if (thing instanceof Range) {
			return true;
		}
		if (!thing) {
			return false;
		}
212 213
		return Position.isPosition((<Range>thing).start)
			&& Position.isPosition((<Range>thing.end));
J
Johannes Rieken 已提交
214 215
	}

E
Erich Gamma 已提交
216 217 218 219 220 221 222 223 224 225 226 227
	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 已提交
228
	constructor(startLine: number, startColumn: number, endLine: number, endColumn: number);
229
	constructor(startLineOrStart: number | Position, startColumnOrEnd: number | Position, endLine?: number, endColumn?: number) {
E
Erich Gamma 已提交
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
		let start: Position;
		let end: Position;

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

	intersection(other: Range): Range {
		let start = Position.Max(other.start, this._start);
		let end = Position.Min(other.end, this._end);
		if (start.isAfter(end)) {
			// this happens when there is no overlap:
			// |-----|
			//          |----|
M
Matt Bierner 已提交
282
			return undefined;
E
Erich Gamma 已提交
283 284 285 286 287 288 289 290 291 292
		}
		return new Range(start, end);
	}

	union(other: Range): Range {
		if (this.contains(other)) {
			return this;
		} else if (other.contains(this)) {
			return other;
		}
B
Benjamin Pasero 已提交
293 294
		let start = Position.Min(other.start, this._start);
		let end = Position.Max(other.end, this.end);
E
Erich Gamma 已提交
295 296 297 298 299 300 301 302 303 304 305
		return new Range(start, end);
	}

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

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

306 307 308 309 310 311 312 313 314 315 316 317
	with(change: { start?: Position, end?: Position }): Range;
	with(start?: Position, end?: Position): Range;
	with(startOrChange: Position | { start?: Position, end?: Position }, end: Position = this.end): Range {

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

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

318
		} else if (Position.isPosition(startOrChange)) {
319 320 321 322 323 324 325
			start = startOrChange;

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

E
Erich Gamma 已提交
326 327 328 329 330
		if (start.isEqual(this._start) && end.isEqual(this.end)) {
			return this;
		}
		return new Range(start, end);
	}
331 332 333 334

	toJSON(): any {
		return [this.start, this.end];
	}
E
Erich Gamma 已提交
335 336 337 338
}

export class Selection extends Range {

339 340 341 342 343 344 345 346 347 348 349 350 351
	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 已提交
352 353 354 355 356 357 358 359 360 361 362 363 364
	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 已提交
365
	constructor(anchorLine: number, anchorColumn: number, activeLine: number, activeColumn: number);
366
	constructor(anchorLineOrAnchor: number | Position, anchorColumnOrActive: number | Position, activeLine?: number, activeColumn?: number) {
E
Erich Gamma 已提交
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
		let anchor: Position;
		let active: Position;

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

382 383
		super(anchor, active);

E
Erich Gamma 已提交
384 385 386 387 388 389 390
		this._anchor = anchor;
		this._active = active;
	}

	get isReversed(): boolean {
		return this._anchor === this._end;
	}
391 392 393 394 395 396 397

	toJSON() {
		return {
			start: this.start,
			end: this.end,
			active: this.active,
			anchor: this.anchor
B
Benjamin Pasero 已提交
398
		};
399
	}
E
Erich Gamma 已提交
400 401
}

402 403 404 405 406
export enum EndOfLine {
	LF = 1,
	CRLF = 2
}

E
Erich Gamma 已提交
407 408
export class TextEdit {

409 410 411 412 413 414 415 416 417 418 419
	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 已提交
420 421 422 423 424 425 426 427 428 429 430 431
	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, '');
	}

432 433 434 435 436
	static setEndOfLine(eol: EndOfLine): TextEdit {
		let ret = new TextEdit(undefined, undefined);
		ret.newEol = eol;
		return ret;
	}
E
Erich Gamma 已提交
437

438
	protected _range: Range;
E
Erich Gamma 已提交
439
	protected _newText: string;
440
	protected _newEol: EndOfLine;
E
Erich Gamma 已提交
441 442 443 444 445 446

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

	set range(value: Range) {
447
		if (value && !Range.isRange(value)) {
B
Benjamin Pasero 已提交
448
			throw illegalArgument('range');
E
Erich Gamma 已提交
449 450 451 452 453 454 455 456
		}
		this._range = value;
	}

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

457 458 459 460
	set newText(value: string) {
		if (value && typeof value !== 'string') {
			throw illegalArgument('newText');
		}
E
Erich Gamma 已提交
461 462 463
		this._newText = value;
	}

464 465 466 467 468 469 470 471 472 473 474
	get newEol(): EndOfLine {
		return this._newEol;
	}

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

E
Erich Gamma 已提交
475 476 477 478
	constructor(range: Range, newText: string) {
		this.range = range;
		this.newText = newText;
	}
479 480 481 482

	toJSON(): any {
		return {
			range: this.range,
483 484
			newText: this.newText,
			newEol: this._newEol
485 486
		};
	}
E
Erich Gamma 已提交
487 488
}

J
Johannes Rieken 已提交
489
export class Uri extends URI { }
E
Erich Gamma 已提交
490 491 492 493

export class WorkspaceEdit {

	private _values: [Uri, TextEdit[]][] = [];
J
Johannes Rieken 已提交
494
	private _index = new Map<string, number>();
E
Erich Gamma 已提交
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514

	replace(uri: Uri, range: Range, newText: string): void {
		let edit = new TextEdit(range, newText);
		let array = this.get(uri);
		if (array) {
			array.push(edit);
		} else {
			this.set(uri, [edit]);
		}
	}

	insert(resource: Uri, position: Position, newText: string): void {
		this.replace(resource, new Range(position, position), newText);
	}

	delete(resource: Uri, range: Range): void {
		this.replace(resource, range, '');
	}

	has(uri: Uri): boolean {
J
Johannes Rieken 已提交
515
		return this._index.has(uri.toString());
E
Erich Gamma 已提交
516 517 518
	}

	set(uri: Uri, edits: TextEdit[]): void {
J
Johannes Rieken 已提交
519
		const idx = this._index.get(uri.toString());
E
Erich Gamma 已提交
520 521
		if (typeof idx === 'undefined') {
			let newLen = this._values.push([uri, edits]);
J
Johannes Rieken 已提交
522
			this._index.set(uri.toString(), newLen - 1);
E
Erich Gamma 已提交
523 524 525 526 527 528
		} else {
			this._values[idx][1] = edits;
		}
	}

	get(uri: Uri): TextEdit[] {
J
Johannes Rieken 已提交
529
		let idx = this._index.get(uri.toString());
E
Erich Gamma 已提交
530 531 532 533 534 535 536 537 538 539
		return typeof idx !== 'undefined' && this._values[idx][1];
	}

	entries(): [Uri, TextEdit[]][] {
		return this._values;
	}

	get size(): number {
		return this._values.length;
	}
540 541 542 543

	toJSON(): any {
		return this._values;
	}
E
Erich Gamma 已提交
544 545
}

546 547
export class SnippetString {

J
Joel Day 已提交
548 549 550 551 552 553 554 555 556 557
	static isSnippetString(thing: any): thing is SnippetString {
		if (thing instanceof SnippetString) {
			return true;
		}
		if (!thing) {
			return false;
		}
		return typeof (<SnippetString>thing).value === 'string';
	}

558 559 560 561
	private static _escape(value: string): string {
		return value.replace(/\$|}|\\/g, '\\$&');
	}

562 563
	private _tabstop: number = 1;

564 565
	value: string;

566 567 568 569 570
	constructor(value?: string) {
		this.value = value || '';
	}

	appendText(string: string): SnippetString {
571
		this.value += SnippetString._escape(string);
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
		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 {
590
			value = SnippetString._escape(value);
591 592 593 594 595 596 597 598
		}

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

599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
		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 += '}';


624
		return this;
625 626 627
	}
}

E
Erich Gamma 已提交
628 629 630 631 632 633 634 635 636
export enum DiagnosticSeverity {
	Hint = 3,
	Information = 2,
	Warning = 1,
	Error = 0
}

export class Location {

637 638 639 640 641 642 643 644 645 646 647
	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 已提交
648 649 650
	uri: URI;
	range: Range;

651
	constructor(uri: URI, rangeOrPosition: Range | Position) {
E
Erich Gamma 已提交
652 653
		this.uri = uri;

654 655 656 657 658 659
		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 已提交
660 661 662 663
		} else {
			throw new Error('Illegal argument');
		}
	}
664 665 666 667 668 669 670

	toJSON(): any {
		return {
			uri: this.uri,
			range: this.range
		};
	}
E
Erich Gamma 已提交
671 672 673 674 675 676
}

export class Diagnostic {

	range: Range;
	message: string;
677
	source: string;
E
Erich Gamma 已提交
678 679 680 681 682 683 684 685
	code: string | number;
	severity: DiagnosticSeverity;

	constructor(range: Range, message: string, severity: DiagnosticSeverity = DiagnosticSeverity.Error) {
		this.range = range;
		this.message = message;
		this.severity = severity;
	}
686 687 688 689 690 691 692 693

	toJSON(): any {
		return {
			severity: DiagnosticSeverity[this.severity],
			message: this.message,
			range: this.range,
			source: this.source,
			code: this.code,
B
Benjamin Pasero 已提交
694
		};
695
	}
E
Erich Gamma 已提交
696 697 698 699 700 701 702
}

export class Hover {

	public contents: vscode.MarkedString[];
	public range: Range;

J
Johannes Rieken 已提交
703
	constructor(contents: vscode.MarkedString | vscode.MarkedString[], range?: Range) {
E
Erich Gamma 已提交
704
		if (!contents) {
705
			throw new Error('Illegal argument, contents must be defined');
E
Erich Gamma 已提交
706 707 708 709 710 711 712 713 714 715 716 717
		}

		if (Array.isArray(contents)) {
			this.contents = contents;
		} else {
			this.contents = [contents];
		}
		this.range = range;
	}
}

export enum DocumentHighlightKind {
718 719 720
	Text = 0,
	Read = 1,
	Write = 2
E
Erich Gamma 已提交
721 722 723 724 725 726 727 728 729 730 731
}

export class DocumentHighlight {

	range: Range;
	kind: DocumentHighlightKind;

	constructor(range: Range, kind: DocumentHighlightKind = DocumentHighlightKind.Text) {
		this.range = range;
		this.kind = kind;
	}
732 733 734 735 736

	toJSON(): any {
		return {
			range: this.range,
			kind: DocumentHighlightKind[this.kind]
B
Benjamin Pasero 已提交
737
		};
738
	}
E
Erich Gamma 已提交
739 740 741
}

export enum SymbolKind {
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763
	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,
764 765
	Struct = 22,
	Event = 23,
766 767
	Operator = 24,
	TypeParameter = 25
E
Erich Gamma 已提交
768 769 770 771 772 773 774 775 776
}

export class SymbolInformation {

	name: string;
	location: Location;
	kind: SymbolKind;
	containerName: string;

777 778 779
	constructor(name: string, kind: SymbolKind, containerName: string, location: Location);
	constructor(name: string, kind: SymbolKind, range: Range, uri?: URI, containerName?: string);
	constructor(name: string, kind: SymbolKind, rangeOrContainer: string | Range, locationOrUri?: Location | URI, containerName?: string) {
E
Erich Gamma 已提交
780 781 782
		this.name = name;
		this.kind = kind;
		this.containerName = containerName;
783 784 785 786 787 788 789

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

		if (locationOrUri instanceof Location) {
			this.location = locationOrUri;
790
		} else if (rangeOrContainer instanceof Range) {
791
			this.location = new Location(<URI>locationOrUri, rangeOrContainer);
792
		}
E
Erich Gamma 已提交
793
	}
794 795 796 797 798 799 800

	toJSON(): any {
		return {
			name: this.name,
			kind: SymbolKind[this.kind],
			location: this.location,
			containerName: this.containerName
B
Benjamin Pasero 已提交
801
		};
802
	}
E
Erich Gamma 已提交
803 804 805 806 807 808 809 810 811 812
}

export class CodeLens {

	range: Range;

	command: vscode.Command;

	constructor(range: Range, command?: vscode.Command) {
		this.range = range;
813
		this.command = command;
E
Erich Gamma 已提交
814 815 816 817 818 819 820 821 822 823
	}

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

export class ParameterInformation {

	label: string;
824
	documentation?: string;
E
Erich Gamma 已提交
825 826 827 828 829 830 831 832 833 834

	constructor(label: string, documentation?: string) {
		this.label = label;
		this.documentation = documentation;
	}
}

export class SignatureInformation {

	label: string;
835
	documentation?: string;
E
Erich Gamma 已提交
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
	parameters: ParameterInformation[];

	constructor(label: string, documentation?: string) {
		this.label = label;
		this.documentation = documentation;
		this.parameters = [];
	}
}

export class SignatureHelp {

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

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

export enum CompletionItemKind {
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
	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,
874
	Reference = 17,
875 876
	Folder = 18,
	EnumMember = 19,
877
	Constant = 20,
878 879
	Struct = 21,
	Event = 22,
880 881
	Operator = 23,
	TypeParameter = 24
E
Erich Gamma 已提交
882 883 884 885 886
}

export class CompletionItem {

	label: string;
J
Johannes Rieken 已提交
887
	kind: CompletionItemKind;
E
Erich Gamma 已提交
888 889 890 891
	detail: string;
	documentation: string;
	sortText: string;
	filterText: string;
892 893
	insertText: string | SnippetString;
	range: Range;
E
Erich Gamma 已提交
894
	textEdit: TextEdit;
895 896
	additionalTextEdits: TextEdit[];
	command: vscode.Command;
E
Erich Gamma 已提交
897

898
	constructor(label: string, kind?: CompletionItemKind) {
E
Erich Gamma 已提交
899
		this.label = label;
900
		this.kind = kind;
E
Erich Gamma 已提交
901
	}
902 903 904 905 906 907 908 909 910 911 912

	toJSON(): any {
		return {
			label: this.label,
			kind: CompletionItemKind[this.kind],
			detail: this.detail,
			documentation: this.documentation,
			sortText: this.sortText,
			filterText: this.filterText,
			insertText: this.insertText,
			textEdit: this.textEdit
B
Benjamin Pasero 已提交
913
		};
914
	}
E
Erich Gamma 已提交
915 916
}

917 918
export class CompletionList {

919
	isIncomplete?: boolean;
920 921 922 923 924 925 926 927 928

	items: vscode.CompletionItem[];

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

E
Erich Gamma 已提交
929 930 931 932 933 934 935 936 937
export enum ViewColumn {
	One = 1,
	Two = 2,
	Three = 3
}

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

940 941 942 943 944 945
export enum TextEditorLineNumbersStyle {
	Off = 0,
	On = 1,
	Relative = 2
}

946
export enum TextDocumentSaveReason {
947 948
	Manual = 1,
	AfterDelay = 2,
949 950 951
	FocusOut = 3
}

952 953 954
export enum TextEditorRevealType {
	Default = 0,
	InCenter = 1,
955 956
	InCenterIfOutsideViewport = 2,
	AtTop = 3
957
}
J
Johannes Rieken 已提交
958

959 960 961 962 963 964 965 966 967 968 969 970 971
export enum TextEditorSelectionChangeKind {
	Keyboard = 1,
	Mouse = 2,
	Command = 3
}

export namespace TextEditorSelectionChangeKind {
	export function fromValue(s: string) {
		switch (s) {
			case 'keyboard': return TextEditorSelectionChangeKind.Keyboard;
			case 'mouse': return TextEditorSelectionChangeKind.Mouse;
			case 'api': return TextEditorSelectionChangeKind.Command;
		}
M
Matt Bierner 已提交
972
		return undefined;
973 974 975
	}
}

J
Johannes Rieken 已提交
976 977 978 979 980 981 982
export class DocumentLink {

	range: Range;

	target: URI;

	constructor(range: Range, target: URI) {
983
		if (target && !(target instanceof URI)) {
J
Johannes Rieken 已提交
984 985
			throw illegalArgument('target');
		}
986
		if (!Range.isRange(range) || range.isEmpty) {
J
Johannes Rieken 已提交
987 988 989 990 991
			throw illegalArgument('range');
		}
		this.range = range;
		this.target = target;
	}
992
}
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020

export enum FileLocationKind {
	Auto = 1,

	Relative = 2,

	Absolute = 3
}

export enum ApplyToKind {
	AllDocuments = 1,

	OpenDocuments = 2,

	ClosedDocuments = 3
}

export enum RevealKind {
	Always = 1,

	Silent = 2,

	Never = 3
}

export class BaseTask {

	private _name: string;
1021
	private _problemMatchers: (string | vscode.ProblemMatcher)[];
D
Dirk Baeumer 已提交
1022 1023 1024
	private _identifier: string;
	private _isBackground: boolean;
	private _terminal: vscode.TerminalBehaviour;
1025

1026
	constructor(name: string, problemMatchers: (string | vscode.ProblemMatcher)[]) {
1027 1028 1029 1030
		if (typeof name !== 'string') {
			throw illegalArgument('name');
		}
		this._name = name;
D
Dirk Baeumer 已提交
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
		this._identifier = name;
		this._problemMatchers = problemMatchers || [];
		this._isBackground = false;
		this._terminal = Object.create(null);
	}

	get identifier(): string {
		return this._identifier;
	}

	set identifier(value: string) {
1042
		if (typeof value !== 'string') {
D
Dirk Baeumer 已提交
1043 1044
			throw illegalArgument('identifier');
		}
1045 1046 1047
		if (value.indexOf(':') !== -1) {
			throw illegalArgument('identifier must not contain \':\'');
		}
D
Dirk Baeumer 已提交
1048
		this._identifier = value;
1049 1050 1051 1052 1053 1054
	}

	get name(): string {
		return this._name;
	}

D
Dirk Baeumer 已提交
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
	get isBackground(): boolean {
		return this._isBackground;
	}

	set isBackground(value: boolean) {
		if (value !== true && value !== false) {
			value = false;
		}
		this._isBackground = value;
	}

	get terminal(): vscode.TerminalBehaviour {
		return this._terminal;
	}

	set terminal(value: vscode.TerminalBehaviour) {
		if (value === void 0 || value === null) {
			value = Object.create(null);
		}
		this._terminal = value;
	}

1077
	get problemMatchers(): (string | vscode.ProblemMatcher)[] {
1078 1079
		return this._problemMatchers;
	}
D
Dirk Baeumer 已提交
1080

1081
	set problemMatchers(value: (string | vscode.ProblemMatcher)[]) {
D
Dirk Baeumer 已提交
1082 1083 1084 1085 1086
		if (!Array.isArray(value)) {
			value = [];
		}
		this._problemMatchers = value;
	}
1087 1088 1089 1090 1091 1092 1093 1094 1095
}

namespace ProblemMatcher {
	export function is(value: any): value is vscode.ProblemMatcher {
		let candidate: vscode.ProblemMatcher = value;
		return candidate && !!candidate.pattern;
	}
}

1096 1097 1098 1099 1100 1101
namespace ShellOptions {
	export function is(value: any): value is vscode.ShellOptions {
		return value && ((typeof value.executable === 'string') || (typeof value.cwd === 'string') || !!value.env);
	}
}

1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
export namespace TaskGroup {
	/**
	 * The clean task group
	 */
	export const Clean: 'clean' = 'clean';

	/**
	 * The build task group
	 */
	export const Build: 'build' = 'build';

	/**
	 * The rebuild all task group
	 */
	export const RebuildAll: 'rebuildAll' = 'rebuildAll';

	/**
	 * The test task group
	 */
	export const Test: 'test' = 'test';

	export function is(value: string): value is vscode.TaskGroup {
		return value === Clean || value === Build || value === RebuildAll || value === Test;
	}
}
1127 1128 1129 1130

export class ProcessTask extends BaseTask {

	private _process: string;
D
Dirk Baeumer 已提交
1131
	private _args: string[];
1132
	private _group: vscode.TaskGroup;
D
Dirk Baeumer 已提交
1133
	private _options: vscode.ProcessOptions;
1134

1135 1136 1137
	constructor(name: string, process: string, args?: string[], problemMatchers?: vscode.ProblemMatchers);
	constructor(name: string, process: string, args: string[] | undefined, options: vscode.ProcessOptions, problemMatchers?: vscode.ProblemMatchers);
	constructor(name: string, process: string, arg3?: string[], arg4?: vscode.ProcessOptions | vscode.ProblemMatchers, arg5?: vscode.ProblemMatchers) {
1138 1139 1140
		if (typeof process !== 'string') {
			throw illegalArgument('process');
		}
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
		let args: string[];
		let options: vscode.ProcessOptions;
		let problemMatchers: vscode.ProblemMatchers;

		args = arg3 || [];
		if (arg4) {
			if (Array.isArray(arg4) || typeof arg4 === 'string' || ProblemMatcher.is(arg4)) {
				problemMatchers = arg4;
			} else {
				options = arg4;
			}
		}
		if (arg5 && !problemMatchers) {
			problemMatchers = arg5;
		}
		let pm: (string | vscode.ProblemMatcher)[];
		if (problemMatchers && (typeof problemMatchers === 'string' || ProblemMatcher.is(problemMatchers))) {
			pm = [problemMatchers];
		} else if (Array.isArray(problemMatchers)) {
			pm = problemMatchers;
		}
		pm = pm || [];
		super(name, pm);
1164
		this._process = process;
D
Dirk Baeumer 已提交
1165 1166
		this._args = args;
		this._options = options || Object.create(null);
1167 1168 1169 1170 1171
	}

	get process(): string {
		return this._process;
	}
D
Dirk Baeumer 已提交
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183

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

	set args(value: string[]) {
		if (!Array.isArray(value)) {
			value = [];
		}
		this._args = value;
	}

1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
	get group(): vscode.TaskGroup {
		return this._group;
	}

	set group(value: vscode.TaskGroup) {
		if (!TaskGroup.is(value)) {
			throw illegalArgument('group');
		}
		this._group = value;
	}

D
Dirk Baeumer 已提交
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
	get options(): vscode.ProcessOptions {
		return this._options;
	}

	set options(value: vscode.ProcessOptions) {
		if (value === void 0 || value === null) {
			value = Object.create(null);
		}
		this._options = value;
	}
1205 1206
}

1207
export class ShellTask extends BaseTask implements vscode.ShellTask {
1208 1209

	private _commandLine: string;
1210
	private _group: vscode.TaskGroup;
D
Dirk Baeumer 已提交
1211
	private _options: vscode.ShellOptions;
1212

1213 1214 1215
	constructor(name: string, commandLine: string, problemMatchers?: vscode.ProblemMatchers);
	constructor(name: string, commandLine: string, options: vscode.ShellOptions, problemMatchers?: vscode.ProblemMatchers);
	constructor(name: string, commandLine: string, optionsOrProblemMatchers?: vscode.ShellOptions | vscode.ProblemMatchers, problemMatchers?: vscode.ProblemMatchers) {
1216 1217 1218
		if (typeof commandLine !== 'string') {
			throw illegalArgument('commandLine');
		}
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
		let options: vscode.ShellOptions = undefined;
		let pm: (string | vscode.ProblemMatcher)[];
		if (ShellOptions.is(optionsOrProblemMatchers)) {
			options = optionsOrProblemMatchers;
		} else {
			problemMatchers = optionsOrProblemMatchers;
		}
		if (problemMatchers && (typeof problemMatchers === 'string' || ProblemMatcher.is(problemMatchers))) {
			pm = [problemMatchers];
		} else if (Array.isArray(problemMatchers)) {
			pm = problemMatchers;
		}
		pm = pm || [];
		super(name, pm);
1233
		this._commandLine = commandLine;
D
Dirk Baeumer 已提交
1234
		this._options = options || Object.create(null);
1235 1236 1237 1238 1239
	}

	get commandLine(): string {
		return this._commandLine;
	}
D
Dirk Baeumer 已提交
1240

1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
	get group(): vscode.TaskGroup {
		return this._group;
	}

	set group(value: vscode.TaskGroup) {
		if (!TaskGroup.is(value)) {
			throw illegalArgument('group');
		}
		this._group = value;
	}

D
Dirk Baeumer 已提交
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261
	get options(): vscode.ShellOptions {
		return this._options;
	}

	set options(value: vscode.ShellOptions) {
		if (value === void 0 || value === null) {
			value = Object.create(null);
		}
		this._options = value;
	}
1262
}
J
Johannes Rieken 已提交
1263 1264

export enum ProgressLocation {
1265
	SourceControl = 1,
J
Johannes Rieken 已提交
1266 1267
	Window = 10,
}
S
Sandeep Somavarapu 已提交
1268 1269 1270 1271 1272

export enum TreeItemCollapsibleState {
	Collapsed = 1,
	Expanded = 2
}