extHostSCM.ts 17.4 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

J
Joao Moreno 已提交
7 8
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
J
Joao 已提交
9 10 11
import Event, { Emitter, once } from 'vs/base/common/event';
import { debounce } from 'vs/base/common/decorators';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
J
Joao Moreno 已提交
12
import { asWinJsPromise } from 'vs/base/common/async';
J
Joao Moreno 已提交
13
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
14
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
15
import { MainContext, MainThreadSCMShape, SCMRawResource, SCMRawResourceSplice, SCMRawResourceSplices, IMainContext } from './extHost.protocol';
J
Joao Moreno 已提交
16
import { sortedDiff } from 'vs/base/common/arrays';
17 18
import { comparePaths } from 'vs/base/common/comparers';
import * as vscode from 'vscode';
J
Joao Moreno 已提交
19
import { ISplice } from 'vs/base/common/sequence';
J
Joao Moreno 已提交
20
import { ILogService } from 'vs/platform/log/common/log';
J
Joao Moreno 已提交
21

22 23 24 25
type ProviderHandle = number;
type GroupHandle = number;
type ResourceStateHandle = number;

J
Joao Moreno 已提交
26
function getIconPath(decorations: vscode.SourceControlResourceThemableDecorations) {
J
Joao Moreno 已提交
27
	if (!decorations) {
J
Joao Moreno 已提交
28
		return undefined;
J
Joao Moreno 已提交
29 30 31 32 33
	} else if (typeof decorations.iconPath === 'string') {
		return URI.file(decorations.iconPath).toString();
	} else if (decorations.iconPath) {
		return `${decorations.iconPath}`;
	}
M
Matt Bierner 已提交
34
	return undefined;
J
Joao Moreno 已提交
35 36
}

J
Joao 已提交
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 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
function compareResourceThemableDecorations(a: vscode.SourceControlResourceThemableDecorations, b: vscode.SourceControlResourceThemableDecorations): number {
	if (!a.iconPath && !b.iconPath) {
		return 0;
	} else if (!a.iconPath) {
		return -1;
	} else if (!b.iconPath) {
		return 1;
	}

	const aPath = typeof a.iconPath === 'string' ? a.iconPath : a.iconPath.fsPath;
	const bPath = typeof b.iconPath === 'string' ? b.iconPath : b.iconPath.fsPath;
	return comparePaths(aPath, bPath);
}

function compareResourceStatesDecorations(a: vscode.SourceControlResourceDecorations, b: vscode.SourceControlResourceDecorations): number {
	let result = 0;

	if (a.strikeThrough !== b.strikeThrough) {
		return a.strikeThrough ? 1 : -1;
	}

	if (a.faded !== b.faded) {
		return a.faded ? 1 : -1;
	}

	if (a.tooltip !== b.tooltip) {
		return (a.tooltip || '').localeCompare(b.tooltip);
	}

	result = compareResourceThemableDecorations(a, b);

	if (result !== 0) {
		return result;
	}

	if (a.light && b.light) {
		result = compareResourceThemableDecorations(a.light, b.light);
	} else if (a.light) {
		return 1;
	} else if (b.light) {
		return -1;
	}

	if (result !== 0) {
		return result;
	}

	if (a.dark && b.dark) {
		result = compareResourceThemableDecorations(a.dark, b.dark);
	} else if (a.dark) {
		return 1;
	} else if (b.dark) {
		return -1;
	}

	return result;
}

function compareResourceStates(a: vscode.SourceControlResourceState, b: vscode.SourceControlResourceState): number {
	let result = comparePaths(a.resourceUri.fsPath, b.resourceUri.fsPath);

	if (result !== 0) {
		return result;
	}

	if (a.decorations && b.decorations) {
		result = compareResourceStatesDecorations(a.decorations, b.decorations);
	} else if (a.decorations) {
		return 1;
	} else if (b.decorations) {
		return -1;
	}

	return result;
111 112
}

113
export class ExtHostSCMInputBox implements vscode.SourceControlInputBox {
114 115 116 117 118 119 120 121

	private _value: string = '';

	get value(): string {
		return this._value;
	}

	set value(value: string) {
J
Joao Moreno 已提交
122
		this._proxy.$setInputBoxValue(this._sourceControlHandle, value);
123 124 125 126 127 128 129 130 131
		this.updateValue(value);
	}

	private _onDidChange = new Emitter<string>();

	get onDidChange(): Event<string> {
		return this._onDidChange.event;
	}

132 133 134 135 136 137 138 139 140 141 142
	private _placeholder: string = '';

	get placeholder(): string {
		return this._placeholder;
	}

	set placeholder(placeholder: string) {
		this._proxy.$setInputBoxPlaceholder(this._sourceControlHandle, placeholder);
		this._placeholder = placeholder;
	}

J
Joao Moreno 已提交
143
	private _lineWarningLength: number | undefined;
144

J
Joao Moreno 已提交
145 146
	get lineWarningLength(): number | undefined {
		return this._lineWarningLength;
147 148
	}

J
Joao Moreno 已提交
149 150 151
	set lineWarningLength(lineWarningLength: number) {
		this._proxy.$setLineWarningLength(this._sourceControlHandle, lineWarningLength);
		this._lineWarningLength = lineWarningLength;
152 153
	}

J
Joao Moreno 已提交
154
	constructor(private _proxy: MainThreadSCMShape, private _sourceControlHandle: number) {
155 156 157 158 159 160 161 162 163 164 165 166 167
		// noop
	}

	$onInputBoxValueChange(value: string): void {
		this.updateValue(value);
	}

	private updateValue(value: string): void {
		this._value = value;
		this._onDidChange.fire(value);
	}
}

J
Joao Moreno 已提交
168
class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceGroup {
J
Joao Moreno 已提交
169

J
Joao Moreno 已提交
170
	private static _handlePool: number = 0;
171
	private _resourceHandlePool: number = 0;
J
Joao Moreno 已提交
172
	private _resourceStates: vscode.SourceControlResourceState[] = [];
J
Joao 已提交
173

J
Joao Moreno 已提交
174
	private _resourceStatesMap: Map<ResourceStateHandle, vscode.SourceControlResourceState> = new Map<ResourceStateHandle, vscode.SourceControlResourceState>();
175
	private _resourceStatesCommandsMap: Map<ResourceStateHandle, vscode.Command> = new Map<ResourceStateHandle, vscode.Command>();
J
Joao Moreno 已提交
176

J
Joao 已提交
177 178 179 180
	private _onDidUpdateResourceStates = new Emitter<void>();
	readonly onDidUpdateResourceStates = this._onDidUpdateResourceStates.event;
	private _onDidDispose = new Emitter<void>();
	readonly onDidDispose = this._onDidDispose.event;
J
Joao Moreno 已提交
181

182
	private _handlesSnapshot: number[] = [];
183
	private _resourceSnapshot: vscode.SourceControlResourceState[] = [];
184

J
Joao 已提交
185
	get id(): string { return this._id; }
J
Joao Moreno 已提交
186

J
Joao 已提交
187
	get label(): string { return this._label; }
188 189
	set label(label: string) {
		this._label = label;
J
Joao 已提交
190
		this._proxy.$updateGroupLabel(this._sourceControlHandle, this.handle, label);
191 192
	}

J
Joao Moreno 已提交
193
	private _hideWhenEmpty: boolean | undefined = undefined;
J
Joao 已提交
194
	get hideWhenEmpty(): boolean | undefined { return this._hideWhenEmpty; }
J
Joao Moreno 已提交
195 196
	set hideWhenEmpty(hideWhenEmpty: boolean | undefined) {
		this._hideWhenEmpty = hideWhenEmpty;
J
Joao 已提交
197
		this._proxy.$updateGroup(this._sourceControlHandle, this.handle, { hideWhenEmpty });
J
Joao Moreno 已提交
198 199
	}

J
Joao 已提交
200
	get resourceStates(): vscode.SourceControlResourceState[] { return [...this._resourceStates]; }
J
Joao Moreno 已提交
201
	set resourceStates(resources: vscode.SourceControlResourceState[]) {
J
Joao Moreno 已提交
202
		this._resourceStates = [...resources];
J
Joao 已提交
203 204
		this._onDidUpdateResourceStates.fire();
	}
J
Joao Moreno 已提交
205

J
Joao 已提交
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
	readonly handle = ExtHostSourceControlResourceGroup._handlePool++;
	private _disposables: IDisposable[] = [];

	constructor(
		private _proxy: MainThreadSCMShape,
		private _commands: ExtHostCommands,
		private _sourceControlHandle: number,
		private _id: string,
		private _label: string,
	) {
		this._proxy.$registerGroup(_sourceControlHandle, this.handle, _id, _label);
	}

