mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 21:39:43 +00:00
Improvements to canonical URI API (#182667)
* Improve API names * Allow requesting a specific scheme * Implement ile uri support
This commit is contained in:
parent
c2b15febd7
commit
0880f76765
|
@ -13,7 +13,7 @@
|
||||||
"diffCommand",
|
"diffCommand",
|
||||||
"contribEditorContentMenu",
|
"contribEditorContentMenu",
|
||||||
"contribEditSessions",
|
"contribEditSessions",
|
||||||
"canonicalUriIdentityProvider",
|
"canonicalUriProvider",
|
||||||
"contribViewsWelcome",
|
"contribViewsWelcome",
|
||||||
"editSessionIdentityProvider",
|
"editSessionIdentityProvider",
|
||||||
"quickDiffProvider",
|
"quickDiffProvider",
|
||||||
|
|
|
@ -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 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({
|
return JSON.stringify({
|
||||||
remote: remote?.toString() ?? remoteUrl,
|
remote: remote?.toString() ?? remoteUrl,
|
||||||
|
|
|
@ -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>;
|
|
||||||
}
|
|
||||||
}
|
|
47
extensions/git/src/typings/vscode.proposed.canonicalUriProvider.d.ts
vendored
Normal file
47
extensions/git/src/typings/vscode.proposed.canonicalUriProvider.d.ts
vendored
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,7 +28,7 @@
|
||||||
"enabledApiProposals": [
|
"enabledApiProposals": [
|
||||||
"contribShareMenu",
|
"contribShareMenu",
|
||||||
"contribEditSessions",
|
"contribEditSessions",
|
||||||
"canonicalUriIdentityProvider"
|
"canonicalUriProvider"
|
||||||
],
|
],
|
||||||
"contributes": {
|
"contributes": {
|
||||||
"commands": [
|
"commands": [
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
49
extensions/github/src/canonicalUriProvider.ts
Normal file
49
extensions/github/src/canonicalUriProvider.ts
Normal 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;
|
||||||
|
}
|
|
@ -13,7 +13,7 @@ import { GithubPushErrorHandler } from './pushErrorHandler';
|
||||||
import { GitBaseExtension } from './typings/git-base';
|
import { GitBaseExtension } from './typings/git-base';
|
||||||
import { GithubRemoteSourcePublisher } from './remoteSourcePublisher';
|
import { GithubRemoteSourcePublisher } from './remoteSourcePublisher';
|
||||||
import { GithubBranchProtectionProviderManager } from './branchProtection';
|
import { GithubBranchProtectionProviderManager } from './branchProtection';
|
||||||
import { GitHubCanonicalUriIdentityProvider } from './canonicalUriIdentityProvider';
|
import { GitHubCanonicalUriProvider } from './canonicalUriProvider';
|
||||||
|
|
||||||
export function activate(context: ExtensionContext): void {
|
export function activate(context: ExtensionContext): void {
|
||||||
const disposables: Disposable[] = [];
|
const disposables: Disposable[] = [];
|
||||||
|
@ -30,7 +30,6 @@ export function activate(context: ExtensionContext): void {
|
||||||
|
|
||||||
disposables.push(initializeGitBaseExtension());
|
disposables.push(initializeGitBaseExtension());
|
||||||
disposables.push(initializeGitExtension(context, logger));
|
disposables.push(initializeGitExtension(context, logger));
|
||||||
disposables.push(new GitHubCanonicalUriIdentityProvider());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeGitBaseExtension(): Disposable {
|
function initializeGitBaseExtension(): Disposable {
|
||||||
|
@ -95,6 +94,7 @@ function initializeGitExtension(context: ExtensionContext, logger: LogOutputChan
|
||||||
disposables.add(new GithubBranchProtectionProviderManager(gitAPI, context.globalState, logger));
|
disposables.add(new GithubBranchProtectionProviderManager(gitAPI, context.globalState, logger));
|
||||||
disposables.add(gitAPI.registerPushErrorHandler(new GithubPushErrorHandler()));
|
disposables.add(gitAPI.registerPushErrorHandler(new GithubPushErrorHandler()));
|
||||||
disposables.add(gitAPI.registerRemoteSourcePublisher(new GithubRemoteSourcePublisher(gitAPI)));
|
disposables.add(gitAPI.registerRemoteSourcePublisher(new GithubRemoteSourcePublisher(gitAPI)));
|
||||||
|
disposables.add(new GitHubCanonicalUriProvider(gitAPI));
|
||||||
setGitHubContext(gitAPI, disposables);
|
setGitHubContext(gitAPI, disposables);
|
||||||
|
|
||||||
commands.executeCommand('setContext', 'git-base.gitEnabled', true);
|
commands.executeCommand('setContext', 'git-base.gitEnabled', true);
|
||||||
|
|
|
@ -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>;
|
|
||||||
}
|
|
||||||
}
|
|
47
extensions/github/src/typings/vscode.proposed.canonicalUriProvider.d.ts
vendored
Normal file
47
extensions/github/src/typings/vscode.proposed.canonicalUriProvider.d.ts
vendored
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,14 +8,14 @@ import { IDisposable } from 'vs/base/common/lifecycle';
|
||||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||||
|
|
||||||
export interface ICanonicalUriIdentityProvider {
|
export interface ICanonicalUriProvider {
|
||||||
readonly scheme: string;
|
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;
|
readonly _serviceBrand: undefined;
|
||||||
registerCanonicalUriIdentityProvider(provider: ICanonicalUriIdentityProvider): IDisposable;
|
registerCanonicalUriProvider(provider: ICanonicalUriProvider): IDisposable;
|
||||||
}
|
}
|
|
@ -28,7 +28,7 @@ import { ExtHostContext, ExtHostWorkspaceShape, ITextSearchComplete, IWorkspaceD
|
||||||
import { IEditSessionIdentityService } from 'vs/platform/workspace/common/editSessions';
|
import { IEditSessionIdentityService } from 'vs/platform/workspace/common/editSessions';
|
||||||
import { EditorResourceAccessor, SaveReason, SideBySideEditor } from 'vs/workbench/common/editor';
|
import { EditorResourceAccessor, SaveReason, SideBySideEditor } from 'vs/workbench/common/editor';
|
||||||
import { coalesce, firstOrDefault } from 'vs/base/common/arrays';
|
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)
|
@extHostNamedCustomer(MainContext.MainThreadWorkspace)
|
||||||
export class MainThreadWorkspace implements MainThreadWorkspaceShape {
|
export class MainThreadWorkspace implements MainThreadWorkspaceShape {
|
||||||
|
@ -43,7 +43,7 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
|
||||||
@ISearchService private readonly _searchService: ISearchService,
|
@ISearchService private readonly _searchService: ISearchService,
|
||||||
@IWorkspaceContextService private readonly _contextService: IWorkspaceContextService,
|
@IWorkspaceContextService private readonly _contextService: IWorkspaceContextService,
|
||||||
@IEditSessionIdentityService private readonly _editSessionIdentityService: IEditSessionIdentityService,
|
@IEditSessionIdentityService private readonly _editSessionIdentityService: IEditSessionIdentityService,
|
||||||
@ICanonicalUriIdentityService private readonly _canonicalUriIdentityService: ICanonicalUriIdentityService,
|
@ICanonicalUriService private readonly _canonicalUriService: ICanonicalUriService,
|
||||||
@IEditorService private readonly _editorService: IEditorService,
|
@IEditorService private readonly _editorService: IEditorService,
|
||||||
@IWorkspaceEditingService private readonly _workspaceEditingService: IWorkspaceEditingService,
|
@IWorkspaceEditingService private readonly _workspaceEditingService: IWorkspaceEditingService,
|
||||||
@INotificationService private readonly _notificationService: INotificationService,
|
@INotificationService private readonly _notificationService: INotificationService,
|
||||||
|
@ -273,13 +273,13 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- canonical uri identities ---
|
// --- canonical uri identities ---
|
||||||
private registeredCanonicalUriIdentityProviders = new Map<number, IDisposable>();
|
private registeredCanonicalUriProviders = new Map<number, IDisposable>();
|
||||||
|
|
||||||
$registerCanonicalUriIdentityProvider(handle: number, scheme: string) {
|
$registerCanonicalUriProvider(handle: number, scheme: string) {
|
||||||
const disposable = this._canonicalUriIdentityService.registerCanonicalUriIdentityProvider({
|
const disposable = this._canonicalUriService.registerCanonicalUriProvider({
|
||||||
scheme: scheme,
|
scheme: scheme,
|
||||||
provideCanonicalUriIdentity: async (uri: UriComponents, token: CancellationToken) => {
|
provideCanonicalUri: async (uri: UriComponents, targetScheme: string, token: CancellationToken) => {
|
||||||
const result = await this._proxy.$provideCanonicalUriIdentity(uri, token);
|
const result = await this._proxy.$provideCanonicalUri(uri, targetScheme, token);
|
||||||
if (result) {
|
if (result) {
|
||||||
return URI.revive(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);
|
this._toDispose.add(disposable);
|
||||||
}
|
}
|
||||||
|
|
||||||
$unregisterCanonicalUriIdentityProvider(handle: number) {
|
$unregisterCanonicalUriProvider(handle: number) {
|
||||||
const disposable = this.registeredCanonicalUriIdentityProviders.get(handle);
|
const disposable = this.registeredCanonicalUriProviders.get(handle);
|
||||||
disposable?.dispose();
|
disposable?.dispose();
|
||||||
this.registeredCanonicalUriIdentityProviders.delete(handle);
|
this.registeredCanonicalUriProviders.delete(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1097,13 +1097,13 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
||||||
checkProposedApiEnabled(extension, 'editSessionIdentityProvider');
|
checkProposedApiEnabled(extension, 'editSessionIdentityProvider');
|
||||||
return extHostWorkspace.getOnWillCreateEditSessionIdentityEvent(extension)(listener, thisArgs, disposables);
|
return extHostWorkspace.getOnWillCreateEditSessionIdentityEvent(extension)(listener, thisArgs, disposables);
|
||||||
},
|
},
|
||||||
registerCanonicalUriIdentityProvider: (scheme: string, provider: vscode.CanonicalUriIdentityProvider) => {
|
registerCanonicalUriProvider: (scheme: string, provider: vscode.CanonicalUriProvider) => {
|
||||||
checkProposedApiEnabled(extension, 'canonicalUriIdentityProvider');
|
checkProposedApiEnabled(extension, 'canonicalUriProvider');
|
||||||
return extHostWorkspace.registerCanonicalUriIdentityProvider(scheme, provider);
|
return extHostWorkspace.registerCanonicalUriProvider(scheme, provider);
|
||||||
},
|
},
|
||||||
provideCanonicalUriIdentity: (uri: vscode.Uri, token: vscode.CancellationToken) => {
|
getCanonicalUri: (uri: vscode.Uri, options: vscode.CanonicalUriRequestOptions, token: vscode.CancellationToken) => {
|
||||||
checkProposedApiEnabled(extension, 'canonicalUriIdentityProvider');
|
checkProposedApiEnabled(extension, 'canonicalUriProvider');
|
||||||
return extHostWorkspace.provideCanonicalUriIdentity(uri, token);
|
return extHostWorkspace.provideCanonicalUri(uri, options, token);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1203,8 +1203,8 @@ export interface MainThreadWorkspaceShape extends IDisposable {
|
||||||
$requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise<boolean | undefined>;
|
$requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise<boolean | undefined>;
|
||||||
$registerEditSessionIdentityProvider(handle: number, scheme: string): void;
|
$registerEditSessionIdentityProvider(handle: number, scheme: string): void;
|
||||||
$unregisterEditSessionIdentityProvider(handle: number): void;
|
$unregisterEditSessionIdentityProvider(handle: number): void;
|
||||||
$registerCanonicalUriIdentityProvider(handle: number, scheme: string): void;
|
$registerCanonicalUriProvider(handle: number, scheme: string): void;
|
||||||
$unregisterCanonicalUriIdentityProvider(handle: number): void;
|
$unregisterCanonicalUriProvider(handle: number): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IFileChangeDto {
|
export interface IFileChangeDto {
|
||||||
|
@ -1551,7 +1551,7 @@ export interface ExtHostWorkspaceShape {
|
||||||
$getEditSessionIdentifier(folder: UriComponents, token: CancellationToken): Promise<string | undefined>;
|
$getEditSessionIdentifier(folder: UriComponents, token: CancellationToken): Promise<string | undefined>;
|
||||||
$provideEditSessionIdentityMatch(folder: UriComponents, identity1: string, identity2: string, token: CancellationToken): Promise<EditSessionIdentityMatch | undefined>;
|
$provideEditSessionIdentityMatch(folder: UriComponents, identity1: string, identity2: string, token: CancellationToken): Promise<EditSessionIdentityMatch | undefined>;
|
||||||
$onWillCreateEditSessionIdentity(folder: UriComponents, token: CancellationToken, timeout: number): Promise<void>;
|
$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 {
|
export interface ExtHostFileSystemInfoShape {
|
||||||
|
|
|
@ -699,32 +699,32 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
|
||||||
|
|
||||||
// --- canonical uri identity ---
|
// --- canonical uri identity ---
|
||||||
|
|
||||||
private readonly _canonicalUriIdentityProviders = new Map<string, vscode.CanonicalUriIdentityProvider>();
|
private readonly _canonicalUriProviders = new Map<string, vscode.CanonicalUriProvider>();
|
||||||
|
|
||||||
// called by ext host
|
// called by ext host
|
||||||
registerCanonicalUriIdentityProvider(scheme: string, provider: vscode.CanonicalUriIdentityProvider) {
|
registerCanonicalUriProvider(scheme: string, provider: vscode.CanonicalUriProvider) {
|
||||||
if (this._canonicalUriIdentityProviders.has(scheme)) {
|
if (this._canonicalUriProviders.has(scheme)) {
|
||||||
throw new Error(`A provider has already been registered for scheme ${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 outgoingScheme = this._uriTransformerService.transformOutgoingScheme(scheme);
|
||||||
const handle = this._providerHandlePool++;
|
const handle = this._providerHandlePool++;
|
||||||
this._proxy.$registerCanonicalUriIdentityProvider(handle, outgoingScheme);
|
this._proxy.$registerCanonicalUriProvider(handle, outgoingScheme);
|
||||||
|
|
||||||
return toDisposable(() => {
|
return toDisposable(() => {
|
||||||
this._canonicalUriIdentityProviders.delete(scheme);
|
this._canonicalUriProviders.delete(scheme);
|
||||||
this._proxy.$unregisterCanonicalUriIdentityProvider(handle);
|
this._proxy.$unregisterCanonicalUriProvider(handle);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async provideCanonicalUriIdentity(uri: URI, cancellationToken: CancellationToken): Promise<URI | undefined> {
|
async provideCanonicalUri(uri: URI, options: vscode.CanonicalUriRequestOptions, cancellationToken: CancellationToken): Promise<URI | undefined> {
|
||||||
const provider = this._canonicalUriIdentityProviders.get(uri.scheme);
|
const provider = this._canonicalUriProviders.get(uri.scheme);
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await provider.provideCanonicalUriIdentity?.(URI.revive(uri), cancellationToken);
|
const result = await provider.provideCanonicalUri?.(URI.revive(uri), options, cancellationToken);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -733,8 +733,8 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
|
||||||
}
|
}
|
||||||
|
|
||||||
// called by main thread
|
// called by main thread
|
||||||
async $provideCanonicalUriIdentity(uri: UriComponents, cancellationToken: CancellationToken): Promise<UriComponents | undefined> {
|
async $provideCanonicalUri(uri: UriComponents, targetScheme: string, cancellationToken: CancellationToken): Promise<UriComponents | undefined> {
|
||||||
return this.provideCanonicalUriIdentity(URI.revive(uri), cancellationToken);
|
return this.provideCanonicalUri(URI.revive(uri), { targetScheme }, cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
export const allApiProposals = Object.freeze({
|
export const allApiProposals = Object.freeze({
|
||||||
authGetSessions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.authGetSessions.d.ts',
|
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',
|
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',
|
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',
|
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',
|
contribCommentEditorActionsMenu: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribCommentEditorActionsMenu.d.ts',
|
||||||
|
|
|
@ -7,27 +7,27 @@ import { CancellationToken } from 'vs/base/common/cancellation';
|
||||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||||
import { URI } from 'vs/base/common/uri';
|
import { URI } from 'vs/base/common/uri';
|
||||||
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
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;
|
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);
|
this._providers.set(provider.scheme, provider);
|
||||||
return {
|
return {
|
||||||
dispose: () => this._providers.delete(provider.scheme)
|
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);
|
const provider = this._providers.get(uri.scheme);
|
||||||
if (provider) {
|
if (provider) {
|
||||||
return provider.provideCanonicalUriIdentity(uri, token);
|
return provider.provideCanonicalUri(uri, targetScheme, token);
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerSingleton(ICanonicalUriIdentityService, CanonicalUriIdentityService, InstantiationType.Delayed);
|
registerSingleton(ICanonicalUriService, CanonicalUriService, InstantiationType.Delayed);
|
|
@ -55,7 +55,7 @@ import 'vs/workbench/browser/parts/views/viewsService';
|
||||||
import 'vs/platform/actions/common/actions.contribution';
|
import 'vs/platform/actions/common/actions.contribution';
|
||||||
import 'vs/platform/undoRedo/common/undoRedoService';
|
import 'vs/platform/undoRedo/common/undoRedoService';
|
||||||
import 'vs/workbench/services/workspaces/common/editSessionIdentityService';
|
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/extensions/browser/extensionUrlHandler';
|
||||||
import 'vs/workbench/services/keybinding/common/keybindingEditing';
|
import 'vs/workbench/services/keybinding/common/keybindingEditing';
|
||||||
import 'vs/workbench/services/decorations/browser/decorationsService';
|
import 'vs/workbench/services/decorations/browser/decorationsService';
|
||||||
|
|
|
@ -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>;
|
|
||||||
}
|
|
||||||
}
|
|
47
src/vscode-dts/vscode.proposed.canonicalUriProvider.d.ts
vendored
Normal file
47
src/vscode-dts/vscode.proposed.canonicalUriProvider.d.ts
vendored
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue