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 23dcde5c1b69e..511a9b652fe21 100644 --- a/packages/plugin-ext/src/plugin/plugin-context.ts +++ b/packages/plugin-ext/src/plugin/plugin-context.ts @@ -195,7 +195,8 @@ import { TextMergeTabInput, WebviewEditorTabInput, DocumentPasteEdit, - ExternalUriOpenerPriority + ExternalUriOpenerPriority, + EditSessionIdentityMatch } from './types-impl'; import { AuthenticationExtImpl } from './authentication-ext'; import { SymbolKind } from '../common/plugin-api-rpc-model'; @@ -735,7 +736,13 @@ export function createAPIFactory( }, registerEditSessionIdentityProvider(scheme: string, provider: theia.EditSessionIdentityProvider) { return workspaceExt.$registerEditSessionIdentityProvider(scheme, provider); - } + }, + /** + * @stubbed + * This is a stub implementation, that should minimally satisfy vscode built-in extensions + * that currently use this proposed API. + */ + onWillCreateEditSessionIdentity: () => Disposable.NULL, }; const onDidChangeLogLevel = new Emitter(); @@ -1369,7 +1376,8 @@ export function createAPIFactory( TerminalExitReason, DocumentPasteEdit, ExternalUriOpenerPriority, - TerminalQuickFixType + TerminalQuickFixType, + EditSessionIdentityMatch }; }; } diff --git a/packages/plugin-ext/src/plugin/types-impl.ts b/packages/plugin-ext/src/plugin/types-impl.ts index 723d6dfb067eb..04b38ccecfa15 100644 --- a/packages/plugin-ext/src/plugin/types-impl.ts +++ b/packages/plugin-ext/src/plugin/types-impl.ts @@ -3500,3 +3500,11 @@ export class DocumentPasteEdit { additionalEdit?: WorkspaceEdit; } // #endregion + +// #region DocumentPaste +export enum EditSessionIdentityMatch { + Complete = 100, + Partial = 50, + None = 0 +} +// #endregion diff --git a/packages/plugin/src/theia-proposed.d.ts b/packages/plugin/src/theia-proposed.d.ts index ba478fee5564a..85bef08d3dd7c 100644 --- a/packages/plugin/src/theia-proposed.d.ts +++ b/packages/plugin/src/theia-proposed.d.ts @@ -684,29 +684,6 @@ export module '@theia/plugin' { } // #endregion - // #region SessionIdentityProvider - export namespace workspace { - /** - * - * @param scheme The URI scheme that this provider can provide edit session identities for. - * @param provider A provider which can convert URIs for workspace folders of scheme @param scheme to - * an edit session identifier which is stable across machines. This enables edit sessions to be resolved. - */ - export function registerEditSessionIdentityProvider(scheme: string, provider: EditSessionIdentityProvider): Disposable; - } - - export interface EditSessionIdentityProvider { - /** - * - * @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. - */ - provideEditSessionIdentity(workspaceFolder: WorkspaceFolder, token: CancellationToken): ProviderResult; - } - - // #endregion - // #region ProfileContentHandler export interface ProfileContentHandler { diff --git a/packages/plugin/src/theia.d.ts b/packages/plugin/src/theia.d.ts index 6dc86338340b0..5f46a5b41ca61 100644 --- a/packages/plugin/src/theia.d.ts +++ b/packages/plugin/src/theia.d.ts @@ -23,6 +23,7 @@ import './theia-extra'; import './theia-proposed'; import './theia.proposed.externalUriOpener'; +import './vscode.proposed.editSessionIdentityProvider'; /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable max-len */ diff --git a/packages/plugin/src/vscode.proposed.editSessionIdentityProvider.d.ts b/packages/plugin/src/vscode.proposed.editSessionIdentityProvider.d.ts new file mode 100644 index 0000000000000..4ca5573c1cdba --- /dev/null +++ b/packages/plugin/src/vscode.proposed.editSessionIdentityProvider.d.ts @@ -0,0 +1,91 @@ +// ***************************************************************************** +// Copyright (C) 2023 Ericsson and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0. +// +// This Source Code may also be made available under the following Secondary +// Licenses when the conditions for such availability set forth in the Eclipse +// Public License v. 2.0 are satisfied: GNU General Public License, version 2 +// with the GNU Classpath Exception which is available at +// https://www.gnu.org/software/classpath/license.html. +// +// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +// ***************************************************************************** + +// Copied from: https://github.com/microsoft/vscode/blob/1.77.0/src/vscode-dts/vscode.proposed.editSessionIdentityProvider.d.ts +// and slightly adapted to work in Theia + +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +export module '@theia/plugin' { + + // https://github.com/microsoft/vscode/issues/157734 + + 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. + * @param provider A provider which can convert URIs for workspace folders of scheme @param scheme to + * an edit session identifier which is stable across machines. This enables edit sessions to be resolved. + */ + export function registerEditSessionIdentityProvider(scheme: string, provider: EditSessionIdentityProvider): Disposable; + } + + export interface EditSessionIdentityProvider { + /** + * + * @param workspaceFolder The workspace folder to provide an edit session identity for. + * @param token A cancellation token for the request. + * @returns A string representing the edit session identity for the requested workspace folder. + */ + 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. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + waitUntil(thenable: Thenable): void; + } +}