From a68364b9e06986a1cdb916fb7e50b6dd8833b066 Mon Sep 17 00:00:00 2001 From: colin-grant-work Date: Wed, 20 Apr 2022 15:18:06 -0600 Subject: [PATCH] Ensure recentworkspaces.json contains only stringified URI's (#11016) --- .../workspace/src/node/default-workspace-server.spec.ts | 4 ++-- packages/workspace/src/node/default-workspace-server.ts | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/workspace/src/node/default-workspace-server.spec.ts b/packages/workspace/src/node/default-workspace-server.spec.ts index d1478bb058157..4f556b18ea2c8 100644 --- a/packages/workspace/src/node/default-workspace-server.spec.ts +++ b/packages/workspace/src/node/default-workspace-server.spec.ts @@ -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 { @@ -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()]); }); }); }); diff --git a/packages/workspace/src/node/default-workspace-server.ts b/packages/workspace/src/node/default-workspace-server.ts index 26a17abb3049d..4cdfa5d524f43 100644 --- a/packages/workspace/src/node/default-workspace-server.ts +++ b/packages/workspace/src/node/default-workspace-server.ts @@ -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 { @@ -101,14 +102,16 @@ export class DefaultWorkspaceServer implements WorkspaceServer, BackendApplicati return this.root.promise; } - async setMostRecentlyUsedWorkspace(uri: string): Promise { + async setMostRecentlyUsedWorkspace(rawUri: string): Promise { + 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 { + async removeRecentWorkspace(rawUri: string): Promise { + 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) { @@ -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); } } });