Skip to content

Commit

Permalink
allow workspaces with 0 folders (#34622)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Sep 21, 2017
1 parent 8751a1c commit 0c29dc7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ export class WorkspacesMainService implements IWorkspacesMainService {
throw new Error(`${path} cannot be parsed as JSON file (${error}).`);
}

// Filter out folders which do not have a path set
// Filter out folders which do not have a path or uri set
if (Array.isArray(storedWorkspace.folders)) {
storedWorkspace.folders = storedWorkspace.folders.filter(folder => isStoredWorkspaceFolder(folder));
}

// Validate
if (!Array.isArray(storedWorkspace.folders) || storedWorkspace.folders.length === 0) {
if (!Array.isArray(storedWorkspace.folders)) {
throw new Error(`${path} looks like an invalid workspace file.`);
}

Expand Down
15 changes: 7 additions & 8 deletions src/vs/workbench/parts/files/browser/fileActions.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,13 @@ class FilesViewerActionContributor extends ActionBarContributor {
}

if (stat.isRoot && this.environmentService.appQuality !== 'stable') {
let action: Action = this.instantiationService.createInstance(AddRootFolderAction, AddRootFolderAction.ID, AddRootFolderAction.LABEL);
action.order = 52;
actions.push(action);
if (this.contextService.getWorkspace().folders.length > 1) {
action = this.instantiationService.createInstance(RemoveRootFolderAction, stat.resource, RemoveRootFolderAction.ID, RemoveRootFolderAction.LABEL);
action.order = 53;
actions.push(action);
}
const addRootFolderAction: Action = this.instantiationService.createInstance(AddRootFolderAction, AddRootFolderAction.ID, AddRootFolderAction.LABEL);
addRootFolderAction.order = 52;
actions.push(addRootFolderAction);

const removeRootFolderAction = this.instantiationService.createInstance(RemoveRootFolderAction, stat.resource, RemoveRootFolderAction.ID, RemoveRootFolderAction.LABEL);
removeRootFolderAction.order = 53;
actions.push(removeRootFolderAction);
actions.push(new Separator(null, 54));
}

Expand Down
7 changes: 2 additions & 5 deletions src/vs/workbench/services/configuration/node/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ contributionRegistry.registerSchema('vscode://schemas/workspaceConfig', {
required: ['folders'],
properties: {
'folders': {
minItems: 1,
minItems: 0,
uniqueItems: true,
description: nls.localize('workspaceConfig.folders.description', "List of folders to be loaded in the workspace. Must be a file path. e.g. `/root/folderA` or `./folderA` for a relative path that will be resolved against the location of the workspace file."),
description: nls.localize('workspaceConfig.folders.description', "List of folders to be loaded in the workspace."),
items: {
type: 'object',
default: { path: '' },
Expand Down Expand Up @@ -407,9 +407,6 @@ export class WorkspaceService extends Disposable implements IWorkspaceConfigurat
.then(() => {
const workspaceConfigurationModel = this.workspaceConfiguration.workspaceConfigurationModel;
const workspaceFolders = toWorkspaceFolders(workspaceConfigurationModel.folders, URI.file(paths.dirname(workspaceConfigPath.fsPath)));
if (!workspaceFolders.length) {
return TPromise.wrapError<Workspace>(new Error('Invalid workspace configuraton file ' + workspaceConfigPath));
}
const workspaceId = workspaceIdentifier.id;
const workspaceName = getWorkspaceLabel({ id: workspaceId, configPath: workspaceConfigPath.fsPath }, this.environmentService);
return new Workspace(workspaceId, workspaceName, workspaceFolders, workspaceConfigPath);
Expand Down

0 comments on commit 0c29dc7

Please sign in to comment.