mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-29 13:03:42 +01:00
✨ scm: require uris on resources and groups
This commit is contained in:
@@ -456,11 +456,6 @@ export function createApiFactory(initData: IInitData, threadService: IThreadServ
|
||||
return extHostSCM.inputBox;
|
||||
}
|
||||
|
||||
@proposed(extension)
|
||||
getResourceFromURI(uri) {
|
||||
return extHostSCM.getResourceFromURI(uri);
|
||||
}
|
||||
|
||||
@proposed(extension)
|
||||
registerSCMProvider(provider) {
|
||||
return extHostSCM.registerSCMProvider(provider);
|
||||
|
||||
@@ -258,10 +258,17 @@ export interface SCMProviderFeatures {
|
||||
|
||||
export type SCMRawResource = [
|
||||
string /*uri*/,
|
||||
string /*sourceUri*/,
|
||||
string[] /*icons: light, dark*/,
|
||||
boolean /*strike through*/
|
||||
];
|
||||
export type SCMRawResourceGroup = [string /*id*/, string /*label*/, SCMRawResource[]];
|
||||
|
||||
export type SCMRawResourceGroup = [
|
||||
string /*uri*/,
|
||||
string /*id*/,
|
||||
string /*label*/,
|
||||
SCMRawResource[]
|
||||
];
|
||||
|
||||
export abstract class MainThreadSCMShape {
|
||||
$register(id: string, features: SCMProviderFeatures): void { throw ni(); }
|
||||
@@ -409,7 +416,7 @@ export abstract class ExtHostTerminalServiceShape {
|
||||
}
|
||||
|
||||
export abstract class ExtHostSCMShape {
|
||||
$open(id: string, resourceGroupId: string, uri: string): TPromise<void> { throw ni(); }
|
||||
$open(id: string, uri: string): TPromise<void> { throw ni(); }
|
||||
$acceptChanges(id: string): TPromise<void> { throw ni(); }
|
||||
$getOriginalResource(id: string, uri: URI): TPromise<URI> { throw ni(); }
|
||||
$onInputBoxValueChange(value: string): TPromise<void> { throw ni(); }
|
||||
|
||||
@@ -26,10 +26,7 @@ function getIconPath(decorations: vscode.SCMResourceThemableDecorations) {
|
||||
|
||||
export interface Cache {
|
||||
[providerId: string]: {
|
||||
[groupId: string]: {
|
||||
resourceGroup: vscode.SCMResourceGroup,
|
||||
resources: { [uri: string]: vscode.SCMResource }
|
||||
};
|
||||
[resourceUri: string]: vscode.SCMResource;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -87,60 +84,6 @@ export class ExtHostSCM {
|
||||
this._inputBox = new ExtHostSCMInputBox(this._proxy);
|
||||
}
|
||||
|
||||
getResourceFromURI(uri: vscode.Uri): vscode.SCMResource | vscode.SCMResourceGroup | undefined {
|
||||
if (uri.scheme !== 'scm') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const providerId = uri.authority;
|
||||
const providerCache = this.cache[providerId];
|
||||
|
||||
if (!providerCache) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const match = /^\/([^/]+)(\/(.*))?$/.exec(uri.path);
|
||||
|
||||
if (!match) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const resourceGroupId = match[1];
|
||||
const resourceGroupRef = providerCache[resourceGroupId];
|
||||
|
||||
if (!resourceGroupRef) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const rawResourceUri = match[3];
|
||||
|
||||
if (!rawResourceUri) {
|
||||
return resourceGroupRef.resourceGroup;
|
||||
}
|
||||
|
||||
let resourceUri: string;
|
||||
|
||||
try {
|
||||
const rawResource = JSON.parse(rawResourceUri);
|
||||
const resource = URI.from(rawResource);
|
||||
resourceUri = resource.toString();
|
||||
} catch (err) {
|
||||
resourceUri = undefined;
|
||||
}
|
||||
|
||||
if (!resourceUri) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const resource = resourceGroupRef.resources[resourceUri];
|
||||
|
||||
if (!resource) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
registerSCMProvider(provider: vscode.SCMProvider): Disposable {
|
||||
const providerId = provider.id;
|
||||
|
||||
@@ -163,10 +106,11 @@ export class ExtHostSCM {
|
||||
this.cache[providerId] = Object.create(null);
|
||||
|
||||
const rawResourceGroups = resourceGroups.map(g => {
|
||||
const resources: { [id: string]: vscode.SCMResource; } = Object.create(null);
|
||||
|
||||
const rawResources = g.resources.map(r => {
|
||||
const uri = r.uri.toString();
|
||||
this.cache[providerId][uri] = r;
|
||||
|
||||
const sourceUri = r.sourceUri.toString();
|
||||
const iconPath = getIconPath(r.decorations);
|
||||
const lightIconPath = r.decorations && getIconPath(r.decorations.light) || iconPath;
|
||||
const darkIconPath = r.decorations && getIconPath(r.decorations.dark) || iconPath;
|
||||
@@ -181,14 +125,11 @@ export class ExtHostSCM {
|
||||
}
|
||||
|
||||
const strikeThrough = r.decorations && !!r.decorations.strikeThrough;
|
||||
resources[uri] = r;
|
||||
|
||||
return [uri, icons, strikeThrough] as SCMRawResource;
|
||||
return [uri, sourceUri, icons, strikeThrough] as SCMRawResource;
|
||||
});
|
||||
|
||||
this.cache[providerId][g.id] = { resourceGroup: g, resources };
|
||||
|
||||
return [g.id, g.label, rawResources] as SCMRawResourceGroup;
|
||||
return [g.uri.toString(), g.id, g.label, rawResources] as SCMRawResourceGroup;
|
||||
});
|
||||
|
||||
this._proxy.$onChange(providerId, rawResourceGroups, provider.count, provider.state);
|
||||
@@ -201,16 +142,14 @@ export class ExtHostSCM {
|
||||
});
|
||||
}
|
||||
|
||||
$open(providerId: string, resourceGroupId: string, uri: string): TPromise<void> {
|
||||
$open(providerId: string, uri: string): TPromise<void> {
|
||||
const provider = this._providers[providerId];
|
||||
|
||||
if (!provider) {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
const providerCache = this.cache[providerId];
|
||||
const resourceGroup = providerCache[resourceGroupId];
|
||||
const resource = resourceGroup && resourceGroup.resources[uri];
|
||||
const resource = this.cache[providerId][uri];
|
||||
|
||||
if (!resource) {
|
||||
return TPromise.as(null);
|
||||
|
||||
@@ -49,7 +49,7 @@ class MainThreadSCMProvider implements ISCMProvider {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
return this.proxy.$open(this.id, resource.resourceGroupId, resource.uri.toString());
|
||||
return this.proxy.$open(this.id, resource.uri.toString());
|
||||
}
|
||||
|
||||
acceptChanges(): TPromise<void> {
|
||||
@@ -76,10 +76,10 @@ class MainThreadSCMProvider implements ISCMProvider {
|
||||
|
||||
$onChange(rawResourceGroups: SCMRawResourceGroup[], count: number | undefined, state: string | undefined): void {
|
||||
this._resources = rawResourceGroups.map(rawGroup => {
|
||||
const [id, label, rawResources] = rawGroup;
|
||||
const [uri, id, label, rawResources] = rawGroup;
|
||||
|
||||
const resources = rawResources.map(rawResource => {
|
||||
const [uri, icons, strikeThrough] = rawResource;
|
||||
const [uri, sourceUri, icons, strikeThrough] = rawResource;
|
||||
|
||||
const icon = icons[0];
|
||||
const iconDark = icons[1] || icon;
|
||||
@@ -93,11 +93,12 @@ class MainThreadSCMProvider implements ISCMProvider {
|
||||
return {
|
||||
resourceGroupId: id,
|
||||
uri: URI.parse(uri),
|
||||
sourceUri: URI.parse(sourceUri),
|
||||
decorations
|
||||
};
|
||||
});
|
||||
|
||||
return { id, label, resources };
|
||||
return { uri: URI.parse(uri), id, label, resources };
|
||||
});
|
||||
|
||||
this._count = count;
|
||||
|
||||
Reference in New Issue
Block a user