	getResourceState(handle: number): vscode.SourceControlResourceState | undefined {
		return this._resourceStatesMap.get(handle);
	}

	async $executeResourceCommand(handle: number): TPromise<void> {
		const command = this._resourceStatesCommandsMap.get(handle);

		if (!command) {
			return;
		}

N
Nick Snyder 已提交
230
		await this._commands.executeCommand(command.command, ...command.arguments);
J
Joao 已提交
231 232
	}

J
Joao 已提交
233 234
	_takeResourceStateSnapshot(): SCMRawResourceSplice[] {
		const snapshot = [...this._resourceStates].sort(compareResourceStates);
235
		const diffs = sortedDiff(this._resourceSnapshot, snapshot, compareResourceStates);
236

J
Joao Moreno 已提交
237 238
		const splices = diffs.map<ISplice<{ rawResource: SCMRawResource, handle: number }>>(diff => {
			const toInsert = diff.toInsert.map(r => {
J
Joao Moreno 已提交
239 240
				const handle = this._resourceHandlePool++;
				this._resourceStatesMap.set(handle, r);
241

J
Joao Moreno 已提交
242 243 244 245 246
				const sourceUri = r.resourceUri.toString();
				const iconPath = getIconPath(r.decorations);
				const lightIconPath = r.decorations && getIconPath(r.decorations.light) || iconPath;
				const darkIconPath = r.decorations && getIconPath(r.decorations.dark) || iconPath;
				const icons: string[] = [];
247

J
Joao Moreno 已提交
248 249 250
				if (r.command) {
					this._resourceStatesCommandsMap.set(handle, r.command);
				}
251

J
Joao Moreno 已提交
252 253 254
				if (lightIconPath || darkIconPath) {
					icons.push(lightIconPath);
				}
255

J
Joao Moreno 已提交
256 257 258
				if (darkIconPath !== lightIconPath) {
					icons.push(darkIconPath);
				}
259

J
Joao Moreno 已提交
260 261 262
				const tooltip = (r.decorations && r.decorations.tooltip) || '';
				const strikeThrough = r.decorations && !!r.decorations.strikeThrough;
				const faded = r.decorations && !!r.decorations.faded;
263

J
Joao Moreno 已提交
264 265 266
				const source = r.decorations && r.decorations.source || undefined;
				const letter = r.decorations && r.decorations.letter || undefined;
				const color = r.decorations && r.decorations.color || undefined;
267

J
Joao Moreno 已提交
268
				const rawResource = [handle, sourceUri, icons, tooltip, strikeThrough, faded, source, letter, color] as SCMRawResource;
269

J
Joao Moreno 已提交
270 271
				return { rawResource, handle };
			});
272

J
Joao Moreno 已提交
273
			return { start: diff.start, deleteCount: diff.deleteCount, toInsert };
J
Joao Moreno 已提交
274
		});
J
Joao Moreno 已提交
275

J
Joao Moreno 已提交
276
		const rawResourceSplices = splices
J
Joao Moreno 已提交
277
			.map(({ start, deleteCount, toInsert }) => [start, deleteCount, toInsert.map(i => i.rawResource)] as SCMRawResourceSplice);
J
Joao Moreno 已提交
278 279

		const reverseSplices = splices.reverse();
280

J
Joao Moreno 已提交
281 282
		for (const { start, deleteCount, toInsert } of reverseSplices) {
			const handles = toInsert.map(i => i.handle);
J
Joao Moreno 已提交
283
			const handlesToDelete = this._handlesSnapshot.splice(start, deleteCount, ...handles);
J
Joao 已提交
284

J
Joao Moreno 已提交
285 286 287 288
			for (const handle of handlesToDelete) {
				this._resourceStatesMap.delete(handle);
				this._resourceStatesCommandsMap.delete(handle);
			}
J
Joao 已提交
289 290
		}

291
		this._resourceSnapshot = snapshot;
J
Joao Moreno 已提交
292
		return rawResourceSplices;
J
Joao Moreno 已提交
293
	}
J
Joao Moreno 已提交
294

J
Joao Moreno 已提交
295
	dispose(): void {
J
Joao 已提交
296 297 298
		this._proxy.$unregisterGroup(this._sourceControlHandle, this.handle);
		this._disposables = dispose(this._disposables);
		this._onDidDispose.fire();
J
Joao Moreno 已提交
299 300
	}
}
J
Joao Moreno 已提交
301

J
Joao Moreno 已提交
302
class ExtHostSourceControl implements vscode.SourceControl {
J
Joao Moreno 已提交
303

J
Joao Moreno 已提交
304
	private static _handlePool: number = 0;
305
	private _groups: Map<GroupHandle, ExtHostSourceControlResourceGroup> = new Map<GroupHandle, ExtHostSourceControlResourceGroup>();
J
Joao Moreno 已提交
306

J
Joao Moreno 已提交
307 308 309
	get id(): string {
		return this._id;
	}
J
Joao Moreno 已提交
310

J
Joao Moreno 已提交
311 312 313
	get label(): string {
		return this._label;
	}
J
Joao Moreno 已提交
314

J
Joao Moreno 已提交
315 316 317 318
	get rootUri(): vscode.Uri | undefined {
		return this._rootUri;
	}

J
Joao Moreno 已提交
319 320 321
	private _inputBox: ExtHostSCMInputBox;
	get inputBox(): ExtHostSCMInputBox { return this._inputBox; }

J
Joao Moreno 已提交
322
	private _count: number | undefined = undefined;
J
Joao Moreno 已提交
323

J
Joao Moreno 已提交
324 325
	get count(): number | undefined {
		return this._count;
J
Joao Moreno 已提交
326 327
	}

J
Joao Moreno 已提交
328 329
	set count(count: number | undefined) {
		this._count = count;
J
Joao 已提交
330
		this._proxy.$updateSourceControl(this.handle, { count });
J
Joao Moreno 已提交
331
	}
J
Joao Moreno 已提交
332

J
Joao Moreno 已提交
333 334 335 336 337
	private _quickDiffProvider: vscode.QuickDiffProvider | undefined = undefined;

	get quickDiffProvider(): vscode.QuickDiffProvider | undefined {
		return this._quickDiffProvider;
	}
J
Joao Moreno 已提交
338

J
Joao Moreno 已提交
339 340
	set quickDiffProvider(quickDiffProvider: vscode.QuickDiffProvider | undefined) {
		this._quickDiffProvider = quickDiffProvider;
J
Joao 已提交
341
		this._proxy.$updateSourceControl(this.handle, { hasQuickDiffProvider: !!quickDiffProvider });
J
Joao Moreno 已提交
342
	}
J
Joao Moreno 已提交
343

344 345 346 347 348 349 350 351
	private _commitTemplate: string | undefined = undefined;

	get commitTemplate(): string | undefined {
		return this._commitTemplate;
	}

	set commitTemplate(commitTemplate: string | undefined) {
		this._commitTemplate = commitTemplate;
J
Joao 已提交
352
		this._proxy.$updateSourceControl(this.handle, { commitTemplate });
353 354 355 356 357 358 359 360 361 362 363
	}

	private _acceptInputCommand: vscode.Command | undefined = undefined;

	get acceptInputCommand(): vscode.Command | undefined {
		return this._acceptInputCommand;
	}

	set acceptInputCommand(acceptInputCommand: vscode.Command | undefined) {
		this._acceptInputCommand = acceptInputCommand;

364
		const internal = this._commands.converter.toInternal(acceptInputCommand);
J
Joao 已提交
365
		this._proxy.$updateSourceControl(this.handle, { acceptInputCommand: internal });
366 367 368 369 370 371 372 373 374 375 376
	}

	private _statusBarCommands: vscode.Command[] | undefined = undefined;

	get statusBarCommands(): vscode.Command[] | undefined {
		return this._statusBarCommands;
	}

	set statusBarCommands(statusBarCommands: vscode.Command[] | undefined) {
		this._statusBarCommands = statusBarCommands;

377
		const internal = (statusBarCommands || []).map(c => this._commands.converter.toInternal(c));
J
Joao 已提交
378
		this._proxy.$updateSourceControl(this.handle, { statusBarCommands: internal });
379 380
	}

J
Joao 已提交
381
	private handle: number = ExtHostSourceControl._handlePool++;
J
Joao Moreno 已提交
382

J
Joao Moreno 已提交
383 384
	constructor(
		private _proxy: MainThreadSCMShape,
385
		private _commands: ExtHostCommands,
J
Joao Moreno 已提交
386 387
		private _id: string,
		private _label: string,
J
Joao Moreno 已提交
388
		private _rootUri?: vscode.Uri
J
Joao Moreno 已提交
389
	) {
J
Joao 已提交
390
		this._inputBox = new ExtHostSCMInputBox(this._proxy, this.handle);
J
Joao Moreno 已提交
391
		this._proxy.$registerSourceControl(this.handle, _id, _label, _rootUri && _rootUri.toString());
J
Joao Moreno 已提交
392
	}
J
Joao Moreno 已提交
393

J
Joao 已提交
394 395
	private updatedResourceGroups = new Set<ExtHostSourceControlResourceGroup>();

J
Joao Moreno 已提交
396
	createResourceGroup(id: string, label: string): ExtHostSourceControlResourceGroup {
J
Joao 已提交
397 398 399 400 401 402 403 404 405 406 407 408 409
		const group = new ExtHostSourceControlResourceGroup(this._proxy, this._commands, this.handle, id, label);

		const updateListener = group.onDidUpdateResourceStates(() => {
			this.updatedResourceGroups.add(group);
			this.eventuallyUpdateResourceStates();
		});

		once(group.onDidDispose)(() => {
			this.updatedResourceGroups.delete(group);
			updateListener.dispose();
			this._groups.delete(group.handle);
		});

410 411 412 413
		this._groups.set(group.handle, group);
		return group;
	}

J
Joao 已提交
414 415
	@debounce(100)
	eventuallyUpdateResourceStates(): void {
416
		const splices: SCMRawResourceSplices[] = [];
J
Joao 已提交
417

418
		this.updatedResourceGroups.forEach(group => {
J
Joao 已提交
419
			const snapshot = group._takeResourceStateSnapshot();
420 421 422 423 424 425 426 427 428 429 430

			if (snapshot.length === 0) {
				return;
			}

			splices.push([group.handle, snapshot]);
		});

		if (splices.length > 0) {
			this._proxy.$spliceResourceStates(this.handle, splices);
		}
J
Joao 已提交
431 432 433 434

		this.updatedResourceGroups.clear();
	}

435 436
	getResourceGroup(handle: GroupHandle): ExtHostSourceControlResourceGroup | undefined {
		return this._groups.get(handle);
J
Joao Moreno 已提交
437
	}
J
Joao Moreno 已提交
438

J
Joao Moreno 已提交
439
	dispose(): void {
J
Joao 已提交
440 441
		this._groups.forEach(group => group.dispose());
		this._proxy.$unregisterSourceControl(this.handle);
J
Joao Moreno 已提交
442 443 444 445 446 447 448 449
	}
}

export class ExtHostSCM {

	private static _handlePool: number = 0;

	private _proxy: MainThreadSCMShape;
450
	private _sourceControls: Map<ProviderHandle, ExtHostSourceControl> = new Map<ProviderHandle, ExtHostSourceControl>();
J
Joao Moreno 已提交
451
	private _sourceControlsByExtension: Map<string, ExtHostSourceControl[]> = new Map<string, ExtHostSourceControl[]>();
J
Joao Moreno 已提交
452 453 454 455 456

	private _onDidChangeActiveProvider = new Emitter<vscode.SourceControl>();
	get onDidChangeActiveProvider(): Event<vscode.SourceControl> { return this._onDidChangeActiveProvider.event; }

	constructor(
457
		mainContext: IMainContext,
J
Joao Moreno 已提交
458 459
		private _commands: ExtHostCommands,
		@ILogService private logService: ILogService
J
Joao Moreno 已提交
460
	) {
461
		this._proxy = mainContext.get(MainContext.MainThreadSCM);
462

J
Joao Moreno 已提交
463 464 465 466
		_commands.registerArgumentProcessor({
			processArgument: arg => {
				if (arg && arg.$mid === 3) {
					const sourceControl = this._sourceControls.get(arg.sourceControlHandle);
467

J
Joao Moreno 已提交
468 469 470 471
					if (!sourceControl) {
						return arg;
					}

472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
					const group = sourceControl.getResourceGroup(arg.groupHandle);

					if (!group) {
						return arg;
					}

					return group.getResourceState(arg.handle);
				} else if (arg && arg.$mid === 4) {
					const sourceControl = this._sourceControls.get(arg.sourceControlHandle);

					if (!sourceControl) {
						return arg;
					}

					return sourceControl.getResourceGroup(arg.groupHandle);
J
Joao Moreno 已提交
487 488 489 490 491 492 493 494
				} else if (arg && arg.$mid === 5) {
					const sourceControl = this._sourceControls.get(arg.handle);

					if (!sourceControl) {
						return arg;
					}

					return sourceControl;
J
Joao Moreno 已提交
495
				}
496

J
Joao Moreno 已提交
497 498 499
				return arg;
			}
		});
J
Joao Moreno 已提交
500 501
	}

J
Joao Moreno 已提交
502
	createSourceControl(extension: IExtensionDescription, id: string, label: string, rootUri: vscode.Uri | undefined): vscode.SourceControl {
J
Joao Moreno 已提交
503 504
		this.logService.trace('ExtHostSCM#createSourceControl', extension.id, id, label, rootUri);

J
Joao Moreno 已提交
505
		const handle = ExtHostSCM._handlePool++;
J
Joao Moreno 已提交
506
		const sourceControl = new ExtHostSourceControl(this._proxy, this._commands, id, label, rootUri);
J
Joao Moreno 已提交
507 508
		this._sourceControls.set(handle, sourceControl);

J
Joao Moreno 已提交
509 510 511 512
		const sourceControls = this._sourceControlsByExtension.get(extension.id) || [];
		sourceControls.push(sourceControl);
		this._sourceControlsByExtension.set(extension.id, sourceControls);

J
Joao Moreno 已提交
513
		return sourceControl;
J
Joao Moreno 已提交
514 515
	}

J
Joao Moreno 已提交
516 517
	// Deprecated
	getLastInputBox(extension: IExtensionDescription): ExtHostSCMInputBox {
J
Joao Moreno 已提交
518 519
		this.logService.trace('ExtHostSCM#getLastInputBox', extension.id);

J
Joao Moreno 已提交
520 521 522 523 524 525 526
		const sourceControls = this._sourceControlsByExtension.get(extension.id);
		const sourceControl = sourceControls && sourceControls[sourceControls.length - 1];
		const inputBox = sourceControl && sourceControl.inputBox;

		return inputBox;
	}

527
	$provideOriginalResource(sourceControlHandle: number, uri: URI): TPromise<URI> {
J
Joao Moreno 已提交
528 529
		this.logService.trace('ExtHostSCM#$provideOriginalResource', sourceControlHandle, uri);

J
Joao Moreno 已提交
530
		const sourceControl = this._sourceControls.get(sourceControlHandle);
J
Joao Moreno 已提交
531

J
Joao Moreno 已提交
532
		if (!sourceControl || !sourceControl.quickDiffProvider) {
J
Joao Moreno 已提交
533 534 535
			return TPromise.as(null);
		}

J
Joao Moreno 已提交
536 537 538 539
		return asWinJsPromise(token => {
			const result = sourceControl.quickDiffProvider.provideOriginalResource(uri, token);
			return result && URI.parse(result.toString());
		});
J
Joao Moreno 已提交
540
	}
541

J
Joao Moreno 已提交
542
	$onInputBoxValueChange(sourceControlHandle: number, value: string): TPromise<void> {
J
Joao Moreno 已提交
543 544
		this.logService.trace('ExtHostSCM#$onInputBoxValueChange', sourceControlHandle);

J
Joao Moreno 已提交
545
		const sourceControl = this._sourceControls.get(sourceControlHandle);
J
Joao Moreno 已提交
546

547
		if (!sourceControl) {
J
Joao Moreno 已提交
548 549
			return TPromise.as(null);
		}
J
Joao Moreno 已提交
550

J
Joao Moreno 已提交
551
		sourceControl.inputBox.$onInputBoxValueChange(value);
J
Joao Moreno 已提交
552 553
		return TPromise.as(null);
	}
554 555

	async $executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number): TPromise<void> {
J
Joao Moreno 已提交
556 557
		this.logService.trace('ExtHostSCM#$executeResourceCommand', sourceControlHandle, groupHandle, handle);

558 559 560 561 562 563 564 565 566 567 568 569
		const sourceControl = this._sourceControls.get(sourceControlHandle);

		if (!sourceControl) {
			return;
		}

		const group = sourceControl.getResourceGroup(groupHandle);

		if (!group) {
			return;
		}

N
Nick Snyder 已提交
570
		await group.$executeResourceCommand(handle);
571
	}
J
Joao Moreno 已提交
572
}