mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 12:04:04 +01:00
Tolerate minor edit session identity differences (#163804)
Also add basic support for partial edit session identity matches
This commit is contained in:
@@ -35,4 +35,39 @@ export class GitEditSessionIdentityProvider implements vscode.EditSessionIdentit
|
||||
sha: repository.HEAD?.commit ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
provideEditSessionIdentityMatch(identity1: string, identity2: string): vscode.EditSessionIdentityMatch {
|
||||
try {
|
||||
const normalizedIdentity1 = normalizeEditSessionIdentity(identity1);
|
||||
const normalizedIdentity2 = normalizeEditSessionIdentity(identity2);
|
||||
|
||||
if (normalizedIdentity1.remote === normalizedIdentity2.remote &&
|
||||
normalizedIdentity1.ref === normalizedIdentity2.ref &&
|
||||
normalizedIdentity1.sha === normalizedIdentity2.sha) {
|
||||
// This is a perfect match
|
||||
return vscode.EditSessionIdentityMatch.Complete;
|
||||
} else if (normalizedIdentity1.sha !== normalizedIdentity2.sha) {
|
||||
// Same branch and remote but different SHA
|
||||
return vscode.EditSessionIdentityMatch.Partial;
|
||||
} else {
|
||||
return vscode.EditSessionIdentityMatch.None;
|
||||
}
|
||||
} catch (ex) {
|
||||
return vscode.EditSessionIdentityMatch.Partial;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeEditSessionIdentity(identity: string) {
|
||||
let { remote, ref, sha } = JSON.parse(identity);
|
||||
|
||||
if (typeof remote === 'string' && remote.endsWith('.git')) {
|
||||
remote = remote.slice(0, remote.length - 4);
|
||||
}
|
||||
|
||||
return {
|
||||
remote,
|
||||
ref,
|
||||
sha
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,8 +22,23 @@ declare module 'vscode' {
|
||||
*
|
||||
* @param workspaceFolder The workspace folder to provide an edit session identity for.
|
||||
* @param token A cancellation token for the request.
|
||||
* @returns An string representing the edit session identity for the requested workspace folder.
|
||||
* @returns A string representing the edit session identity for the requested workspace folder.
|
||||
*/
|
||||
provideEditSessionIdentity(workspaceFolder: WorkspaceFolder, token: CancellationToken): ProviderResult<string>;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param identity1 An edit session identity.
|
||||
* @param identity2 A second edit session identity to compare to @param identity1.
|
||||
* @param token A cancellation token for the request.
|
||||
* @returns An {@link EditSessionIdentityMatch} representing the edit session identity match confidence for the provided identities.
|
||||
*/
|
||||
provideEditSessionIdentityMatch(identity1: string, identity2: string, token: CancellationToken): ProviderResult<EditSessionIdentityMatch>;
|
||||
}
|
||||
|
||||
export enum EditSessionIdentityMatch {
|
||||
Complete = 100,
|
||||
Partial = 50,
|
||||
None = 0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user