🐛 any resource can come in via command arguments

This commit is contained in:
Joao Moreno
2017-03-30 14:40:46 +02:00
parent d1d5b8009c
commit 8738327b29
5 changed files with 89 additions and 54 deletions

View File

@@ -198,14 +198,8 @@ class ExtHostSourceControl implements vscode.SourceControl {
return group;
}
getResourceState(groupHandle: GroupHandle, handle: number): vscode.SourceControlResourceState | undefined {
const group = this._groups.get(groupHandle);
if (!group) {
return undefined;
}
return group.getResourceState(handle);
getResourceGroup(handle: GroupHandle): ExtHostSourceControlResourceGroup | undefined {
return this._groups.get(handle);
}
dispose(): void {
@@ -249,7 +243,21 @@ export class ExtHostSCM {
return arg;
}
return sourceControl.getResourceState(arg.groupHandle, arg.handle);
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);
}
return arg;

View File

@@ -16,14 +16,25 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
import { ExtHostContext, MainThreadSCMShape, ExtHostSCMShape, SCMProviderFeatures, SCMRawResource, SCMGroupFeatures } from './extHost.protocol';
import { Command } from 'vs/editor/common/modes';
interface IMainThreadSCMResourceGroup {
handle: number;
provider: ISCMProvider;
uri: URI;
features: SCMGroupFeatures;
label: string;
contextKey?: string;
resources: ISCMResource[];
class MainThreadSCMResourceGroup implements ISCMResourceGroup {
constructor(
private sourceControlHandle: number,
private handle: number,
public provider: ISCMProvider,
public features: SCMGroupFeatures,
public label: string,
public contextKey: string,
public resources: ISCMResource[]
) { }
toJSON(): any {
return {
$mid: 4,
sourceControlHandle: this.sourceControlHandle,
groupHandle: this.handle
};
}
}
class MainThreadSCMResource implements ISCMResource {
@@ -50,8 +61,8 @@ class MainThreadSCMResource implements ISCMResource {
class MainThreadSCMProvider implements ISCMProvider {
private _groups: IMainThreadSCMResourceGroup[] = [];
private _groupsByHandle: { [handle: number]: IMainThreadSCMResourceGroup; } = Object.create(null);
private _groups: MainThreadSCMResourceGroup[] = [];
private _groupsByHandle: { [handle: number]: MainThreadSCMResourceGroup; } = Object.create(null);
get resources(): ISCMResourceGroup[] {
return this._groups
@@ -85,15 +96,15 @@ class MainThreadSCMProvider implements ISCMProvider {
}
$registerGroup(handle: number, id: string, label: string): void {
const group: IMainThreadSCMResourceGroup = {
const group = new MainThreadSCMResourceGroup(
this.handle,
handle,
provider: this,
contextKey: id,
this,
{},
label,
uri: null,
resources: [],
features: {}
};
id,
[]
);
this._groups.push(group);
this._groupsByHandle[handle] = group;
@@ -110,8 +121,8 @@ class MainThreadSCMProvider implements ISCMProvider {
this._onDidChange.fire();
}
$updateGroupResourceStates(handle: number, resources: SCMRawResource[]): void {
const group = this._groupsByHandle[handle];
$updateGroupResourceStates(groupHandle: number, resources: SCMRawResource[]): void {
const group = this._groupsByHandle[groupHandle];
if (!group) {
return;
@@ -129,7 +140,7 @@ class MainThreadSCMProvider implements ISCMProvider {
return new MainThreadSCMResource(
this.handle,
group.handle,
groupHandle,
handle,
URI.parse(sourceUri),
command,