mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 18:19:12 +01:00
Explore resolver api
This commit is contained in:
@@ -641,6 +641,9 @@ export function createApiFactory(
|
||||
registerWorkspaceCommentProvider: proposedApiFunction(extension, (provider: vscode.WorkspaceCommentProvider) => {
|
||||
return exthostCommentProviders.registerWorkspaceCommentProvider(extension.identifier, provider);
|
||||
}),
|
||||
registerRemoteAuthorityResolver: proposedApiFunction(extension, (authorityPrefix: string, resolver: vscode.RemoteAuthorityResolver) => {
|
||||
return extensionService.registerRemoteAuthorityResolver(authorityPrefix, resolver);
|
||||
}),
|
||||
onDidRenameFile: proposedApiFunction(extension, (listener, thisArg?, disposables?) => {
|
||||
return extHostFileSystemEvent.onDidRenameFile(listener, thisArg, disposables);
|
||||
}),
|
||||
@@ -793,6 +796,7 @@ export function createApiFactory(
|
||||
QuickInputButtons: extHostTypes.QuickInputButtons,
|
||||
Range: extHostTypes.Range,
|
||||
RelativePattern: extHostTypes.RelativePattern,
|
||||
ResolvedAuthority: extHostTypes.ResolvedAuthority,
|
||||
Selection: extHostTypes.Selection,
|
||||
SelectionRange: extHostTypes.SelectionRange,
|
||||
SelectionRangeKind: extHostTypes.SelectionRangeKind,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import * as nls from 'vs/nls';
|
||||
import * as path from 'vs/base/common/path';
|
||||
import { Barrier } from 'vs/base/common/async';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { TernarySearchTree } from 'vs/base/common/map';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
@@ -25,6 +25,7 @@ import { connectProxyResolver } from 'vs/workbench/services/extensions/node/prox
|
||||
import { CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import * as errors from 'vs/base/common/errors';
|
||||
import { ResolvedAuthority } from 'vs/platform/remote/common/remoteAuthorityResolver';
|
||||
import * as vscode from 'vscode';
|
||||
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
|
||||
import { IWorkspace } from 'vs/platform/workspace/common/workspace';
|
||||
|
||||
@@ -168,6 +169,8 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
|
||||
private _extensionPathIndex: Promise<TernarySearchTree<IExtensionDescription>>;
|
||||
private readonly _extensionApiFactory: IExtensionApiFactory;
|
||||
|
||||
private readonly _resolvers: { [authorityPrefix: string]: vscode.RemoteAuthorityResolver; };
|
||||
|
||||
private _started: boolean;
|
||||
|
||||
constructor(
|
||||
@@ -228,6 +231,8 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
|
||||
// initialize API first (i.e. do not release barrier until the API is initialized)
|
||||
this._extensionApiFactory = createApiFactory(this._initData, this._extHostContext, this._extHostWorkspace, this._extHostConfiguration, this, this._extHostLogService, this._storage);
|
||||
|
||||
this._resolvers = Object.create(null);
|
||||
|
||||
this._started = false;
|
||||
|
||||
this._initialize();
|
||||
@@ -661,10 +666,40 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
|
||||
});
|
||||
}
|
||||
|
||||
// -- called by extensions
|
||||
|
||||
public registerRemoteAuthorityResolver(authorityPrefix: string, resolver: vscode.RemoteAuthorityResolver): vscode.Disposable {
|
||||
this._resolvers[authorityPrefix] = resolver;
|
||||
return toDisposable(() => {
|
||||
this._resolvers[authorityPrefix] = null;
|
||||
});
|
||||
}
|
||||
|
||||
// -- called by main thread
|
||||
|
||||
public async $resolveAuthority(remoteAuthority: string): Promise<ResolvedAuthority> {
|
||||
throw new Error(`Not implemented`);
|
||||
const authorityPlusIndex = remoteAuthority.indexOf('+');
|
||||
if (authorityPlusIndex === -1) {
|
||||
throw new Error(`Not an authority that can be resolved!`);
|
||||
}
|
||||
const authorityPrefix = remoteAuthority.substr(0, authorityPlusIndex);
|
||||
|
||||
await this._barrier.wait();
|
||||
await this._activateByEvent(`onResolveRemoteAuthority:${authorityPrefix}`, false);
|
||||
|
||||
const resolver = this._resolvers[authorityPrefix];
|
||||
if (!resolver) {
|
||||
throw new Error(`No resolver available for ${authorityPrefix}`);
|
||||
}
|
||||
|
||||
const result = await resolver.resolve(remoteAuthority);
|
||||
return {
|
||||
authority: remoteAuthority,
|
||||
host: result.host,
|
||||
port: result.port,
|
||||
debugListenPort: result.debugListenPort,
|
||||
debugConnectPort: result.debugConnectPort,
|
||||
};
|
||||
}
|
||||
|
||||
public $startExtensionHost(enabledExtensionIds: ExtensionIdentifier[]): Promise<void> {
|
||||
|
||||
@@ -431,6 +431,24 @@ export class Selection extends Range {
|
||||
}
|
||||
}
|
||||
|
||||
export class ResolvedAuthority {
|
||||
readonly host: string;
|
||||
readonly port: number;
|
||||
debugListenPort?: number;
|
||||
debugConnectPort?: number;
|
||||
|
||||
constructor(host: string, port: number) {
|
||||
if (typeof host !== 'string' || host.length === 0) {
|
||||
throw illegalArgument('host');
|
||||
}
|
||||
if (typeof port !== 'number' || port === 0 || Math.round(port) !== port) {
|
||||
throw illegalArgument('port');
|
||||
}
|
||||
this.host = host;
|
||||
this.port = Math.round(port);
|
||||
}
|
||||
}
|
||||
|
||||
export enum EndOfLine {
|
||||
LF = 1,
|
||||
CRLF = 2
|
||||
|
||||
Reference in New Issue
Block a user