mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-02 14:31:31 +01:00
Make resolveExternalUri return just a plain uri instead of a disposable result
For #81131 We had trouble coming up with cases where extensions could actually reliably dispose of the resolved uri
This commit is contained in:
@@ -14,8 +14,6 @@ import { ExtHostContext, ExtHostWindowShape, IExtHostContext, IOpenUriOptions, M
|
||||
@extHostNamedCustomer(MainContext.MainThreadWindow)
|
||||
export class MainThreadWindow implements MainThreadWindowShape {
|
||||
|
||||
private handlePool = 1;
|
||||
|
||||
private readonly proxy: ExtHostWindowShape;
|
||||
private readonly disposables = new DisposableStore();
|
||||
private readonly resolved = new Map<number, IDisposable>();
|
||||
@@ -49,23 +47,9 @@ export class MainThreadWindow implements MainThreadWindowShape {
|
||||
return this.openerService.open(uri, { openExternal: true, allowTunneling: options.allowTunneling });
|
||||
}
|
||||
|
||||
async $resolveExternalUri(uriComponents: UriComponents, options: IOpenUriOptions): Promise<{ handle: number, result: UriComponents }> {
|
||||
async $resolveExternalUri(uriComponents: UriComponents, options: IOpenUriOptions): Promise<UriComponents> {
|
||||
const uri = URI.revive(uriComponents);
|
||||
const handle = ++this.handlePool;
|
||||
|
||||
const result = await this.openerService.resolveExternalUri(uri, options);
|
||||
this.resolved.set(handle, result);
|
||||
|
||||
return { handle, result: result.resolved };
|
||||
}
|
||||
|
||||
async $releaseResolvedExternalUri(handle: number): Promise<boolean> {
|
||||
const entry = this.resolved.get(handle);
|
||||
if (entry) {
|
||||
entry.dispose();
|
||||
this.resolved.delete(handle);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return result.resolved;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -744,8 +744,7 @@ export interface IOpenUriOptions {
|
||||
export interface MainThreadWindowShape extends IDisposable {
|
||||
$getWindowVisibility(): Promise<boolean>;
|
||||
$openUri(uri: UriComponents, options: IOpenUriOptions): Promise<boolean>;
|
||||
$resolveExternalUri(uri: UriComponents, options: IOpenUriOptions): Promise<{ readonly handle: number, readonly result: UriComponents }>;
|
||||
$releaseResolvedExternalUri(handle: number): Promise<boolean>;
|
||||
$resolveExternalUri(uri: UriComponents, options: IOpenUriOptions): Promise<UriComponents>;
|
||||
}
|
||||
|
||||
// -- extension host
|
||||
|
||||
@@ -9,7 +9,6 @@ import { WindowState } from 'vscode';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { isFalsyOrWhitespace } from 'vs/base/common/strings';
|
||||
import { once } from 'vs/base/common/functional';
|
||||
|
||||
export class ExtHostWindow implements ExtHostWindowShape {
|
||||
|
||||
@@ -55,19 +54,14 @@ export class ExtHostWindow implements ExtHostWindowShape {
|
||||
return this._proxy.$openUri(stringOrUri, options);
|
||||
}
|
||||
|
||||
async resolveExternalUri(uri: URI, options: IOpenUriOptions): Promise<{ resolved: URI, dispose(): void }> {
|
||||
async resolveExternalUri(uri: URI, options: IOpenUriOptions): Promise<URI> {
|
||||
if (isFalsyOrWhitespace(uri.scheme)) {
|
||||
return Promise.reject('Invalid scheme - cannot be empty');
|
||||
} else if (!new Set([Schemas.http, Schemas.https]).has(uri.scheme)) {
|
||||
return Promise.reject(`Invalid scheme '${uri.scheme}'`);
|
||||
}
|
||||
|
||||
const { result, handle } = await this._proxy.$resolveExternalUri(uri, options);
|
||||
return {
|
||||
resolved: URI.from(result),
|
||||
dispose: once(() => {
|
||||
this._proxy.$releaseResolvedExternalUri(handle);
|
||||
}),
|
||||
};
|
||||
const result = await this._proxy.$resolveExternalUri(uri, options);
|
||||
return URI.from(result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user