Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updateWorkspaceFolders may create an untitled workspace if none is defined #13181

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 7 additions & 6 deletions packages/workspace/src/browser/workspace-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,12 @@ export class WorkspaceService implements FrontendApplicationContribution {
}

async spliceRoots(start: number, deleteCount?: number, ...rootsToAdd: URI[]): Promise<URI[]> {
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<string>();
const roots = this._roots.map(root => (dedup.add(root.resource.toString()), root.resource.toString()));
Expand All @@ -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);
Expand Down
Loading