Skip to content

Commit

Permalink
Ensure recentworkspaces.json contains only stringified URI's (#11016)
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-grant-work authored Apr 20, 2022
1 parent c70312f commit a68364b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/workspace/src/node/default-workspace-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('DefaultWorkspaceServer', function (): void {

const recent = await workspaceServer.getRecentWorkspaces();

expect(recent).to.have.members([FileUri.fsPath(tmpConfigDir)]);
expect(recent).to.have.members([tmpConfigDir.toString()]);
});

it('should ignore non-string array entries but return remaining existing file paths', async function (): Promise<void> {
Expand All @@ -95,7 +95,7 @@ describe('DefaultWorkspaceServer', function (): void {

const recent = await workspaceServer.getRecentWorkspaces();

expect(recent).to.have.members([FileUri.fsPath(tmpConfigDir)]);
expect(recent).to.have.members([tmpConfigDir.toString()]);
});
});
});
9 changes: 6 additions & 3 deletions packages/workspace/src/node/default-workspace-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { CliContribution } from '@theia/core/lib/node/cli';
import { Deferred } from '@theia/core/lib/common/promise-util';
import { WorkspaceServer, CommonWorkspaceUtils } from '../common';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import URI from '@theia/core/lib/common/uri';

@injectable()
export class WorkspaceCliContribution implements CliContribution {
Expand Down Expand Up @@ -101,14 +102,16 @@ export class DefaultWorkspaceServer implements WorkspaceServer, BackendApplicati
return this.root.promise;
}

async setMostRecentlyUsedWorkspace(uri: string): Promise<void> {
async setMostRecentlyUsedWorkspace(rawUri: string): Promise<void> {
const uri = rawUri && new URI(rawUri).toString(); // the empty string is used as a signal from the frontend not to load a workspace.
this.root = new Deferred();
this.root.resolve(uri);
const recentRoots = Array.from(new Set([uri, ...await this.getRecentWorkspaces()]));
this.writeToUserHome({ recentRoots });
}

async removeRecentWorkspace(uri: string): Promise<void> {
async removeRecentWorkspace(rawUri: string): Promise<void> {
const uri = rawUri && new URI(rawUri).toString(); // the empty string is used as a signal from the frontend not to load a workspace.
const recentRoots = await this.getRecentWorkspaces();
const index = recentRoots.indexOf(uri);
if (index !== -1) {
Expand All @@ -126,7 +129,7 @@ export class DefaultWorkspaceServer implements WorkspaceServer, BackendApplicati
data.recentRoots.forEach(element => {
if (element.length > 0) {
if (this.workspaceStillExist(element)) {
listUri.push(FileUri.fsPath(element));
listUri.push(element);
}
}
});
Expand Down

0 comments on commit a68364b

Please sign in to comment.