Skip to content

Commit

Permalink
[vscode][proposed] Stub onWillCreateEditSessionIdentity
Browse files Browse the repository at this point in the history
This event was recently added to proposed API EditSessionIdentityProvider.
For now we add a stub that will allow `[email protected]` and more recent
to activate and be successfully used in Theia applications.

Fixes #12521

Signed-off-by: Marc Dumais <[email protected]>
  • Loading branch information
marcdumais-work committed May 15, 2023
1 parent 3eb7137 commit e7b4dab
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ export interface WorkspaceExt {
$provideTextDocumentContent(uri: string): Promise<string | undefined | null>;
$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 {
Expand Down
15 changes: 13 additions & 2 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<theia.EditSessionIdentityWillCreateEvent> {
return workspaceExt.onWillCreateEditSessionIdentityEvent;
}
};

Expand Down Expand Up @@ -1353,7 +1363,8 @@ export function createAPIFactory(
TabInputTerminal: TerminalEditorTabInput,
TerminalLocation,
TerminalExitReason,
DocumentPasteEdit
DocumentPasteEdit,
EditSessionIdentityMatch
};
};
}
Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3488,3 +3488,11 @@ export class DocumentPasteEdit {
additionalEdit?: WorkspaceEdit;
}
// #endregion

// #region DocumentPaste
export enum EditSessionIdentityMatch {
Complete = 100,
Partial = 50,
None = 0
}
// #endregion
8 changes: 8 additions & 0 deletions packages/plugin-ext/src/plugin/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ export class WorkspaceExtImpl implements WorkspaceExt {
private didGrantWorkspaceTrustEmitter = new Emitter<void>();
public readonly onDidGrantWorkspaceTrust: Event<void> = this.didGrantWorkspaceTrustEmitter.event;

private willCreateEditSessionIdentityEmitter = new Emitter<theia.EditSessionIdentityWillCreateEvent>();
/**
* @stubbed
* This is a stub implementation, lacking a Session Identity server/service, and so the event
* should never fire
*/
public readonly onWillCreateEditSessionIdentityEvent: Event<theia.EditSessionIdentityWillCreateEvent> = this.willCreateEditSessionIdentityEmitter.event;

constructor(rpc: RPCProtocol,
private editorsAndDocuments: EditorsAndDocumentsExtImpl,
private messageService: MessageRegistryExt) {
Expand Down
43 changes: 42 additions & 1 deletion packages/plugin/src/theia-proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<EditSessionIdentityWillCreateEvent>;
/**
*
* @param scheme The URI scheme that this provider can provide edit session identities for.
Expand All @@ -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<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
}

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<any>): void;
}

// #endregion
Expand Down

0 comments on commit e7b4dab

Please sign in to comment.