forked from eclipse-theia/theia
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement CanonicalUriProvider API. Fixes eclipse-theia#12735
The implementation follows the usual pattern of having a Theia service for canonicla URI's with the VS Code implementation being a special case of the Theia service contributions. The API is proposed in VS Code, but used in built-in extensions in versions >= 1.80.0 Contributed on behalf of STMicroelectronics Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>
- Loading branch information
Showing
10 changed files
with
213 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/plugin/src/theia.proposed.canonicalUriProvider.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
// code copied and modified from https://github.com/microsoft/vscode/blob/main/src/vscode-dts/vscode.proposed.canonicalUriProvider.d.ts | ||
|
||
export module '@theia/plugin' { | ||
|
||
// 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
import { CancellationToken, URI } from '@theia/core/lib/common'; | ||
import { injectable } from '@theia/core/shared/inversify'; | ||
import { Disposable } from '@theia/core/shared/vscode-languageserver-protocol'; | ||
|
||
export interface CanonicalUriProvider extends Disposable { | ||
provideCanonicalUri(uri: URI, targetScheme: string, token: CancellationToken): Promise<URI | undefined>; | ||
} | ||
|
||
@injectable() | ||
export class CanonicalUriService { | ||
private providers = new Map<string, CanonicalUriProvider>(); | ||
|
||
registerCanonicalUriProvider(scheme: string, provider: CanonicalUriProvider): Disposable { | ||
if (this.providers.has(scheme)) { | ||
throw new Error(`Canonical URI provider for scheme: '${scheme}' already exists`); | ||
} | ||
|
||
this.providers.set(scheme, provider); | ||
return Disposable.create(() => { this.removeCanonicalUriProvider(scheme); }); | ||
} | ||
|
||
private removeCanonicalUriProvider(scheme: string): void { | ||
const provider = this.providers.get(scheme); | ||
if (!provider) { | ||
throw new Error(`No Canonical URI provider for scheme: '${scheme}' exists`); | ||
} | ||
|
||
this.providers.delete(scheme); | ||
provider.dispose(); | ||
} | ||
|
||
async provideCanonicalUri(uri: URI, targetScheme: string, token: CancellationToken = CancellationToken.None): Promise<URI | undefined> { | ||
const provider = this.providers.get(uri.scheme); | ||
if (!provider) { | ||
console.warn(`No Canonical URI provider for scheme: '${uri.scheme}' exists`); | ||
return undefined; | ||
} | ||
|
||
return provider.provideCanonicalUri(uri, targetScheme, token); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters