diff --git a/packages/plugin-ext/src/common/plugin-api-rpc.ts b/packages/plugin-ext/src/common/plugin-api-rpc.ts index 1af94682a501f..cedcc7f047c2e 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc.ts @@ -702,7 +702,7 @@ export interface WorkspaceExt { $provideTextDocumentContent(uri: string): Promise; $onTextSearchResult(searchRequestId: number, done: boolean, result?: SearchInWorkspaceResult): void; $onWorkspaceTrustChanged(trust: boolean | undefined): void; - $registerEditSessionIdentityProvider(scheme: string, provider: theia.EditSessionIdentityProvider): theia.Disposable + $registerEditSessionIdentityProvider(scheme: string, provider: theia.EditSessionIdentityProvider): theia.Disposable; } export interface TimelineExt { diff --git a/packages/plugin-ext/src/plugin/plugin-context.ts b/packages/plugin-ext/src/plugin/plugin-context.ts index 0e7d98ddcfd22..d74040f53ebc5 100644 --- a/packages/plugin-ext/src/plugin/plugin-context.ts +++ b/packages/plugin-ext/src/plugin/plugin-context.ts @@ -193,7 +193,8 @@ import { TextDiffTabInput, TextMergeTabInput, WebviewEditorTabInput, - DocumentPasteEdit + DocumentPasteEdit, + EditSessionIdentityMatch } from './types-impl'; import { AuthenticationExtImpl } from './authentication-ext'; import { SymbolKind } from '../common/plugin-api-rpc-model'; @@ -721,6 +722,15 @@ export function createAPIFactory( }, registerEditSessionIdentityProvider(scheme: string, provider: theia.EditSessionIdentityProvider) { return workspaceExt.$registerEditSessionIdentityProvider(scheme, provider); + }, + /** + * @stubbed + * This is a stub implementation, lacking a Session Identity server/service, and so the event + * should never fire. This should minimally satisfy vscode built-in extensions that decide to + * use this proposed API. + */ + get onWillCreateEditSessionIdentity(): theia.Event { + return workspaceExt.onWillCreateEditSessionIdentityEvent; } }; @@ -1353,7 +1363,8 @@ export function createAPIFactory( TabInputTerminal: TerminalEditorTabInput, TerminalLocation, TerminalExitReason, - DocumentPasteEdit + DocumentPasteEdit, + EditSessionIdentityMatch }; }; } diff --git a/packages/plugin-ext/src/plugin/types-impl.ts b/packages/plugin-ext/src/plugin/types-impl.ts index 7fe67bfc85a84..4efb8836e1932 100644 --- a/packages/plugin-ext/src/plugin/types-impl.ts +++ b/packages/plugin-ext/src/plugin/types-impl.ts @@ -3488,3 +3488,11 @@ export class DocumentPasteEdit { additionalEdit?: WorkspaceEdit; } // #endregion + +// #region DocumentPaste +export enum EditSessionIdentityMatch { + Complete = 100, + Partial = 50, + None = 0 +} +// #endregion diff --git a/packages/plugin-ext/src/plugin/workspace.ts b/packages/plugin-ext/src/plugin/workspace.ts index a768cf4006da9..7912d3e905ce0 100644 --- a/packages/plugin-ext/src/plugin/workspace.ts +++ b/packages/plugin-ext/src/plugin/workspace.ts @@ -60,6 +60,14 @@ export class WorkspaceExtImpl implements WorkspaceExt { private didGrantWorkspaceTrustEmitter = new Emitter(); public readonly onDidGrantWorkspaceTrust: Event = this.didGrantWorkspaceTrustEmitter.event; + private willCreateEditSessionIdentityEmitter = new Emitter(); + /** + * @stubbed + * This is a stub implementation, lacking a Session Identity server/service, and so the event + * should never fire + */ + public readonly onWillCreateEditSessionIdentityEvent: Event = this.willCreateEditSessionIdentityEmitter.event; + constructor(rpc: RPCProtocol, private editorsAndDocuments: EditorsAndDocumentsExtImpl, private messageService: MessageRegistryExt) { diff --git a/packages/plugin/src/theia-proposed.d.ts b/packages/plugin/src/theia-proposed.d.ts index 9ce7b3c3db907..c9510d9563ec1 100644 --- a/packages/plugin/src/theia-proposed.d.ts +++ b/packages/plugin/src/theia-proposed.d.ts @@ -686,6 +686,10 @@ export module '@theia/plugin' { // #region SessionIdentityProvider export namespace workspace { + /** + * An event that is emitted when an edit session identity is about to be requested. + */ + export const onWillCreateEditSessionIdentity: Event; /** * * @param scheme The URI scheme that this provider can provide edit session identities for. @@ -700,9 +704,46 @@ export module '@theia/plugin' { * * @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 An {@link EditSessionIdentityMatch} representing the edit session identity match confidence for the provided identities. */ provideEditSessionIdentity(workspaceFolder: WorkspaceFolder, token: CancellationToken): ProviderResult; + + /** + * + * @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; + } + + export enum EditSessionIdentityMatch { + Complete = 100, + Partial = 50, + None = 0 + } + + export interface EditSessionIdentityWillCreateEvent { + + /** + * A cancellation token. + */ + readonly token: CancellationToken; + + /** + * The workspace folder to create an edit session identity for. + */ + readonly workspaceFolder: WorkspaceFolder; + + /** + * Allows to pause the event until the provided thenable resolves. + * + * *Note:* This function can only be called during event dispatch. + * + * @param thenable A thenable that delays saving. + */ + waitUntil(thenable: Thenable): void; } // #endregion