Skip to content

Commit 5ef5fb3

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix-1278
2 parents bda787d + e3d6460 commit 5ef5fb3

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
@@ -9,17 +9,30 @@ import { currentWorkspaceFolder, notIsfs, uriOfWorkspaceFolder } from "../utils"
99
import { getUrisForDocument } from "../utils/documentIndex";
1010

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

src/utils/index.ts

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

512-
const cwd: string = await fileExists(vscode.Uri.file(path.join(workspaceFolderPath, file))).then((exists) => {
512+
const cwd: string = await fileExists(vscode.Uri.file(path.join(workspaceFolderPath, file))).then(async (exists) => {
513513
if (exists) {
514-
return workspaceRootPath;
515-
} else {
516-
throw new Error(`File '${file}' not found.`);
514+
return workspaceFolderPath;
515+
}
516+
if (workspaceFolderPath !== workspaceRootPath) {
517+
exists = await fileExists(vscode.Uri.file(path.join(workspaceRootPath, file)));
518+
if (exists) {
519+
return workspaceRootPath;
520+
}
521+
throw new Error(`File '${file}' not found in ${workspaceFolderPath} or ${workspaceRootPath}.`);
517522
}
523+
throw new Error(`File '${file}' not found in ${workspaceFolderPath}.`);
518524
});
519525

520526
if (!cwd) {
@@ -530,7 +536,7 @@ export async function portFromDockerCompose(): Promise<{ port: number; docker: b
530536
reject(error.message);
531537
}
532538
if (!stdout.replaceAll("\r", "").split("\n").includes(service)) {
533-
reject(`Service '${service}' not found in '${file}', or not running.`);
539+
reject(`Service '${service}' not found in '${path.join(cwd, file)}', or not running.`);
534540
}
535541

536542
exec(`${cmd} port --protocol=tcp ${service} ${internalPort}`, { cwd }, (error, stdout) => {
@@ -539,7 +545,7 @@ export async function portFromDockerCompose(): Promise<{ port: number; docker: b
539545
}
540546
const [, port] = stdout.match(/:(\d+)/) || [];
541547
if (!port) {
542-
reject(`Port ${internalPort} not published for service '${service}'.`);
548+
reject(`Port ${internalPort} not published for service '${service}' in '${path.join(cwd, file)}'.`);
543549
}
544550
resolve({ port: parseInt(port, 10), docker: true, service });
545551
});

0 commit comments

Comments
 (0)