提交 51c42516 编写于 作者: J Joao

scm: don't send resource states commands back and forward

上级 41ec9836
......@@ -56,15 +56,19 @@ class MainThreadSCMResourceGroup implements ISCMResourceGroup {
class MainThreadSCMResource implements ISCMResource {
constructor(
private proxy: ExtHostSCMShape,
private sourceControlHandle: number,
private groupHandle: number,
private handle: number,
public sourceUri: URI,
public command: Command | undefined,
public resourceGroup: ISCMResourceGroup,
public decorations: ISCMResourceDecorations
) { }
open(): TPromise<void> {
return this.proxy.$executeResourceCommand(this.sourceControlHandle, this.groupHandle, this.handle);
}
toJSON(): any {
return {
$mid: 3,
......@@ -182,7 +186,7 @@ class MainThreadSCMProvider implements ISCMProvider {
for (const [start, deleteCount, rawResources] of groupSlices) {
const resources = rawResources.map(rawResource => {
const [handle, sourceUri, command, icons, tooltip, strikeThrough, faded] = rawResource;
const [handle, sourceUri, icons, tooltip, strikeThrough, faded] = rawResource;
const icon = icons[0];
const iconDark = icons[1] || icon;
const decorations = {
......@@ -194,11 +198,11 @@ class MainThreadSCMProvider implements ISCMProvider {
};
return new MainThreadSCMResource(
this.proxy,
this.handle,
groupHandle,
handle,
URI.parse(sourceUri),
command,
group,
decorations
);
......
......@@ -330,7 +330,6 @@ export interface SCMGroupFeatures {
export type SCMRawResource = [
number /*handle*/,
string /*resourceUri*/,
modes.Command /*command*/,
string[] /*icons: light, dark*/,
string /*tooltip*/,
boolean /*strike through*/,
......@@ -540,6 +539,7 @@ export interface ExtHostTerminalServiceShape {
export interface ExtHostSCMShape {
$provideOriginalResource(sourceControlHandle: number, uri: URI): TPromise<URI>;
$onInputBoxValueChange(sourceControlHandle: number, value: string): TPromise<void>;
$executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number): TPromise<void>;
}
export interface ExtHostTaskShape {
......
......@@ -11,12 +11,16 @@ import { debounce } from 'vs/base/common/decorators';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { asWinJsPromise } from 'vs/base/common/async';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { ExtHostCommands, CommandsConverter } from 'vs/workbench/api/node/extHostCommands';
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
import { MainContext, MainThreadSCMShape, SCMRawResource, SCMRawResourceSplice, SCMRawResourceSplices, IMainContext } from './extHost.protocol';
import { LcsDiff, ISequence } from 'vs/base/common/diff/diff';
import { comparePaths } from 'vs/base/common/comparers';
import * as vscode from 'vscode';
type ProviderHandle = number;
type GroupHandle = number;
type ResourceStateHandle = number;
function getIconPath(decorations: vscode.SourceControlResourceThemableDecorations) {
if (!decorations) {
return undefined;
......@@ -161,6 +165,7 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
private _resourceStatesRollingDisposables: { (): void }[] = [];
private _resourceStatesMap: Map<ResourceStateHandle, vscode.SourceControlResourceState> = new Map<ResourceStateHandle, vscode.SourceControlResourceState>();
private _resourceStatesCommandsMap: Map<ResourceStateHandle, vscode.Command> = new Map<ResourceStateHandle, vscode.Command>();
private _onDidUpdateResourceStates = new Emitter<void>();
readonly onDidUpdateResourceStates = this._onDidUpdateResourceStates.event;
......@@ -212,12 +217,15 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
handles.push(handle);
const sourceUri = r.resourceUri.toString();
const command = this._commands.toInternal(r.command);
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[] = [];
if (r.command) {
this._resourceStatesCommandsMap.set(handle, r.command);
}
if (lightIconPath || darkIconPath) {
icons.push(lightIconPath);
}
......@@ -230,7 +238,7 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
const strikeThrough = r.decorations && !!r.decorations.strikeThrough;
const faded = r.decorations && !!r.decorations.faded;
return [handle, sourceUri, command, icons, tooltip, strikeThrough, faded] as SCMRawResource;
return [handle, sourceUri, icons, tooltip, strikeThrough, faded] as SCMRawResource;
});
handlesToDelete.push(...this._handlesSnapshot.splice(start, deleteCount, ...handles));
......@@ -238,7 +246,11 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
return [start, deleteCount, rawResources] as SCMRawResourceSplice;
});
const disposable = () => handlesToDelete.forEach(handle => this._resourceStatesMap.delete(handle));
const disposable = () => handlesToDelete.forEach(handle => {
this._resourceStatesMap.delete(handle);
this._resourceStatesCommandsMap.delete(handle);
});
this._resourceStatesRollingDisposables.push(disposable);
while (this._resourceStatesRollingDisposables.length >= 10) {
......@@ -254,7 +266,7 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
constructor(
private _proxy: MainThreadSCMShape,
private _commands: CommandsConverter,
private _commands: ExtHostCommands,
private _sourceControlHandle: number,
private _id: string,
private _label: string,
......@@ -266,6 +278,16 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
return this._resourceStatesMap.get(handle);
}
async $executeResourceCommand(handle: number): TPromise<void> {
const command = this._resourceStatesCommandsMap.get(handle);
if (!command) {
return;
}
this._commands.executeCommand(command.command, ...command.arguments);
}
dispose(): void {
this._proxy.$unregisterGroup(this._sourceControlHandle, this.handle);
this._disposables = dispose(this._disposables);
......@@ -331,7 +353,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
set acceptInputCommand(acceptInputCommand: vscode.Command | undefined) {
this._acceptInputCommand = acceptInputCommand;
const internal = this._commands.toInternal(acceptInputCommand);
const internal = this._commands.converter.toInternal(acceptInputCommand);
this._proxy.$updateSourceControl(this.handle, { acceptInputCommand: internal });
}
......@@ -344,7 +366,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
set statusBarCommands(statusBarCommands: vscode.Command[] | undefined) {
this._statusBarCommands = statusBarCommands;
const internal = (statusBarCommands || []).map(c => this._commands.toInternal(c));
const internal = (statusBarCommands || []).map(c => this._commands.converter.toInternal(c));
this._proxy.$updateSourceControl(this.handle, { statusBarCommands: internal });
}
......@@ -352,7 +374,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
constructor(
private _proxy: MainThreadSCMShape,
private _commands: CommandsConverter,
private _commands: ExtHostCommands,
private _id: string,
private _label: string,
) {
......@@ -411,10 +433,6 @@ class ExtHostSourceControl implements vscode.SourceControl {
}
}
type ProviderHandle = number;
type GroupHandle = number;
type ResourceStateHandle = number;
export class ExtHostSCM {
private static _handlePool: number = 0;
......@@ -473,7 +491,7 @@ export class ExtHostSCM {
createSourceControl(extension: IExtensionDescription, id: string, label: string): vscode.SourceControl {
const handle = ExtHostSCM._handlePool++;
const sourceControl = new ExtHostSourceControl(this._proxy, this._commands.converter, id, label);
const sourceControl = new ExtHostSourceControl(this._proxy, this._commands, id, label);
this._sourceControls.set(handle, sourceControl);
const sourceControls = this._sourceControlsByExtension.get(extension.id) || [];
......@@ -508,11 +526,27 @@ export class ExtHostSCM {
$onInputBoxValueChange(sourceControlHandle: number, value: string): TPromise<void> {
const sourceControl = this._sourceControls.get(sourceControlHandle);
if (!sourceControl || !sourceControl.quickDiffProvider) {
if (!sourceControl) {
return TPromise.as(null);
}
sourceControl.inputBox.$onInputBoxValueChange(value);
return TPromise.as(null);
}
async $executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number): TPromise<void> {
const sourceControl = this._sourceControls.get(sourceControlHandle);
if (!sourceControl) {
return;
}
const group = sourceControl.getResourceGroup(groupHandle);
if (!group) {
return;
}
group.$executeResourceCommand(handle);
}
}
......@@ -418,12 +418,7 @@ class SourceControlView extends CollapsibleView {
}
private open(e: ISCMResource): void {
if (!e.command) {
return;
}
this.commandService.executeCommand(e.command.id, ...e.command.arguments)
.done(undefined, onUnexpectedError);
e.open().done(undefined, onUnexpectedError);
}
private pin(): void {
......
......@@ -40,8 +40,8 @@ export interface ISCMResourceCollection {
export interface ISCMResource {
readonly resourceGroup: ISCMResourceGroup;
readonly sourceUri: URI;
readonly command?: Command;
readonly decorations: ISCMResourceDecorations;
open(): TPromise<void>;
}
export interface ISCMResourceGroup {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册