提交 0c29dc72 编写于 作者: B Benjamin Pasero

allow workspaces with 0 folders (#34622)

上级 8751a1c2
......@@ -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.`);
}
......
......@@ -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));
}
......
......@@ -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: '' },
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册