Skip to content

Commit

Permalink
Introduce and adopt IExtHostWorkspaceProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Feb 20, 2019
1 parent 7d7e1b6 commit 3199f1f
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 188 deletions.
36 changes: 18 additions & 18 deletions src/vs/workbench/api/node/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import * as extHostTypes from 'vs/workbench/api/node/extHostTypes';
import { ExtHostUrls } from 'vs/workbench/api/node/extHostUrls';
import { ExtHostWebviews } from 'vs/workbench/api/node/extHostWebview';
import { ExtHostWindow } from 'vs/workbench/api/node/extHostWindow';
import { ExtHostWorkspace, ExtHostWorkspaceProvider } from 'vs/workbench/api/node/extHostWorkspace';
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { IExtensionDescription, throwProposedApiError, checkProposedApiEnabled, nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
import { ProxyIdentifier } from 'vs/workbench/services/extensions/node/proxyIdentifier';
import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/node/extensionDescriptionRegistry';
Expand All @@ -67,7 +67,7 @@ import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { originalFSPath } from 'vs/base/common/resources';

export interface IExtensionApiFactory {
(extension: IExtensionDescription, registry: ExtensionDescriptionRegistry, workspaceProvider: ExtHostWorkspaceProvider, configProvider: ExtHostConfigProvider): typeof vscode;
(extension: IExtensionDescription, registry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode;
}

function proposedApiFunction<T>(extension: IExtensionDescription, fn: T): T {
Expand Down Expand Up @@ -143,7 +143,7 @@ export function createApiFactory(
// Register API-ish commands
ExtHostApiCommands.register(extHostCommands);

return function (extension: IExtensionDescription, extensionRegistry: ExtensionDescriptionRegistry, workspaceProvider: ExtHostWorkspaceProvider, configProvider: ExtHostConfigProvider): typeof vscode {
return function (extension: IExtensionDescription, extensionRegistry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode {

// Check document selectors for being overly generic. Technically this isn't a problem but
// in practice many extensions say they support `fooLang` but need fs-access to do so. Those
Expand Down Expand Up @@ -516,34 +516,34 @@ export function createApiFactory(
// namespace: workspace
const workspace: typeof vscode.workspace = {
get rootPath() {
return workspaceProvider.getPath();
return extHostWorkspace.getPath();
},
set rootPath(value) {
throw errors.readonly();
},
getWorkspaceFolder(resource) {
return workspaceProvider.getWorkspaceFolder(resource);
return extHostWorkspace.getWorkspaceFolder(resource);
},
get workspaceFolders() {
return workspaceProvider.getWorkspaceFolders();
return extHostWorkspace.getWorkspaceFolders();
},
get name() {
return workspaceProvider.name;
return extHostWorkspace.name;
},
set name(value) {
throw errors.readonly();
},
updateWorkspaceFolders: (index, deleteCount, ...workspaceFoldersToAdd) => {
return workspaceProvider.updateWorkspaceFolders(extension, index, deleteCount || 0, ...workspaceFoldersToAdd);
return extHostWorkspace.updateWorkspaceFolders(extension, index, deleteCount || 0, ...workspaceFoldersToAdd);
},
onDidChangeWorkspaceFolders: function (listener, thisArgs?, disposables?) {
return workspaceProvider.onDidChangeWorkspace(listener, thisArgs, disposables);
return extHostWorkspace.onDidChangeWorkspace(listener, thisArgs, disposables);
},
asRelativePath: (pathOrUri, includeWorkspace) => {
return workspaceProvider.getRelativePath(pathOrUri, includeWorkspace);
return extHostWorkspace.getRelativePath(pathOrUri, includeWorkspace);
},
findFiles: (include, exclude, maxResults?, token?) => {
return workspaceProvider.findFiles(typeConverters.GlobPattern.from(include), typeConverters.GlobPattern.from(exclude), maxResults, extension.identifier, token);
return extHostWorkspace.findFiles(typeConverters.GlobPattern.from(include), typeConverters.GlobPattern.from(exclude), maxResults, extension.identifier, token);
},
findTextInFiles: (query: vscode.TextSearchQuery, optionsOrCallback, callbackOrToken?, token?: vscode.CancellationToken) => {
let options: vscode.FindTextInFilesOptions;
Expand All @@ -558,10 +558,10 @@ export function createApiFactory(
token = callbackOrToken;
}

return workspaceProvider.findTextInFiles(query, options || {}, callback, extension.identifier, token);
return extHostWorkspace.findTextInFiles(query, options || {}, callback, extension.identifier, token);
},
saveAll: (includeUntitled?) => {
return workspaceProvider.saveAll(includeUntitled);
return extHostWorkspace.saveAll(includeUntitled);
},
applyEdit(edit: vscode.WorkspaceEdit): Thenable<boolean> {
return extHostEditors.applyWorkspaceEdit(edit);
Expand Down Expand Up @@ -874,11 +874,11 @@ class Extension<T> implements vscode.Extension<T> {
}
}

export function initializeExtensionApi(extensionService: ExtHostExtensionService, apiFactory: IExtensionApiFactory, extensionRegistry: ExtensionDescriptionRegistry, workspaceProvider: ExtHostWorkspaceProvider, configProvider: ExtHostConfigProvider): Promise<void> {
return extensionService.getExtensionPathIndex().then(trie => defineAPI(apiFactory, trie, extensionRegistry, workspaceProvider, configProvider));
export function initializeExtensionApi(extensionService: ExtHostExtensionService, apiFactory: IExtensionApiFactory, extensionRegistry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): Promise<void> {
return extensionService.getExtensionPathIndex().then(trie => defineAPI(apiFactory, trie, extensionRegistry, configProvider));
}

function defineAPI(factory: IExtensionApiFactory, extensionPaths: TernarySearchTree<IExtensionDescription>, extensionRegistry: ExtensionDescriptionRegistry, workspaceProvider: ExtHostWorkspaceProvider, configProvider: ExtHostConfigProvider): void {
function defineAPI(factory: IExtensionApiFactory, extensionPaths: TernarySearchTree<IExtensionDescription>, extensionRegistry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): void {

// each extension is meant to get its own api implementation
const extApiImpl = new Map<string, typeof vscode>();
Expand All @@ -896,7 +896,7 @@ function defineAPI(factory: IExtensionApiFactory, extensionPaths: TernarySearchT
if (ext) {
let apiImpl = extApiImpl.get(ExtensionIdentifier.toKey(ext.identifier));
if (!apiImpl) {
apiImpl = factory(ext, extensionRegistry, workspaceProvider, configProvider);
apiImpl = factory(ext, extensionRegistry, configProvider);
extApiImpl.set(ExtensionIdentifier.toKey(ext.identifier), apiImpl);
}
return apiImpl;
Expand All @@ -907,7 +907,7 @@ function defineAPI(factory: IExtensionApiFactory, extensionPaths: TernarySearchT
let extensionPathsPretty = '';
extensionPaths.forEach((value, index) => extensionPathsPretty += `\t${index} -> ${value.identifier.value}\n`);
console.warn(`Could not identify extension for 'vscode' require call from ${parent.filename}. These are the extension path mappings: \n${extensionPathsPretty}`);
defaultApiImpl = factory(nullExtensionDescription, extensionRegistry, workspaceProvider, configProvider);
defaultApiImpl = factory(nullExtensionDescription, extensionRegistry, configProvider);
}
return defaultApiImpl;
};
Expand Down
12 changes: 5 additions & 7 deletions src/vs/workbench/api/node/extHostConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { mixin, deepClone } from 'vs/base/common/objects';
import { URI } from 'vs/base/common/uri';
import { Event, Emitter } from 'vs/base/common/event';
import * as vscode from 'vscode';
import { ExtHostWorkspace, ExtHostWorkspaceProvider } from 'vs/workbench/api/node/extHostWorkspace';
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { ExtHostConfigurationShape, MainThreadConfigurationShape, IWorkspaceConfigurationChangeEventData, IConfigurationInitData } from './extHost.protocol';
import { ConfigurationTarget as ExtHostConfigurationTarget } from './extHostTypes';
import { IConfigurationData, ConfigurationTarget, IConfigurationModel } from 'vs/platform/configuration/common/configuration';
Expand Down Expand Up @@ -57,10 +57,8 @@ export class ExtHostConfiguration implements ExtHostConfigurationShape {
}

$initializeConfiguration(data: IConfigurationInitData): void {
this._extHostWorkspace.getWorkspaceProvider().then(workspaceProvider => {
this._actual = new ExtHostConfigProvider(this._proxy, workspaceProvider, data);
this._barrier.open();
});
this._actual = new ExtHostConfigProvider(this._proxy, this._extHostWorkspace, data);
this._barrier.open();
}

$acceptConfigurationChanged(data: IConfigurationInitData, eventData: IWorkspaceConfigurationChangeEventData): void {
Expand All @@ -72,11 +70,11 @@ export class ExtHostConfigProvider {

private readonly _onDidChangeConfiguration = new Emitter<vscode.ConfigurationChangeEvent>();
private readonly _proxy: MainThreadConfigurationShape;
private readonly _extHostWorkspace: ExtHostWorkspaceProvider;
private readonly _extHostWorkspace: ExtHostWorkspace;
private _configurationScopes: { [key: string]: ConfigurationScope };
private _configuration: Configuration;

constructor(proxy: MainThreadConfigurationShape, extHostWorkspace: ExtHostWorkspaceProvider, data: IConfigurationInitData) {
constructor(proxy: MainThreadConfigurationShape, extHostWorkspace: ExtHostWorkspace, data: IConfigurationInitData) {
this._proxy = proxy;
this._extHostWorkspace = extHostWorkspace;
this._configuration = ExtHostConfigProvider.parse(data);
Expand Down
57 changes: 27 additions & 30 deletions src/vs/workbench/api/node/extHostDebugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import * as vscode from 'vscode';
import { Disposable, Position, Location, SourceBreakpoint, FunctionBreakpoint, DebugAdapterServer, DebugAdapterExecutable } from 'vs/workbench/api/node/extHostTypes';
import { ExecutableDebugAdapter, SocketDebugAdapter, AbstractDebugAdapter } from 'vs/workbench/contrib/debug/node/debugAdapter';
import { ExtHostWorkspace, ExtHostWorkspaceProvider } from 'vs/workbench/api/node/extHostWorkspace';
import { IExtHostWorkspaceProvider } from 'vs/workbench/api/node/extHostWorkspace';
import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/node/extHostDocumentsAndEditors';
import { ITerminalSettings, IDebuggerContribution, IConfig, IDebugAdapter, IDebugAdapterServer, IDebugAdapterExecutable, IAdapterDescriptor } from 'vs/workbench/contrib/debug/common/debug';
Expand Down Expand Up @@ -82,7 +82,7 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape {


constructor(mainContext: IMainContext,
private _workspaceService: ExtHostWorkspace,
private _workspaceService: IExtHostWorkspaceProvider,
private _extensionService: ExtHostExtensionService,
private _editorsService: ExtHostDocumentsAndEditors,
private _configurationService: ExtHostConfiguration,
Expand Down Expand Up @@ -359,12 +359,12 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape {
}

public async $substituteVariables(folderUri: UriComponents | undefined, config: IConfig): Promise<IConfig> {
const [workspaceProvider, configProvider] = await Promise.all([this._workspaceService.getWorkspaceProvider(), this._configurationService.getConfigProvider()]);
const [workspaceFolders, configProvider] = await Promise.all([this._workspaceService.getWorkspaceFolders2(), this._configurationService.getConfigProvider()]);
if (!this._variableResolver) {
this._variableResolver = new ExtHostVariableResolverService(workspaceProvider, this._editorsService, configProvider);
this._variableResolver = new ExtHostVariableResolverService(workspaceFolders, this._editorsService, configProvider);
}
let ws: IWorkspaceFolder | undefined;
const folder = this.getFolder(folderUri, workspaceProvider);
const folder = await this.getFolder(folderUri);
if (folder) {
ws = {
uri: folder.uri,
Expand All @@ -379,10 +379,9 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape {
}

public async $startDASession(debugAdapterHandle: number, sessionDto: IDebugSessionDto): Promise<void> {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
const mythis = this;

const session = this.getSession(sessionDto, workspaceProvider);
const session = await this.getSession(sessionDto);
return this.getAdapterDescriptor(this.getAdapterFactoryByType(session.type), session).then(x => {

const adapter = this.convertToDto(x);
Expand Down Expand Up @@ -547,75 +546,73 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape {
}

public async $provideDebugConfigurations(configProviderHandle: number, folderUri: UriComponents | undefined): Promise<vscode.DebugConfiguration[]> {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
let provider = this.getConfigProviderByHandle(configProviderHandle);
if (!provider) {
return Promise.reject(new Error('no handler found'));
}
if (!provider.provideDebugConfigurations) {
return Promise.reject(new Error('handler has no method provideDebugConfigurations'));
}
return asPromise(() => provider.provideDebugConfigurations(this.getFolder(folderUri, workspaceProvider), CancellationToken.None));
const folder = await this.getFolder(folderUri);
return asPromise(() => provider.provideDebugConfigurations(folder, CancellationToken.None));
}

public async $resolveDebugConfiguration(configProviderHandle: number, folderUri: UriComponents | undefined, debugConfiguration: vscode.DebugConfiguration): Promise<vscode.DebugConfiguration> {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
let provider = this.getConfigProviderByHandle(configProviderHandle);
if (!provider) {
return Promise.reject(new Error('no handler found'));
}
if (!provider.resolveDebugConfiguration) {
return Promise.reject(new Error('handler has no method resolveDebugConfiguration'));
}
return asPromise(() => provider.resolveDebugConfiguration(this.getFolder(folderUri, workspaceProvider), debugConfiguration, CancellationToken.None));
const folder = await this.getFolder(folderUri);
return asPromise(() => provider.resolveDebugConfiguration(folder, debugConfiguration, CancellationToken.None));
}

// TODO@AW legacy
public async $legacyDebugAdapterExecutable(configProviderHandle: number, folderUri: UriComponents | undefined): Promise<IAdapterDescriptor> {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
let provider = this.getConfigProviderByHandle(configProviderHandle);
if (!provider) {
return Promise.reject(new Error('no handler found'));
}
if (!provider.debugAdapterExecutable) {
return Promise.reject(new Error('handler has no method debugAdapterExecutable'));
}
return asPromise(() => provider.debugAdapterExecutable(this.getFolder(folderUri, workspaceProvider), CancellationToken.None)).then(x => this.convertToDto(x));
const folder = await this.getFolder(folderUri);
return asPromise(() => provider.debugAdapterExecutable(folder, CancellationToken.None)).then(x => this.convertToDto(x));
}

public async $provideDebugAdapter(adapterProviderHandle: number, sessionDto: IDebugSessionDto): Promise<IAdapterDescriptor> {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
let adapterProvider = this.getAdapterProviderByHandle(adapterProviderHandle);
if (!adapterProvider) {
return Promise.reject(new Error('no handler found'));
}
return this.getAdapterDescriptor(adapterProvider, this.getSession(sessionDto, workspaceProvider)).then(x => this.convertToDto(x));
const session = await this.getSession(sessionDto);
return this.getAdapterDescriptor(adapterProvider, session).then(x => this.convertToDto(x));
}

public async $acceptDebugSessionStarted(sessionDto: IDebugSessionDto): Promise<void> {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
this._onDidStartDebugSession.fire(this.getSession(sessionDto, workspaceProvider));
const session = await this.getSession(sessionDto);
this._onDidStartDebugSession.fire(session);
}

public async $acceptDebugSessionTerminated(sessionDto: IDebugSessionDto): Promise<void> {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
const session = this.getSession(sessionDto, workspaceProvider);
const session = await this.getSession(sessionDto);
if (session) {
this._onDidTerminateDebugSession.fire(session);
this._debugSessions.delete(session.id);
}
}

public async $acceptDebugSessionActiveChanged(sessionDto: IDebugSessionDto | undefined): Promise<void> {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
this._activeDebugSession = sessionDto ? this.getSession(sessionDto, workspaceProvider) : undefined;
this._activeDebugSession = sessionDto ? await this.getSession(sessionDto) : undefined;
this._onDidChangeActiveDebugSession.fire(this._activeDebugSession);
}

public async $acceptDebugSessionCustomEvent(sessionDto: IDebugSessionDto, event: any): Promise<void> {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
const session = await this.getSession(sessionDto);
const ee: vscode.DebugSessionCustomEvent = {
session: this.getSession(sessionDto, workspaceProvider),
session: session,
event: event.event,
body: event.body
};
Expand Down Expand Up @@ -780,23 +777,24 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape {
}
}

private getSession(dto: IDebugSessionDto, workspaceProvider: ExtHostWorkspaceProvider): ExtHostDebugSession {
private async getSession(dto: IDebugSessionDto): Promise<ExtHostDebugSession> {
if (dto) {
if (typeof dto === 'string') {
return this._debugSessions.get(dto);
} else {
const debugSession = new ExtHostDebugSession(this._debugServiceProxy, dto.id, dto.type, dto.name, this.getFolder(dto.folderUri, workspaceProvider), dto.configuration);
const folder = await this.getFolder(dto.folderUri);
const debugSession = new ExtHostDebugSession(this._debugServiceProxy, dto.id, dto.type, dto.name, folder, dto.configuration);
this._debugSessions.set(debugSession.id, debugSession);
return debugSession;
}
}
return undefined;
}

private getFolder(_folderUri: UriComponents | undefined, workspaceProvider: ExtHostWorkspaceProvider): vscode.WorkspaceFolder | undefined {
private async getFolder(_folderUri: UriComponents | undefined): Promise<vscode.WorkspaceFolder | undefined> {
if (_folderUri) {
const folderURI = URI.revive(_folderUri);
return workspaceProvider.resolveWorkspaceFolder(folderURI);
return await this._workspaceService.resolveWorkspaceFolder2(folderURI);
}
return undefined;
}
Expand Down Expand Up @@ -857,18 +855,17 @@ export class ExtHostDebugConsole implements vscode.DebugConsole {

export class ExtHostVariableResolverService extends AbstractVariableResolverService {

constructor(workspaceService: ExtHostWorkspaceProvider, editorService: ExtHostDocumentsAndEditors, configurationService: ExtHostConfigProvider) {
constructor(folders: vscode.WorkspaceFolder[], editorService: ExtHostDocumentsAndEditors, configurationService: ExtHostConfigProvider) {
super({
getFolderUri: (folderName: string): URI => {
const folders = workspaceService.getWorkspaceFolders();
const found = folders.filter(f => f.name === folderName);
if (found && found.length > 0) {
return found[0].uri;
}
return undefined;
},
getWorkspaceFolderCount: (): number => {
return workspaceService.getWorkspaceFolders().length;
return folders.length;
},
getConfigurationValue: (folderUri: URI, section: string) => {
return configurationService.getConfiguration(undefined, folderUri).get<string>(section);
Expand Down
Loading

0 comments on commit 3199f1f

Please sign in to comment.