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

Normalize URI's before interacting with recentworkspaces.json #11016

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
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