Skip to content

Commit f79393a

Browse files
committed
fix: improve /openDevContainer support with local workspace folder
This change allows `localWorkspaceFolder` and `localConfigFile` to be provided which allows us to use `dev-container` rather than `attached-container` to enter enabling all dev container features like file change detection and rebuilding.
1 parent 0c73c83 commit f79393a

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Update `/openDevContainer` to support all dev container features when hostPath
6+
and configFile are provided.
7+
58
## [v1.9.2](https://github.com/coder/vscode-coder/releases/tag/v1.9.2) 2025-06-25
69

710
### Fixed

src/commands.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,8 @@ export class Commands {
631631
const workspaceAgent = args[2] as string;
632632
const devContainerName = args[3] as string;
633633
const devContainerFolder = args[4] as string;
634+
const localWorkspaceFolder = args[5] as string | undefined;
635+
const localConfigFile = args[6] as string | undefined;
634636

635637
await openDevContainer(
636638
baseUrl,
@@ -639,6 +641,8 @@ export class Commands {
639641
workspaceAgent,
640642
devContainerName,
641643
devContainerFolder,
644+
localWorkspaceFolder,
645+
localConfigFile,
642646
);
643647
}
644648

@@ -751,6 +755,8 @@ async function openDevContainer(
751755
workspaceAgent: string,
752756
devContainerName: string,
753757
devContainerFolder: string,
758+
localWorkspaceFolder: string | undefined,
759+
localConfigFile: string | undefined,
754760
) {
755761
const remoteAuthority = toRemoteAuthority(
756762
baseUrl,
@@ -759,11 +765,28 @@ async function openDevContainer(
759765
workspaceAgent,
760766
);
761767

768+
if (!localWorkspaceFolder) {
769+
localConfigFile = undefined;
770+
}
771+
let configFile;
772+
if (localConfigFile) {
773+
configFile = {
774+
path: localConfigFile,
775+
scheme: "vscode-fileHost",
776+
};
777+
}
762778
const devContainer = Buffer.from(
763-
JSON.stringify({ containerName: devContainerName }),
779+
JSON.stringify({
780+
containerName: devContainerName,
781+
hostPath: localWorkspaceFolder,
782+
configFile,
783+
localDocker: false,
784+
}),
764785
"utf-8",
765786
).toString("hex");
766-
const devContainerAuthority = `attached-container+${devContainer}@${remoteAuthority}`;
787+
788+
const type = !!localWorkspaceFolder ? "dev-container" : "attached-container";
789+
const devContainerAuthority = `${type}+${devContainer}@${remoteAuthority}`;
767790

768791
let newWindow = true;
769792
if (!vscode.workspace.workspaceFolders?.length) {

src/extension.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
165165
const workspaceAgent = params.get("agent");
166166
const devContainerName = params.get("devContainerName");
167167
const devContainerFolder = params.get("devContainerFolder");
168+
const localWorkspaceFolder = params.get("localWorkspaceFolder");
169+
const localConfigFile = params.get("localConfigFile");
168170

169171
if (!workspaceOwner) {
170172
throw new Error(
@@ -190,6 +192,12 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
190192
);
191193
}
192194

195+
if (localConfigFile && !localWorkspaceFolder) {
196+
throw new Error(
197+
"local workspace folder must be specified as a query parameter if local config file is provided",
198+
);
199+
}
200+
193201
// We are not guaranteed that the URL we currently have is for the URL
194202
// this workspace belongs to, or that we even have a URL at all (the
195203
// queries will default to localhost) so ask for it if missing.
@@ -228,6 +236,8 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
228236
workspaceAgent,
229237
devContainerName,
230238
devContainerFolder,
239+
localWorkspaceFolder,
240+
localConfigFile,
231241
);
232242
} else {
233243
throw new Error(`Unknown path ${uri.path}`);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy