mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
very first proposed API for multiple roots, #28526
This commit is contained in:
@@ -54,6 +54,12 @@ export interface IExtensionApiFactory {
|
||||
(extension: IExtensionDescription): typeof vscode;
|
||||
}
|
||||
|
||||
function assertProposedApi(extension: IExtensionDescription): void {
|
||||
if (!extension.enableProposedApi) {
|
||||
throw new Error(`[${extension.id}]: Proposed API is only available when running out of dev or with the following command line switch: --enable-proposed-api ${extension.id}`);
|
||||
}
|
||||
}
|
||||
|
||||
function proposedApiFunction<T>(extension: IExtensionDescription, fn: T): T {
|
||||
if (extension.enableProposedApi) {
|
||||
return fn;
|
||||
@@ -348,6 +354,13 @@ export function createApiFactory(
|
||||
set rootPath(value) {
|
||||
throw errors.readonly();
|
||||
},
|
||||
get workspaceFolders() {
|
||||
assertProposedApi(extension);
|
||||
return extHostWorkspace.getRoots();
|
||||
},
|
||||
onDidChangeWorkspaceFolders: proposedApiFunction(extension, (listener, thisArgs?, disposables?) => {
|
||||
return extHostWorkspace.onDidChangeWorkspace(listener, thisArgs, disposables);
|
||||
}),
|
||||
asRelativePath: (pathOrUri) => {
|
||||
return extHostWorkspace.getRelativePath(pathOrUri);
|
||||
},
|
||||
|
||||
@@ -21,11 +21,11 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
|
||||
private static _requestIdPool = 0;
|
||||
|
||||
private readonly _onDidChangeWorkspace = new Emitter<this>();
|
||||
private readonly _onDidChangeWorkspace = new Emitter<URI[]>();
|
||||
private readonly _proxy: MainThreadWorkspaceShape;
|
||||
private _workspace: Workspace;
|
||||
|
||||
readonly onDidChangeWorkspace: Event<this> = this._onDidChangeWorkspace.event;
|
||||
readonly onDidChangeWorkspace: Event<URI[]> = this._onDidChangeWorkspace.event;
|
||||
|
||||
constructor(threadService: IThreadService, data: IWorkspaceData) {
|
||||
super();
|
||||
@@ -35,8 +35,12 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
|
||||
// --- workspace ---
|
||||
|
||||
get workspace(): Workspace {
|
||||
return this._workspace;
|
||||
getRoots(): URI[] {
|
||||
if (!this._workspace) {
|
||||
return undefined;
|
||||
} else {
|
||||
return this._workspace.roots.slice(0);
|
||||
}
|
||||
}
|
||||
|
||||
getPath(): string {
|
||||
@@ -85,7 +89,7 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
|
||||
$acceptWorkspaceData(data: IWorkspaceData): void {
|
||||
this._workspace = data ? new Workspace(data.id, data.name, data.roots) : null;
|
||||
this._onDidChangeWorkspace.fire(this);
|
||||
this._onDidChangeWorkspace.fire(this.getRoots());
|
||||
}
|
||||
|
||||
// --- search ---
|
||||
|
||||
Reference in New Issue
Block a user