diff --git a/packages/workspace/src/browser/workspace-service.spec.ts b/packages/workspace/src/browser/workspace-service.spec.ts index bd823250b09a4..f0e73c1bbefbd 100644 --- a/packages/workspace/src/browser/workspace-service.spec.ts +++ b/packages/workspace/src/browser/workspace-service.spec.ts @@ -229,6 +229,38 @@ describe('WorkspaceService', () => { expect((>wsService['rootWatchers']).has(rootB)).to.be.true; }); + it( + 'should resolve a relative workspace root path to a normalized root path', + async () => { + const workspaceFilePath = '/home/workspaceFile'; + const workspaceFileUri = 'file://' + workspaceFilePath; + const workspaceFileStat = { + uri: workspaceFileUri, + lastModification: 0, + isDirectory: false + }; + const rootRelative = '../workspace'; + const rootActual = 'file:///workspace'; + (mockWorkspaceServer.getMostRecentlyUsedWorkspace).resolves(workspaceFileStat.uri); + const stubGetFileStat = (mockFilesystem.getFileStat); + stubGetFileStat.withArgs(workspaceFileUri).resolves(workspaceFileStat); + (mockFilesystem.exists).resolves(true); + (mockFilesystem.resolveContent).resolves({ + stat: workspaceFileStat, + content: `{"folders":[{"path":"${rootRelative}"}],"settings":{}}` + }); + stubGetFileStat.withArgs(rootActual).resolves({ + uri: rootActual, lastModification: 0, isDirectory: true + }); + (mockFileSystemWatcher.watchFileChanges).resolves(new DisposableCollection()); + + await wsService['init'](); + expect(wsService.workspace).to.eq(workspaceFileStat); + expect((await wsService.roots).length).to.eq(1); + expect(wsService.tryGetRoots().length).to.eq(1); + expect(wsService.tryGetRoots()[0].uri).to.eq(rootActual); + }); + it('should set the exposed roots an empty array if the workspace file stores invalid workspace data', async () => { const workspaceFileUri = 'file:///home/workspaceFile'; const workspaceFileStat = { diff --git a/packages/workspace/src/browser/workspace-service.ts b/packages/workspace/src/browser/workspace-service.ts index 64a2b86da72da..ace89e95c4f78 100644 --- a/packages/workspace/src/browser/workspace-service.ts +++ b/packages/workspace/src/browser/workspace-service.ts @@ -427,7 +427,8 @@ export class WorkspaceService implements FrontendApplicationContribution { if (uriStr.endsWith('/')) { uriStr = uriStr.slice(0, -1); } - const fileStat = await this.fileSystem.getFileStat(uriStr); + const normalizedUriStr = new URI(uriStr).normalizePath().toString(); + const fileStat = await this.fileSystem.getFileStat(normalizedUriStr); if (!fileStat) { return undefined; }