Skip to content

Commit

Permalink
Provide additional workspace API to add/remove workspace folders (for #…
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Oct 24, 2017
1 parent a7b743e commit 4790e47
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5198,6 +5198,32 @@ declare module 'vscode' {
*/
export const onDidChangeWorkspaceFolders: Event<WorkspaceFoldersChangeEvent>;

/**
* Adds workspace folders to the currently opened workspace. Will ignore workspace
* folders that are already part of the workspace.
*
* Note: if this workspace had no folder opened, all extensions will be restarted
* so that the (deprecated) `rootPath` property is updated to point to the first workspace
* folder.
*
* @param folders a list of workspace folders to add.
*/
export function addWorkspaceFolders(folders: { uri: Uri, name?: string }[]): Thenable<void>;

/**
* Removes workspace folders from the currently opened workspace if they are part of the
* workspace.
*
* This method will be a no-op when called while not having a workspace opened.
*
* Note: if the first workspace folder is removed, all extensions will be restarted
* so that the (deprecated) `rootPath` property is updated to point to the first workspace
* folder.
*
* @param folders a list of [workspace folders](#WorkspaceFolder) to remove.
*/
export function removeWorkspaceFolders(folders: WorkspaceFolder[]): Thenable<void>;

/**
* Returns the [workspace folder](#WorkspaceFolder) that contains a given uri.
* * returns `undefined` when the given uri doesn't match any workspace folder
Expand Down
8 changes: 8 additions & 0 deletions src/vs/workbench/api/electron-browser/mainThreadWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
this._proxy.$acceptWorkspaceData(this._contextService.getWorkbenchState() === WorkbenchState.EMPTY ? null : this._contextService.getWorkspace());
}

$addFolders(folders: { uri: URI, name?: string }[]): Thenable<void> {
return this._contextService.addFolders(folders);
}

$removeFolders(folders: URI[]): Thenable<void> {
return this._contextService.removeFolders(folders);
}

// --- search ---

$startSearch(include: string | IRelativePattern, exclude: string | IRelativePattern, maxResults: number, requestId: number): Thenable<URI[]> {
Expand Down
6 changes: 6 additions & 0 deletions src/vs/workbench/api/node/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ export function createApiFactory(
get workspaceFolders() {
return extHostWorkspace.getWorkspaceFolders();
},
addWorkspaceFolders(folders) {
return extHostWorkspace.addWorkspaceFolders(folders);
},
removeWorkspaceFolders(folders) {
return extHostWorkspace.removeWorkspaceFolders(folders);
},
onDidChangeWorkspaceFolders: function (listener, thisArgs?, disposables?) {
return extHostWorkspace.onDidChangeWorkspace(listener, thisArgs, disposables);
},
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ export interface MainThreadWorkspaceShape extends IDisposable {
$startSearch(include: string | IRelativePattern, exclude: string | IRelativePattern, maxResults: number, requestId: number): Thenable<URI[]>;
$cancelSearch(requestId: number): Thenable<boolean>;
$saveAll(includeUntitled?: boolean): Thenable<boolean>;
$addFolders(folders: { uri: URI, name?: string }[]): Thenable<void>;
$removeFolders(folders: URI[]): Thenable<void>;
}

export interface MainThreadFileSystemShape extends IDisposable {
Expand Down
11 changes: 11 additions & 0 deletions src/vs/workbench/api/node/extHostWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape {
}
}

addWorkspaceFolders(folders: { uri: URI, name?: string }[]): Thenable<void> {
return this._proxy.$addFolders(folders);
}

removeWorkspaceFolders(folders: vscode.WorkspaceFolder[]): Thenable<void> {
const existingWorkspaceFolders = this.getWorkspaceFolders();
const folderUrisToRemove = folders.filter(folder => existingWorkspaceFolders.indexOf(folder) >= 0).map(f => f.uri);

return this._proxy.$removeFolders(folderUrisToRemove);
}

getWorkspaceFolder(uri: vscode.Uri, resolveParent?: boolean): vscode.WorkspaceFolder {
if (!this._workspace) {
return undefined;
Expand Down

0 comments on commit 4790e47

Please sign in to comment.