mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-27 10:48:28 +01:00
fa4ff1519d
* Add canonical workspace identifier proposed API * Use canonical id to store and resume edit sessions * Add git extension workspace identity provider * Fix warning incorrectly showing up * Make auto resume behavior opt in * * Create a separate service * Accept WorkspaceFolder instead of URI * Return string instead of object * Make edit session restores resilient to provider registration races * Introduce an activation event * Activate contributing extension before using provider * `CanonicalWorkspaceIdentity` -> `EditSessionIdentity` * Show progress while resuming edit session * Store edit session even if extension will take care of opening target workspace * Address most of PR feedback * `IEditSessionsWorkbenchService` -> `IEditSessionsStorageService` * Unregister provider in renderer * Split out proposal into new `editSessionIdentityProvider.d.ts` * Fix bad merge * Always show progress in window * Convert URI schemes
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import * as path from 'path';
|
|
import * as vscode from 'vscode';
|
|
import { Model } from './model';
|
|
|
|
export class GitEditSessionIdentityProvider implements vscode.EditSessionIdentityProvider, vscode.Disposable {
|
|
|
|
private providerRegistration: vscode.Disposable;
|
|
|
|
constructor(private model: Model) {
|
|
this.providerRegistration = vscode.workspace.registerEditSessionIdentityProvider('file', this);
|
|
}
|
|
|
|
dispose() {
|
|
this.providerRegistration.dispose();
|
|
}
|
|
|
|
async provideEditSessionIdentity(workspaceFolder: vscode.WorkspaceFolder, _token: vscode.CancellationToken): Promise<string | undefined> {
|
|
await this.model.openRepository(path.dirname(workspaceFolder.uri.fsPath));
|
|
|
|
const repository = this.model.getRepository(workspaceFolder.uri);
|
|
await repository?.status();
|
|
|
|
if (!repository || !repository?.HEAD?.upstream) {
|
|
return undefined;
|
|
}
|
|
|
|
return JSON.stringify({
|
|
remote: repository.remotes.find((remote) => remote.name === repository.HEAD?.upstream?.remote)?.pushUrl ?? null,
|
|
ref: repository.HEAD?.name ?? null,
|
|
sha: repository.HEAD?.commit ?? null,
|
|
});
|
|
}
|
|
}
|