Skip to content

Commit e3d6460

Browse files
Give priority to folder-specific docker-compose.yml once again (#1464)
* Give priority to folder-specific docker-compose.yml file once again * Make compareConns function docker-compose aware
1 parent 203c016 commit e3d6460

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/providers/DocumentContentProvider.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,30 @@ import { config, FILESYSTEM_SCHEMA, FILESYSTEM_READONLY_SCHEMA, OBJECTSCRIPT_FIL
88
import { currentWorkspaceFolder, uriOfWorkspaceFolder } from "../utils";
99

1010
export function compareConns(
11-
conn1: { ns: any; server: any; host: any; port: any },
12-
conn2: { ns: any; server: any; host: any; port: any }
11+
conn1: { ns: any; server: any; host: any; port: any; "docker-compose": any },
12+
conn2: { ns: any; server: any; host: any; port: any; "docker-compose": any }
1313
): boolean {
1414
if (conn1.ns === conn2.ns) {
15+
// Same namespace name
1516
if (conn1.server && conn2.server) {
17+
// Both connections name an entry in intersystems.servers
1618
if (conn1.server === conn2.server) {
1719
return true;
1820
}
1921
} else if (!conn1.server && !conn2.server) {
20-
if (conn1.host === conn2.host && conn1.port === conn2.port) {
21-
return true;
22+
if (conn1.port && conn2.port) {
23+
// Both connections specify a target port
24+
if (conn1.host === conn2.host && conn1.port === conn2.port) {
25+
return true;
26+
}
27+
} else if (conn1["docker-compose"] && conn2["docker-compose"]) {
28+
// Both connections specify a docker-compose object
29+
if (conn1["docker-compose"].service === conn2["docker-compose"].service) {
30+
// Assume that if the service names match then the connection is to the same place.
31+
// This may not be true (e.g. if the same service name is used in folder-specific docker-compose files)
32+
// but it's the best we can do here without more information.
33+
return true;
34+
}
2235
}
2336
}
2437
}

src/utils/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,18 @@ export async function portFromDockerCompose(): Promise<{ port: number; docker: b
473473
const workspaceFolderPath = workspaceFolder.fsPath;
474474
const workspaceRootPath = vscode.workspace.workspaceFolders[0].uri.fsPath;
475475

476-
const cwd: string = await fileExists(vscode.Uri.file(path.join(workspaceFolderPath, file))).then((exists) => {
476+
const cwd: string = await fileExists(vscode.Uri.file(path.join(workspaceFolderPath, file))).then(async (exists) => {
477477
if (exists) {
478-
return workspaceRootPath;
479-
} else {
480-
throw new Error(`File '${file}' not found.`);
478+
return workspaceFolderPath;
479+
}
480+
if (workspaceFolderPath !== workspaceRootPath) {
481+
exists = await fileExists(vscode.Uri.file(path.join(workspaceRootPath, file)));
482+
if (exists) {
483+
return workspaceRootPath;
484+
}
485+
throw new Error(`File '${file}' not found in ${workspaceFolderPath} or ${workspaceRootPath}.`);
481486
}
487+
throw new Error(`File '${file}' not found in ${workspaceFolderPath}.`);
482488
});
483489

484490
if (!cwd) {
@@ -494,7 +500,7 @@ export async function portFromDockerCompose(): Promise<{ port: number; docker: b
494500
reject(error.message);
495501
}
496502
if (!stdout.replaceAll("\r", "").split("\n").includes(service)) {
497-
reject(`Service '${service}' not found in '${file}', or not running.`);
503+
reject(`Service '${service}' not found in '${path.join(cwd, file)}', or not running.`);
498504
}
499505

500506
exec(`${cmd} port --protocol=tcp ${service} ${internalPort}`, { cwd }, (error, stdout) => {
@@ -503,7 +509,7 @@ export async function portFromDockerCompose(): Promise<{ port: number; docker: b
503509
}
504510
const [, port] = stdout.match(/:(\d+)/) || [];
505511
if (!port) {
506-
reject(`Port ${internalPort} not published for service '${service}'.`);
512+
reject(`Port ${internalPort} not published for service '${service}' in '${path.join(cwd, file)}'.`);
507513
}
508514
resolve({ port: parseInt(port, 10), docker: true, service });
509515
});

0 commit comments

Comments
 (0)