From 43d51dea61e28dc650a26ee33db2e4b2a4c5bf54 Mon Sep 17 00:00:00 2001 From: Remi Schnekenburger Date: Mon, 18 Dec 2023 11:53:37 +0100 Subject: [PATCH] updateWorkspaceFolder may create an untitled workspace if none is defined fixes #13100 contributed on behalf of STMicroelectronics Signed-off-by: Remi Schnekenburger --- CHANGELOG.md | 2 ++ packages/workspace/src/browser/workspace-service.ts | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77a91d23b8776..412473d665f88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,9 @@ - [Previous Changelogs](https://github.com/eclipse-theia/theia/tree/master/doc/changelogs/) ## Unreleased + - [terminal] Use application shell methods for expanding/collapsing bottom panel for "Terminal: Toggle Terminal" command [#13131](https://github.com/eclipse-theia/theia/pull/13131) +- [workspace] Create an empty workspace if no workspace is active on updateWorkspaceFolders [#13181](https://github.com/eclipse-theia/theia/pull/13181) - contributed on behalf of STMicroelectronics ## v1.44.0 - 11/30/2023 diff --git a/packages/workspace/src/browser/workspace-service.ts b/packages/workspace/src/browser/workspace-service.ts index 81f1ff8c0468e..178bd9cf98141 100644 --- a/packages/workspace/src/browser/workspace-service.ts +++ b/packages/workspace/src/browser/workspace-service.ts @@ -404,8 +404,12 @@ export class WorkspaceService implements FrontendApplicationContribution { } async spliceRoots(start: number, deleteCount?: number, ...rootsToAdd: URI[]): Promise { - if (!this._workspace) { - throw new Error('There is no active workspace'); + if (!this._workspace || this._workspace.isDirectory) { + const untitledWorkspace = await this.getUntitledWorkspace(); + await this.save(untitledWorkspace); + if (!this._workspace) { + throw new Error('Could not create new untitled workspace'); + } } const dedup = new Set(); const roots = this._roots.map(root => (dedup.add(root.resource.toString()), root.resource.toString())); @@ -421,10 +425,7 @@ export class WorkspaceService implements FrontendApplicationContribution { if (!toRemove.length && !toAdd.length) { return []; } - if (this._workspace.isDirectory) { - const untitledWorkspace = await this.getUntitledWorkspace(); - await this.save(untitledWorkspace); - } + const currentData = await this.getWorkspaceDataFromFile(); const newData = WorkspaceData.buildWorkspaceData(roots, currentData); await this.writeWorkspaceFile(this._workspace, newData);