Skip to content

Commit

Permalink
Dev Container uses the right workspace now
Browse files Browse the repository at this point in the history
When there are more than one workspaces open the config json is picked from the right workspace.
Solves #14307
  • Loading branch information
jbicker committed Nov 29, 2024
1 parent 49770ca commit fc69a85
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ export class ContainerConnectionContribution extends AbstractRemoteRegistryContr
}

async getOrSelectDevcontainerFile(): Promise<string | undefined> {
const devcontainerFiles = await this.connectionProvider.getDevContainerFiles();
const workspace = await this.workspaceService.workspace;
if(!workspace) {
return;
}
const devcontainerFiles = await this.connectionProvider.getDevContainerFiles(workspace.resource.path.toString());

if (devcontainerFiles.length === 1) {
return devcontainerFiles[0].path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ export interface DevContainerFile {

export interface RemoteContainerConnectionProvider extends RpcServer<ContainerOutputProvider> {
connectToContainer(options: ContainerConnectionOptions): Promise<ContainerConnectionResult>;
getDevContainerFiles(): Promise<DevContainerFile[]>;
getDevContainerFiles(workspacePath: string): Promise<DevContainerFile[]>;
getCurrentContainerInfo(port: number): Promise<ContainerInspectInfo | undefined>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ export class DevContainerFileService {
return configuration;
}

async getAvailableFiles(): Promise<DevContainerFile[]> {
const workspace = await this.workspaceServer.getMostRecentlyUsedWorkspace();
if (!workspace) {
return [];
}

async getAvailableFiles(workspace: string): Promise<DevContainerFile[]> {
const devcontainerPath = new URI(workspace).path.join('.devcontainer').fsPath();

return (await this.searchForDevontainerJsonFiles(devcontainerPath, 1)).map(file => ({
Expand All @@ -54,7 +49,7 @@ export class DevContainerFileService {
}

protected async searchForDevontainerJsonFiles(directory: string, depth: number): Promise<string[]> {
if (depth < 0) {
if (depth < 0 || !fs.existsSync(directory)) {
return [];
}
const filesPaths = (await fs.readdir(directory)).map(file => new Path(directory).join(file).fsPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export class DevContainerConnectionProvider implements RemoteContainerConnection
}
}

getDevContainerFiles(): Promise<DevContainerFile[]> {
return this.devContainerFileService.getAvailableFiles();
getDevContainerFiles(workspacePath: string): Promise<DevContainerFile[]> {
return this.devContainerFileService.getAvailableFiles(workspacePath);
}

async createContainerConnection(container: Docker.Container, docker: Docker, name?: string): Promise<RemoteDockerContainerConnection> {
Expand Down

0 comments on commit fc69a85

Please sign in to comment.