Improvements to canonical URI API (#182667)

* Improve API names

* Allow requesting a specific scheme

* Implement ile uri support
This commit is contained in:
Joyce Er 2023-05-18 09:23:27 -07:00 committed by GitHub
parent c2b15febd7
commit 0880f76765
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 241 additions and 202 deletions

View file

@ -13,7 +13,7 @@
"diffCommand",
"contribEditorContentMenu",
"contribEditSessions",
"canonicalUriIdentityProvider",
"canonicalUriProvider",
"contribViewsWelcome",
"editSessionIdentityProvider",
"quickDiffProvider",

View file

@ -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,

View file

@ -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<Uri>;
}
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<Uri>;
}
}

View file

@ -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<Uri>;
}
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<Uri>;
}
export interface CanonicalUriRequestOptions {
/**
*
* The desired scheme of the canonical URI.
*/
targetScheme: string;
}
}

View file

@ -28,7 +28,7 @@
"enabledApiProposals": [
"contribShareMenu",
"contribEditSessions",
"canonicalUriIdentityProvider"
"canonicalUriProvider"
],
"contributes": {
"commands": [

View file

@ -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<Uri | undefined> {
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;
}
}

View file

@ -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<Uri> {
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;
}

View file

@ -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);

View file

@ -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<Uri>;
}
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<Uri>;
}
}

View file

@ -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<Uri>;
}
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<Uri>;
}
export interface CanonicalUriRequestOptions {
/**
*
* The desired scheme of the canonical URI.
*/
targetScheme: string;
}
}

View file

@ -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<URI | undefined>;
provideCanonicalUri(uri: UriComponents, targetScheme: string, token: CancellationToken): Promise<URI | undefined>;
}
export const ICanonicalUriIdentityService = createDecorator<ICanonicalUriIdentityService>('canonicalUriIdentityService');
export const ICanonicalUriService = createDecorator<ICanonicalUriService>('canonicalUriIdentityService');
export interface ICanonicalUriIdentityService {
export interface ICanonicalUriService {
readonly _serviceBrand: undefined;
registerCanonicalUriIdentityProvider(provider: ICanonicalUriIdentityProvider): IDisposable;
registerCanonicalUriProvider(provider: ICanonicalUriProvider): IDisposable;
}

View file

@ -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<number, IDisposable>();
private registeredCanonicalUriProviders = new Map<number, IDisposable>();
$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);
}
}

View file

@ -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);
}
};

View file

@ -1203,8 +1203,8 @@ export interface MainThreadWorkspaceShape extends IDisposable {
$requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise<boolean | undefined>;
$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<string | undefined>;
$provideEditSessionIdentityMatch(folder: UriComponents, identity1: string, identity2: string, token: CancellationToken): Promise<EditSessionIdentityMatch | undefined>;
$onWillCreateEditSessionIdentity(folder: UriComponents, token: CancellationToken, timeout: number): Promise<void>;
$provideCanonicalUriIdentity(uri: UriComponents, token: CancellationToken): Promise<UriComponents | undefined>;
$provideCanonicalUri(uri: UriComponents, targetScheme: string, token: CancellationToken): Promise<UriComponents | undefined>;
}
export interface ExtHostFileSystemInfoShape {

View file

@ -699,32 +699,32 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
// --- canonical uri identity ---
private readonly _canonicalUriIdentityProviders = new Map<string, vscode.CanonicalUriIdentityProvider>();
private readonly _canonicalUriProviders = new Map<string, vscode.CanonicalUriProvider>();
// 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<URI | undefined> {
const provider = this._canonicalUriIdentityProviders.get(uri.scheme);
async provideCanonicalUri(uri: URI, options: vscode.CanonicalUriRequestOptions, cancellationToken: CancellationToken): Promise<URI | undefined> {
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<UriComponents | undefined> {
return this.provideCanonicalUriIdentity(URI.revive(uri), cancellationToken);
async $provideCanonicalUri(uri: UriComponents, targetScheme: string, cancellationToken: CancellationToken): Promise<UriComponents | undefined> {
return this.provideCanonicalUri(URI.revive(uri), { targetScheme }, cancellationToken);
}
}

View file

@ -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',

View file

@ -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<string, ICanonicalUriIdentityProvider>();
private readonly _providers = new Map<string, ICanonicalUriProvider>();
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<URI | undefined> {
async provideCanonicalUri(uri: URI, targetScheme: string, token: CancellationToken): Promise<URI | undefined> {
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);

View file

@ -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';

View file

@ -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<Uri>;
}
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<Uri>;
}
}

View file

@ -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<Uri>;
}
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<Uri>;
}
export interface CanonicalUriRequestOptions {
/**
*
* The desired scheme of the canonical URI.
*/
targetScheme: string;
}
}