From 4dae17693707688e516cb29bf837ddb058a9a447 Mon Sep 17 00:00:00 2001 From: Simon Graband Date: Fri, 14 Feb 2025 14:31:06 +0100 Subject: [PATCH] Fix recent workspace tracking for devcontainer workspaces Ensure devcontainer workspaces are correctly added to recentWorkspaces. Previously, incorrect URI handling caused invalid workspace entries. Now, the workspace path is passed instead of the full URI. Also the setMostRecentlyUsedWorkspace is now called with the correct workspace. Renamed the ContainerConnectionOptions.workspaceUri to workspacePath for consistency. Signed-off-by: Simon Graband --- .../electron-browser/container-connection-contribution.ts | 8 ++++---- .../remote-container-connection-provider.ts | 2 +- .../src/electron-node/docker-container-service.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/dev-container/src/electron-browser/container-connection-contribution.ts b/packages/dev-container/src/electron-browser/container-connection-contribution.ts index 32c21f7c42690..f9aa6ad9477e6 100644 --- a/packages/dev-container/src/electron-browser/container-connection-contribution.ts +++ b/packages/dev-container/src/electron-browser/container-connection-contribution.ts @@ -82,7 +82,7 @@ export class ContainerConnectionContribution extends AbstractRemoteRegistryContr throw new Error(`Devcontainer file at ${filePath} not found in workspace`); } - return this.doOpenInContainer(devcontainerFile, uri.toString()); + return this.doOpenInContainer(devcontainerFile, uri.path.toString()); } async getWorkspaceLabel(uri: URI): Promise { @@ -103,7 +103,7 @@ export class ContainerConnectionContribution extends AbstractRemoteRegistryContr this.doOpenInContainer(devcontainerFile); } - async doOpenInContainer(devcontainerFile: DevContainerFile, workspaceUri?: string): Promise { + async doOpenInContainer(devcontainerFile: DevContainerFile, workspacePath?: string): Promise { const lastContainerInfoKey = `${LAST_USED_CONTAINER}:${devcontainerFile.path}`; const lastContainerInfo = await this.workspaceStorageService.getData(lastContainerInfoKey); @@ -113,7 +113,7 @@ export class ContainerConnectionContribution extends AbstractRemoteRegistryContr nodeDownloadTemplate: this.remotePreferences['remote.nodeDownloadTemplate'], lastContainerInfo, devcontainerFile: devcontainerFile.path, - workspaceUri + workspacePath: workspacePath }); this.workspaceStorageService.setData(lastContainerInfoKey, { @@ -122,7 +122,7 @@ export class ContainerConnectionContribution extends AbstractRemoteRegistryContr }); this.workspaceServer.setMostRecentlyUsedWorkspace( - `${DEV_CONTAINER_WORKSPACE_SCHEME}:${this.workspaceService.workspace?.resource.path}?${DEV_CONTAINER_PATH_QUERY}=${devcontainerFile.path}`); + `${DEV_CONTAINER_WORKSPACE_SCHEME}:${workspacePath ?? this.workspaceService.workspace?.resource.path}?${DEV_CONTAINER_PATH_QUERY}=${devcontainerFile.path}`); this.openRemote(connectionResult.port, false, connectionResult.workspacePath); } diff --git a/packages/dev-container/src/electron-common/remote-container-connection-provider.ts b/packages/dev-container/src/electron-common/remote-container-connection-provider.ts index ef96e6045ddb9..fd8046ba24170 100644 --- a/packages/dev-container/src/electron-common/remote-container-connection-provider.ts +++ b/packages/dev-container/src/electron-common/remote-container-connection-provider.ts @@ -26,7 +26,7 @@ export interface ContainerConnectionOptions { nodeDownloadTemplate?: string; lastContainerInfo?: LastContainerInfo devcontainerFile: string; - workspaceUri?: string; + workspacePath?: string; } export interface LastContainerInfo { diff --git a/packages/dev-container/src/electron-node/docker-container-service.ts b/packages/dev-container/src/electron-node/docker-container-service.ts index 8253ad81917e0..124cc033c11b2 100644 --- a/packages/dev-container/src/electron-node/docker-container-service.ts +++ b/packages/dev-container/src/electron-node/docker-container-service.ts @@ -65,7 +65,7 @@ export class DockerContainerService { async getOrCreateContainer(docker: Docker, options: ContainerConnectionOptions, outputProvider?: ContainerOutputProvider): Promise { let container; - const workspace = new URI(options.workspaceUri ?? await this.workspaceServer.getMostRecentlyUsedWorkspace()); + const workspace = new URI(options.workspacePath ?? await this.workspaceServer.getMostRecentlyUsedWorkspace()); if (options.lastContainerInfo && fs.statSync(options.devcontainerFile).mtimeMs < options.lastContainerInfo.lastUsed) { try {