Git/SCM: Use vscode.open and vscode.diff for a better editor opening experience (#110733)

* wip: try to use vscode.open and vscode.diff in git/scm

related to #110397

* 💄

* revert change to commands.converter.toInternal

* complete usage os vscode.open and vscode.diff in git extension
This commit is contained in:
João Moreno
2020-11-16 16:19:26 +01:00
committed by GitHub
parent da9a12b837
commit 62e830be77
7 changed files with 280 additions and 202 deletions

View File

@@ -865,7 +865,8 @@ export type SCMRawResource = [
string /*tooltip*/,
boolean /*strike through*/,
boolean /*faded*/,
string /*context value*/
string /*context value*/,
ICommandDto | undefined /*command*/
];
export type SCMRawResourceSplice = [

View File

@@ -90,6 +90,49 @@ function compareResourceStatesDecorations(a: vscode.SourceControlResourceDecorat
return result;
}
function compareCommands(a: vscode.Command, b: vscode.Command): number {
if (a.command !== b.command) {
return a.command < b.command ? -1 : 1;
}
if (a.title !== b.title) {
return a.title < b.title ? -1 : 1;
}
if (a.tooltip !== b.tooltip) {
if (a.tooltip !== undefined && b.tooltip !== undefined) {
return a.tooltip < b.tooltip ? -1 : 1;
} else if (a.tooltip !== undefined) {
return 1;
} else if (b.tooltip !== undefined) {
return -1;
}
}
if (a.arguments === b.arguments) {
return 0;
} else if (!a.arguments) {
return -1;
} else if (!b.arguments) {
return 1;
} else if (a.arguments.length !== b.arguments.length) {
return a.arguments.length - b.arguments.length;
}
for (let i = 0; i < a.arguments.length; i++) {
const aArg = a.arguments[i];
const bArg = b.arguments[i];
if (aArg === bArg) {
continue;
}
return aArg < bArg ? -1 : 1;
}
return 0;
}
function compareResourceStates(a: vscode.SourceControlResourceState, b: vscode.SourceControlResourceState): number {
let result = comparePaths(a.resourceUri.fsPath, b.resourceUri.fsPath, true);
@@ -97,6 +140,18 @@ function compareResourceStates(a: vscode.SourceControlResourceState, b: vscode.S
return result;
}
if (a.command && b.command) {
result = compareCommands(a.command, b.command);
} else if (a.command) {
return 1;
} else if (b.command) {
return -1;
}
if (result !== 0) {
return result;
}
if (a.decorations && b.decorations) {
result = compareResourceStatesDecorations(a.decorations, b.decorations);
} else if (a.decorations) {
@@ -223,8 +278,9 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
private _resourceHandlePool: number = 0;
private _resourceStates: vscode.SourceControlResourceState[] = [];
private _resourceStatesMap: Map<ResourceStateHandle, vscode.SourceControlResourceState> = new Map<ResourceStateHandle, vscode.SourceControlResourceState>();
private _resourceStatesCommandsMap: Map<ResourceStateHandle, vscode.Command> = new Map<ResourceStateHandle, vscode.Command>();
private _resourceStatesMap = new Map<ResourceStateHandle, vscode.SourceControlResourceState>();
private _resourceStatesCommandsMap = new Map<ResourceStateHandle, vscode.Command>();
private _resourceStatesDisposablesMap = new Map<ResourceStateHandle, IDisposable>();
private readonly _onDidUpdateResourceStates = new Emitter<void>();
readonly onDidUpdateResourceStates = this._onDidUpdateResourceStates.event;
@@ -302,9 +358,16 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
const lightIconUri = r.decorations && getIconResource(r.decorations.light) || iconUri;
const darkIconUri = r.decorations && getIconResource(r.decorations.dark) || iconUri;
const icons: UriComponents[] = [];
let command: ICommandDto | undefined;
if (r.command) {
this._resourceStatesCommandsMap.set(handle, r.command);
if (r.command.command === 'vscode.open' || r.command.command === 'vscode.diff') {
const disposables = new DisposableStore();
command = this._commands.converter.toInternal(r.command, disposables);
this._resourceStatesDisposablesMap.set(handle, disposables);
} else {
this._resourceStatesCommandsMap.set(handle, r.command);
}
}
if (lightIconUri) {
@@ -320,7 +383,7 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
const faded = r.decorations && !!r.decorations.faded;
const contextValue = r.contextValue || '';
const rawResource = [handle, sourceUri, icons, tooltip, strikeThrough, faded, contextValue] as SCMRawResource;
const rawResource = [handle, sourceUri, icons, tooltip, strikeThrough, faded, contextValue, command] as SCMRawResource;
return { rawResource, handle };
});
@@ -340,6 +403,8 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
for (const handle of handlesToDelete) {
this._resourceStatesMap.delete(handle);
this._resourceStatesCommandsMap.delete(handle);
this._resourceStatesDisposablesMap.get(handle)?.dispose();
this._resourceStatesDisposablesMap.delete(handle);
}
}