diff --git a/extensions/git/package.json b/extensions/git/package.json index e13864027b8..5e00d215463 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -13,7 +13,7 @@ "diffCommand", "contribEditorContentMenu", "contribEditSessions", - "canonicalUriIdentityProvider", + "canonicalUriProvider", "contribViewsWelcome", "editSessionIdentityProvider", "quickDiffProvider", diff --git a/extensions/git/src/editSessionIdentityProvider.ts b/extensions/git/src/editSessionIdentityProvider.ts index 10ebbf349e4..6a0a31774a1 100644 --- a/extensions/git/src/editSessionIdentityProvider.ts +++ b/extensions/git/src/editSessionIdentityProvider.ts @@ -35,7 +35,7 @@ export class GitEditSessionIdentityProvider implements vscode.EditSessionIdentit } const remoteUrl = repository.remotes.find((remote) => remote.name === repository.HEAD?.upstream?.remote)?.pushUrl?.replace(/^(git@[^\/:]+)(:)/i, 'ssh://$1/'); - const remote = remoteUrl ? await vscode.workspace.provideCanonicalUriIdentity(vscode.Uri.parse(remoteUrl), token) : null; + const remote = remoteUrl ? await vscode.workspace.getCanonicalUri(vscode.Uri.parse(remoteUrl), { targetScheme: 'https' }, token) : null; return JSON.stringify({ remote: remote?.toString() ?? remoteUrl, diff --git a/extensions/git/src/typings/vscode.proposed.canonicalUriIdentityProvider.d.ts b/extensions/git/src/typings/vscode.proposed.canonicalUriIdentityProvider.d.ts deleted file mode 100644 index 3a61ca15798..00000000000 --- a/extensions/git/src/typings/vscode.proposed.canonicalUriIdentityProvider.d.ts +++ /dev/null @@ -1,38 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -declare module 'vscode' { - - // https://github.com/microsoft/vscode/issues/180582 - - export namespace workspace { - /** - * - * @param scheme The URI scheme that this provider can provide canonical URI identities for. - * A canonical URI represents the conversion of a resource's alias into a source of truth URI. - * Multiple aliases may convert to the same source of truth URI. - * @param provider A provider which can convert URIs for workspace folders of scheme @param scheme to - * a canonical URI identifier which is stable across machines. - */ - export function registerCanonicalUriIdentityProvider(scheme: string, provider: CanonicalUriIdentityProvider): Disposable; - - /** - * - * @param uri The URI to provide a canonical URI identity for. - * @param token A cancellation token for the request. - */ - export function provideCanonicalUriIdentity(uri: Uri, token: CancellationToken): ProviderResult; - } - - export interface CanonicalUriIdentityProvider { - /** - * - * @param uri The URI to provide a canonical URI identity for. - * @param token A cancellation token for the request. - * @returns The canonical URI identity for the requested URI. - */ - provideCanonicalUriIdentity(uri: Uri, token: CancellationToken): ProviderResult; - } -} diff --git a/extensions/git/src/typings/vscode.proposed.canonicalUriProvider.d.ts b/extensions/git/src/typings/vscode.proposed.canonicalUriProvider.d.ts new file mode 100644 index 00000000000..84ee599797d --- /dev/null +++ b/extensions/git/src/typings/vscode.proposed.canonicalUriProvider.d.ts @@ -0,0 +1,47 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +declare module 'vscode' { + + // https://github.com/microsoft/vscode/issues/180582 + + export namespace workspace { + /** + * + * @param scheme The URI scheme that this provider can provide canonical URIs for. + * A canonical URI represents the conversion of a resource's alias into a source of truth URI. + * Multiple aliases may convert to the same source of truth URI. + * @param provider A provider which can convert URIs of scheme @param scheme to + * a canonical URI which is stable across machines. + */ + export function registerCanonicalUriProvider(scheme: string, provider: CanonicalUriProvider): Disposable; + + /** + * + * @param uri The URI to provide a canonical URI for. + * @param token A cancellation token for the request. + */ + export function getCanonicalUri(uri: Uri, options: CanonicalUriRequestOptions, token: CancellationToken): ProviderResult; + } + + export interface CanonicalUriProvider { + /** + * + * @param uri The URI to provide a canonical URI for. + * @param options Options that the provider should honor in the URI it returns. + * @param token A cancellation token for the request. + * @returns The canonical URI for the requested URI or undefined if no canonical URI can be provided. + */ + provideCanonicalUri(uri: Uri, options: CanonicalUriRequestOptions, token: CancellationToken): ProviderResult; + } + + export interface CanonicalUriRequestOptions { + /** + * + * The desired scheme of the canonical URI. + */ + targetScheme: string; + } +} diff --git a/extensions/github/package.json b/extensions/github/package.json index 3da6c53904c..305742e8c11 100644 --- a/extensions/github/package.json +++ b/extensions/github/package.json @@ -28,7 +28,7 @@ "enabledApiProposals": [ "contribShareMenu", "contribEditSessions", - "canonicalUriIdentityProvider" + "canonicalUriProvider" ], "contributes": { "commands": [ diff --git a/extensions/github/src/canonicalUriIdentityProvider.ts b/extensions/github/src/canonicalUriIdentityProvider.ts deleted file mode 100644 index 89c9585c1f6..00000000000 --- a/extensions/github/src/canonicalUriIdentityProvider.ts +++ /dev/null @@ -1,37 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { CancellationToken, CanonicalUriIdentityProvider, Disposable, Uri, workspace } from 'vscode'; - -const SUPPORTED_SCHEMES = ['ssh', 'https']; - -export class GitHubCanonicalUriIdentityProvider implements CanonicalUriIdentityProvider { - - private disposables: Disposable[] = []; - constructor() { - this.disposables.push(...SUPPORTED_SCHEMES.map((scheme) => workspace.registerCanonicalUriIdentityProvider(scheme, this))); - } - - dispose() { this.disposables.forEach((disposable) => disposable.dispose()); } - - async provideCanonicalUriIdentity(uri: Uri, _token: CancellationToken): Promise { - switch (uri.scheme) { - case 'ssh': - // if this is a git@github.com URI, return the HTTPS equivalent - if (uri.authority === 'git@github.com') { - const [owner, repo] = (uri.path.endsWith('.git') ? uri.path.slice(0, -4) : uri.path).split('/').filter((segment) => segment.length > 0); - return Uri.parse(`https://github.com/${owner}/${repo}`); - } - break; - case 'https': - if (uri.authority === 'github.com') { - return uri; - } - break; - } - - return undefined; - } -} diff --git a/extensions/github/src/canonicalUriProvider.ts b/extensions/github/src/canonicalUriProvider.ts new file mode 100644 index 00000000000..09f5e243bc1 --- /dev/null +++ b/extensions/github/src/canonicalUriProvider.ts @@ -0,0 +1,49 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { CancellationToken, CanonicalUriProvider, CanonicalUriRequestOptions, Disposable, ProviderResult, Uri, workspace } from 'vscode'; +import { API } from './typings/git'; + +const SUPPORTED_SCHEMES = ['ssh', 'https', 'file']; + +export class GitHubCanonicalUriProvider implements CanonicalUriProvider { + + private disposables: Disposable[] = []; + constructor(private gitApi: API) { + this.disposables.push(...SUPPORTED_SCHEMES.map((scheme) => workspace.registerCanonicalUriProvider(scheme, this))); + } + + dispose() { this.disposables.forEach((disposable) => disposable.dispose()); } + + provideCanonicalUri(uri: Uri, options: CanonicalUriRequestOptions, _token: CancellationToken): ProviderResult { + if (options.targetScheme !== 'https') { + return; + } + + switch (uri.scheme) { + case 'file': { + const repository = this.gitApi.getRepository(uri); + const remote = repository?.state.remotes.find((remote) => remote.name === repository.state.HEAD?.remote)?.pushUrl?.replace(/^(git@[^\/:]+)(:)/i, 'ssh://$1/'); + if (remote) { + return toHttpsGitHubRemote(uri); + } + } + default: + return toHttpsGitHubRemote(uri); + } + } +} + +function toHttpsGitHubRemote(uri: Uri) { + if (uri.scheme === 'ssh' && uri.authority === 'git@github.com') { + // if this is a git@github.com URI, return the HTTPS equivalent + const [owner, repo] = (uri.path.endsWith('.git') ? uri.path.slice(0, -4) : uri.path).split('/').filter((segment) => segment.length > 0); + return Uri.parse(`https://github.com/${owner}/${repo}`); + } + if (uri.scheme === 'https' && uri.authority === 'github.com') { + return uri; + } + return undefined; +} diff --git a/extensions/github/src/extension.ts b/extensions/github/src/extension.ts index 26ed3bb39b7..57fdc4a938a 100644 --- a/extensions/github/src/extension.ts +++ b/extensions/github/src/extension.ts @@ -13,7 +13,7 @@ import { GithubPushErrorHandler } from './pushErrorHandler'; import { GitBaseExtension } from './typings/git-base'; import { GithubRemoteSourcePublisher } from './remoteSourcePublisher'; import { GithubBranchProtectionProviderManager } from './branchProtection'; -import { GitHubCanonicalUriIdentityProvider } from './canonicalUriIdentityProvider'; +import { GitHubCanonicalUriProvider } from './canonicalUriProvider'; export function activate(context: ExtensionContext): void { const disposables: Disposable[] = []; @@ -30,7 +30,6 @@ export function activate(context: ExtensionContext): void { disposables.push(initializeGitBaseExtension()); disposables.push(initializeGitExtension(context, logger)); - disposables.push(new GitHubCanonicalUriIdentityProvider()); } function initializeGitBaseExtension(): Disposable { @@ -95,6 +94,7 @@ function initializeGitExtension(context: ExtensionContext, logger: LogOutputChan disposables.add(new GithubBranchProtectionProviderManager(gitAPI, context.globalState, logger)); disposables.add(gitAPI.registerPushErrorHandler(new GithubPushErrorHandler())); disposables.add(gitAPI.registerRemoteSourcePublisher(new GithubRemoteSourcePublisher(gitAPI))); + disposables.add(new GitHubCanonicalUriProvider(gitAPI)); setGitHubContext(gitAPI, disposables); commands.executeCommand('setContext', 'git-base.gitEnabled', true); diff --git a/extensions/github/src/typings/vscode.proposed.canonicalUriIdentityProvider.d.ts b/extensions/github/src/typings/vscode.proposed.canonicalUriIdentityProvider.d.ts deleted file mode 100644 index 3a61ca15798..00000000000 --- a/extensions/github/src/typings/vscode.proposed.canonicalUriIdentityProvider.d.ts +++ /dev/null @@ -1,38 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -declare module 'vscode' { - - // https://github.com/microsoft/vscode/issues/180582 - - export namespace workspace { - /** - * - * @param scheme The URI scheme that this provider can provide canonical URI identities for. - * A canonical URI represents the conversion of a resource's alias into a source of truth URI. - * Multiple aliases may convert to the same source of truth URI. - * @param provider A provider which can convert URIs for workspace folders of scheme @param scheme to - * a canonical URI identifier which is stable across machines. - */ - export function registerCanonicalUriIdentityProvider(scheme: string, provider: CanonicalUriIdentityProvider): Disposable; - - /** - * - * @param uri The URI to provide a canonical URI identity for. - * @param token A cancellation token for the request. - */ - export function provideCanonicalUriIdentity(uri: Uri, token: CancellationToken): ProviderResult; - } - - export interface CanonicalUriIdentityProvider { - /** - * - * @param uri The URI to provide a canonical URI identity for. - * @param token A cancellation token for the request. - * @returns The canonical URI identity for the requested URI. - */ - provideCanonicalUriIdentity(uri: Uri, token: CancellationToken): ProviderResult; - } -} diff --git a/extensions/github/src/typings/vscode.proposed.canonicalUriProvider.d.ts b/extensions/github/src/typings/vscode.proposed.canonicalUriProvider.d.ts new file mode 100644 index 00000000000..84ee599797d --- /dev/null +++ b/extensions/github/src/typings/vscode.proposed.canonicalUriProvider.d.ts @@ -0,0 +1,47 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +declare module 'vscode' { + + // https://github.com/microsoft/vscode/issues/180582 + + export namespace workspace { + /** + * + * @param scheme The URI scheme that this provider can provide canonical URIs for. + * A canonical URI represents the conversion of a resource's alias into a source of truth URI. + * Multiple aliases may convert to the same source of truth URI. + * @param provider A provider which can convert URIs of scheme @param scheme to + * a canonical URI which is stable across machines. + */ + export function registerCanonicalUriProvider(scheme: string, provider: CanonicalUriProvider): Disposable; + + /** + * + * @param uri The URI to provide a canonical URI for. + * @param token A cancellation token for the request. + */ + export function getCanonicalUri(uri: Uri, options: CanonicalUriRequestOptions, token: CancellationToken): ProviderResult; + } + + export interface CanonicalUriProvider { + /** + * + * @param uri The URI to provide a canonical URI for. + * @param options Options that the provider should honor in the URI it returns. + * @param token A cancellation token for the request. + * @returns The canonical URI for the requested URI or undefined if no canonical URI can be provided. + */ + provideCanonicalUri(uri: Uri, options: CanonicalUriRequestOptions, token: CancellationToken): ProviderResult; + } + + export interface CanonicalUriRequestOptions { + /** + * + * The desired scheme of the canonical URI. + */ + targetScheme: string; + } +} diff --git a/src/vs/platform/workspace/common/canonicalUriIdentity.ts b/src/vs/platform/workspace/common/canonicalUri.ts similarity index 62% rename from src/vs/platform/workspace/common/canonicalUriIdentity.ts rename to src/vs/platform/workspace/common/canonicalUri.ts index aa781962a7e..11196429b0b 100644 --- a/src/vs/platform/workspace/common/canonicalUriIdentity.ts +++ b/src/vs/platform/workspace/common/canonicalUri.ts @@ -8,14 +8,14 @@ import { IDisposable } from 'vs/base/common/lifecycle'; import { URI, UriComponents } from 'vs/base/common/uri'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; -export interface ICanonicalUriIdentityProvider { +export interface ICanonicalUriProvider { readonly scheme: string; - provideCanonicalUriIdentity(uri: UriComponents, token: CancellationToken): Promise; + provideCanonicalUri(uri: UriComponents, targetScheme: string, token: CancellationToken): Promise; } -export const ICanonicalUriIdentityService = createDecorator('canonicalUriIdentityService'); +export const ICanonicalUriService = createDecorator('canonicalUriIdentityService'); -export interface ICanonicalUriIdentityService { +export interface ICanonicalUriService { readonly _serviceBrand: undefined; - registerCanonicalUriIdentityProvider(provider: ICanonicalUriIdentityProvider): IDisposable; + registerCanonicalUriProvider(provider: ICanonicalUriProvider): IDisposable; } diff --git a/src/vs/workbench/api/browser/mainThreadWorkspace.ts b/src/vs/workbench/api/browser/mainThreadWorkspace.ts index 304141dcca9..e346677647c 100644 --- a/src/vs/workbench/api/browser/mainThreadWorkspace.ts +++ b/src/vs/workbench/api/browser/mainThreadWorkspace.ts @@ -28,7 +28,7 @@ import { ExtHostContext, ExtHostWorkspaceShape, ITextSearchComplete, IWorkspaceD import { IEditSessionIdentityService } from 'vs/platform/workspace/common/editSessions'; import { EditorResourceAccessor, SaveReason, SideBySideEditor } from 'vs/workbench/common/editor'; import { coalesce, firstOrDefault } from 'vs/base/common/arrays'; -import { ICanonicalUriIdentityService } from 'vs/platform/workspace/common/canonicalUriIdentity'; +import { ICanonicalUriService } from 'vs/platform/workspace/common/canonicalUri'; @extHostNamedCustomer(MainContext.MainThreadWorkspace) export class MainThreadWorkspace implements MainThreadWorkspaceShape { @@ -43,7 +43,7 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape { @ISearchService private readonly _searchService: ISearchService, @IWorkspaceContextService private readonly _contextService: IWorkspaceContextService, @IEditSessionIdentityService private readonly _editSessionIdentityService: IEditSessionIdentityService, - @ICanonicalUriIdentityService private readonly _canonicalUriIdentityService: ICanonicalUriIdentityService, + @ICanonicalUriService private readonly _canonicalUriService: ICanonicalUriService, @IEditorService private readonly _editorService: IEditorService, @IWorkspaceEditingService private readonly _workspaceEditingService: IWorkspaceEditingService, @INotificationService private readonly _notificationService: INotificationService, @@ -273,13 +273,13 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape { } // --- canonical uri identities --- - private registeredCanonicalUriIdentityProviders = new Map(); + private registeredCanonicalUriProviders = new Map(); - $registerCanonicalUriIdentityProvider(handle: number, scheme: string) { - const disposable = this._canonicalUriIdentityService.registerCanonicalUriIdentityProvider({ + $registerCanonicalUriProvider(handle: number, scheme: string) { + const disposable = this._canonicalUriService.registerCanonicalUriProvider({ scheme: scheme, - provideCanonicalUriIdentity: async (uri: UriComponents, token: CancellationToken) => { - const result = await this._proxy.$provideCanonicalUriIdentity(uri, token); + provideCanonicalUri: async (uri: UriComponents, targetScheme: string, token: CancellationToken) => { + const result = await this._proxy.$provideCanonicalUri(uri, targetScheme, token); if (result) { return URI.revive(result); } @@ -287,13 +287,13 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape { } }); - this.registeredCanonicalUriIdentityProviders.set(handle, disposable); + this.registeredCanonicalUriProviders.set(handle, disposable); this._toDispose.add(disposable); } - $unregisterCanonicalUriIdentityProvider(handle: number) { - const disposable = this.registeredCanonicalUriIdentityProviders.get(handle); + $unregisterCanonicalUriProvider(handle: number) { + const disposable = this.registeredCanonicalUriProviders.get(handle); disposable?.dispose(); - this.registeredCanonicalUriIdentityProviders.delete(handle); + this.registeredCanonicalUriProviders.delete(handle); } } diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 416c940fa7d..26b89254bc6 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -1097,13 +1097,13 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I checkProposedApiEnabled(extension, 'editSessionIdentityProvider'); return extHostWorkspace.getOnWillCreateEditSessionIdentityEvent(extension)(listener, thisArgs, disposables); }, - registerCanonicalUriIdentityProvider: (scheme: string, provider: vscode.CanonicalUriIdentityProvider) => { - checkProposedApiEnabled(extension, 'canonicalUriIdentityProvider'); - return extHostWorkspace.registerCanonicalUriIdentityProvider(scheme, provider); + registerCanonicalUriProvider: (scheme: string, provider: vscode.CanonicalUriProvider) => { + checkProposedApiEnabled(extension, 'canonicalUriProvider'); + return extHostWorkspace.registerCanonicalUriProvider(scheme, provider); }, - provideCanonicalUriIdentity: (uri: vscode.Uri, token: vscode.CancellationToken) => { - checkProposedApiEnabled(extension, 'canonicalUriIdentityProvider'); - return extHostWorkspace.provideCanonicalUriIdentity(uri, token); + getCanonicalUri: (uri: vscode.Uri, options: vscode.CanonicalUriRequestOptions, token: vscode.CancellationToken) => { + checkProposedApiEnabled(extension, 'canonicalUriProvider'); + return extHostWorkspace.provideCanonicalUri(uri, options, token); } }; diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index de05bdd41d0..28c3398e82b 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1203,8 +1203,8 @@ export interface MainThreadWorkspaceShape extends IDisposable { $requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise; $registerEditSessionIdentityProvider(handle: number, scheme: string): void; $unregisterEditSessionIdentityProvider(handle: number): void; - $registerCanonicalUriIdentityProvider(handle: number, scheme: string): void; - $unregisterCanonicalUriIdentityProvider(handle: number): void; + $registerCanonicalUriProvider(handle: number, scheme: string): void; + $unregisterCanonicalUriProvider(handle: number): void; } export interface IFileChangeDto { @@ -1551,7 +1551,7 @@ export interface ExtHostWorkspaceShape { $getEditSessionIdentifier(folder: UriComponents, token: CancellationToken): Promise; $provideEditSessionIdentityMatch(folder: UriComponents, identity1: string, identity2: string, token: CancellationToken): Promise; $onWillCreateEditSessionIdentity(folder: UriComponents, token: CancellationToken, timeout: number): Promise; - $provideCanonicalUriIdentity(uri: UriComponents, token: CancellationToken): Promise; + $provideCanonicalUri(uri: UriComponents, targetScheme: string, token: CancellationToken): Promise; } export interface ExtHostFileSystemInfoShape { diff --git a/src/vs/workbench/api/common/extHostWorkspace.ts b/src/vs/workbench/api/common/extHostWorkspace.ts index 08271f0670d..c4f627da3c9 100644 --- a/src/vs/workbench/api/common/extHostWorkspace.ts +++ b/src/vs/workbench/api/common/extHostWorkspace.ts @@ -699,32 +699,32 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac // --- canonical uri identity --- - private readonly _canonicalUriIdentityProviders = new Map(); + private readonly _canonicalUriProviders = new Map(); // called by ext host - registerCanonicalUriIdentityProvider(scheme: string, provider: vscode.CanonicalUriIdentityProvider) { - if (this._canonicalUriIdentityProviders.has(scheme)) { + registerCanonicalUriProvider(scheme: string, provider: vscode.CanonicalUriProvider) { + if (this._canonicalUriProviders.has(scheme)) { throw new Error(`A provider has already been registered for scheme ${scheme}`); } - this._canonicalUriIdentityProviders.set(scheme, provider); + this._canonicalUriProviders.set(scheme, provider); const outgoingScheme = this._uriTransformerService.transformOutgoingScheme(scheme); const handle = this._providerHandlePool++; - this._proxy.$registerCanonicalUriIdentityProvider(handle, outgoingScheme); + this._proxy.$registerCanonicalUriProvider(handle, outgoingScheme); return toDisposable(() => { - this._canonicalUriIdentityProviders.delete(scheme); - this._proxy.$unregisterCanonicalUriIdentityProvider(handle); + this._canonicalUriProviders.delete(scheme); + this._proxy.$unregisterCanonicalUriProvider(handle); }); } - async provideCanonicalUriIdentity(uri: URI, cancellationToken: CancellationToken): Promise { - const provider = this._canonicalUriIdentityProviders.get(uri.scheme); + async provideCanonicalUri(uri: URI, options: vscode.CanonicalUriRequestOptions, cancellationToken: CancellationToken): Promise { + const provider = this._canonicalUriProviders.get(uri.scheme); if (!provider) { return undefined; } - const result = await provider.provideCanonicalUriIdentity?.(URI.revive(uri), cancellationToken); + const result = await provider.provideCanonicalUri?.(URI.revive(uri), options, cancellationToken); if (!result) { return undefined; } @@ -733,8 +733,8 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac } // called by main thread - async $provideCanonicalUriIdentity(uri: UriComponents, cancellationToken: CancellationToken): Promise { - return this.provideCanonicalUriIdentity(URI.revive(uri), cancellationToken); + async $provideCanonicalUri(uri: UriComponents, targetScheme: string, cancellationToken: CancellationToken): Promise { + return this.provideCanonicalUri(URI.revive(uri), { targetScheme }, cancellationToken); } } diff --git a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts index c18e798edf8..e9e9c53bd31 100644 --- a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts +++ b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts @@ -8,7 +8,7 @@ export const allApiProposals = Object.freeze({ authGetSessions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.authGetSessions.d.ts', authSession: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.authSession.d.ts', - canonicalUriIdentityProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.canonicalUriIdentityProvider.d.ts', + canonicalUriProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.canonicalUriProvider.d.ts', codiconDecoration: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.codiconDecoration.d.ts', commentsDraftState: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.commentsDraftState.d.ts', contribCommentEditorActionsMenu: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribCommentEditorActionsMenu.d.ts', diff --git a/src/vs/workbench/services/workspaces/common/canonicalUriIdentityService.ts b/src/vs/workbench/services/workspaces/common/canonicalUriService.ts similarity index 57% rename from src/vs/workbench/services/workspaces/common/canonicalUriIdentityService.ts rename to src/vs/workbench/services/workspaces/common/canonicalUriService.ts index d5f47b09d94..bd2a007835c 100644 --- a/src/vs/workbench/services/workspaces/common/canonicalUriIdentityService.ts +++ b/src/vs/workbench/services/workspaces/common/canonicalUriService.ts @@ -7,27 +7,27 @@ import { CancellationToken } from 'vs/base/common/cancellation'; import { IDisposable } from 'vs/base/common/lifecycle'; import { URI } from 'vs/base/common/uri'; import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions'; -import { ICanonicalUriIdentityService, ICanonicalUriIdentityProvider } from 'vs/platform/workspace/common/canonicalUriIdentity'; +import { ICanonicalUriService, ICanonicalUriProvider } from 'vs/platform/workspace/common/canonicalUri'; -export class CanonicalUriIdentityService implements ICanonicalUriIdentityService { +export class CanonicalUriService implements ICanonicalUriService { declare readonly _serviceBrand: undefined; - private readonly _providers = new Map(); + private readonly _providers = new Map(); - registerCanonicalUriIdentityProvider(provider: ICanonicalUriIdentityProvider): IDisposable { + registerCanonicalUriProvider(provider: ICanonicalUriProvider): IDisposable { this._providers.set(provider.scheme, provider); return { dispose: () => this._providers.delete(provider.scheme) }; } - async provideCanonicalUriIdentity(uri: URI, token: CancellationToken): Promise { + async provideCanonicalUri(uri: URI, targetScheme: string, token: CancellationToken): Promise { const provider = this._providers.get(uri.scheme); if (provider) { - return provider.provideCanonicalUriIdentity(uri, token); + return provider.provideCanonicalUri(uri, targetScheme, token); } return undefined; } } -registerSingleton(ICanonicalUriIdentityService, CanonicalUriIdentityService, InstantiationType.Delayed); +registerSingleton(ICanonicalUriService, CanonicalUriService, InstantiationType.Delayed); diff --git a/src/vs/workbench/workbench.common.main.ts b/src/vs/workbench/workbench.common.main.ts index 0786b7607fe..7561fbf1fb9 100644 --- a/src/vs/workbench/workbench.common.main.ts +++ b/src/vs/workbench/workbench.common.main.ts @@ -55,7 +55,7 @@ import 'vs/workbench/browser/parts/views/viewsService'; import 'vs/platform/actions/common/actions.contribution'; import 'vs/platform/undoRedo/common/undoRedoService'; import 'vs/workbench/services/workspaces/common/editSessionIdentityService'; -import 'vs/workbench/services/workspaces/common/canonicalUriIdentityService'; +import 'vs/workbench/services/workspaces/common/canonicalUriService'; import 'vs/workbench/services/extensions/browser/extensionUrlHandler'; import 'vs/workbench/services/keybinding/common/keybindingEditing'; import 'vs/workbench/services/decorations/browser/decorationsService'; diff --git a/src/vscode-dts/vscode.proposed.canonicalUriIdentityProvider.d.ts b/src/vscode-dts/vscode.proposed.canonicalUriIdentityProvider.d.ts deleted file mode 100644 index 3a61ca15798..00000000000 --- a/src/vscode-dts/vscode.proposed.canonicalUriIdentityProvider.d.ts +++ /dev/null @@ -1,38 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -declare module 'vscode' { - - // https://github.com/microsoft/vscode/issues/180582 - - export namespace workspace { - /** - * - * @param scheme The URI scheme that this provider can provide canonical URI identities for. - * A canonical URI represents the conversion of a resource's alias into a source of truth URI. - * Multiple aliases may convert to the same source of truth URI. - * @param provider A provider which can convert URIs for workspace folders of scheme @param scheme to - * a canonical URI identifier which is stable across machines. - */ - export function registerCanonicalUriIdentityProvider(scheme: string, provider: CanonicalUriIdentityProvider): Disposable; - - /** - * - * @param uri The URI to provide a canonical URI identity for. - * @param token A cancellation token for the request. - */ - export function provideCanonicalUriIdentity(uri: Uri, token: CancellationToken): ProviderResult; - } - - export interface CanonicalUriIdentityProvider { - /** - * - * @param uri The URI to provide a canonical URI identity for. - * @param token A cancellation token for the request. - * @returns The canonical URI identity for the requested URI. - */ - provideCanonicalUriIdentity(uri: Uri, token: CancellationToken): ProviderResult; - } -} diff --git a/src/vscode-dts/vscode.proposed.canonicalUriProvider.d.ts b/src/vscode-dts/vscode.proposed.canonicalUriProvider.d.ts new file mode 100644 index 00000000000..84ee599797d --- /dev/null +++ b/src/vscode-dts/vscode.proposed.canonicalUriProvider.d.ts @@ -0,0 +1,47 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +declare module 'vscode' { + + // https://github.com/microsoft/vscode/issues/180582 + + export namespace workspace { + /** + * + * @param scheme The URI scheme that this provider can provide canonical URIs for. + * A canonical URI represents the conversion of a resource's alias into a source of truth URI. + * Multiple aliases may convert to the same source of truth URI. + * @param provider A provider which can convert URIs of scheme @param scheme to + * a canonical URI which is stable across machines. + */ + export function registerCanonicalUriProvider(scheme: string, provider: CanonicalUriProvider): Disposable; + + /** + * + * @param uri The URI to provide a canonical URI for. + * @param token A cancellation token for the request. + */ + export function getCanonicalUri(uri: Uri, options: CanonicalUriRequestOptions, token: CancellationToken): ProviderResult; + } + + export interface CanonicalUriProvider { + /** + * + * @param uri The URI to provide a canonical URI for. + * @param options Options that the provider should honor in the URI it returns. + * @param token A cancellation token for the request. + * @returns The canonical URI for the requested URI or undefined if no canonical URI can be provided. + */ + provideCanonicalUri(uri: Uri, options: CanonicalUriRequestOptions, token: CancellationToken): ProviderResult; + } + + export interface CanonicalUriRequestOptions { + /** + * + * The desired scheme of the canonical URI. + */ + targetScheme: string; + } +}