diff --git a/src/providers/DocumentContentProvider.ts b/src/providers/DocumentContentProvider.ts index 07910d30..7c963f59 100644 --- a/src/providers/DocumentContentProvider.ts +++ b/src/providers/DocumentContentProvider.ts @@ -8,17 +8,30 @@ import { config, FILESYSTEM_SCHEMA, FILESYSTEM_READONLY_SCHEMA, OBJECTSCRIPT_FIL import { currentWorkspaceFolder, uriOfWorkspaceFolder } from "../utils"; export function compareConns( - conn1: { ns: any; server: any; host: any; port: any }, - conn2: { ns: any; server: any; host: any; port: any } + conn1: { ns: any; server: any; host: any; port: any; "docker-compose": any }, + conn2: { ns: any; server: any; host: any; port: any; "docker-compose": any } ): boolean { if (conn1.ns === conn2.ns) { + // Same namespace name if (conn1.server && conn2.server) { + // Both connections name an entry in intersystems.servers if (conn1.server === conn2.server) { return true; } } else if (!conn1.server && !conn2.server) { - if (conn1.host === conn2.host && conn1.port === conn2.port) { - return true; + if (conn1.port && conn2.port) { + // Both connections specify a target port + if (conn1.host === conn2.host && conn1.port === conn2.port) { + return true; + } + } else if (conn1["docker-compose"] && conn2["docker-compose"]) { + // Both connections specify a docker-compose object + if (conn1["docker-compose"].service === conn2["docker-compose"].service) { + // Assume that if the service names match then the connection is to the same place. + // This may not be true (e.g. if the same service name is used in folder-specific docker-compose files) + // but it's the best we can do here without more information. + return true; + } } } } diff --git a/src/utils/index.ts b/src/utils/index.ts index 77e9fa85..a308a827 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -473,12 +473,18 @@ export async function portFromDockerCompose(): Promise<{ port: number; docker: b const workspaceFolderPath = workspaceFolder.fsPath; const workspaceRootPath = vscode.workspace.workspaceFolders[0].uri.fsPath; - const cwd: string = await fileExists(vscode.Uri.file(path.join(workspaceFolderPath, file))).then((exists) => { + const cwd: string = await fileExists(vscode.Uri.file(path.join(workspaceFolderPath, file))).then(async (exists) => { if (exists) { - return workspaceRootPath; - } else { - throw new Error(`File '${file}' not found.`); + return workspaceFolderPath; + } + if (workspaceFolderPath !== workspaceRootPath) { + exists = await fileExists(vscode.Uri.file(path.join(workspaceRootPath, file))); + if (exists) { + return workspaceRootPath; + } + throw new Error(`File '${file}' not found in ${workspaceFolderPath} or ${workspaceRootPath}.`); } + throw new Error(`File '${file}' not found in ${workspaceFolderPath}.`); }); if (!cwd) { @@ -494,7 +500,7 @@ export async function portFromDockerCompose(): Promise<{ port: number; docker: b reject(error.message); } if (!stdout.replaceAll("\r", "").split("\n").includes(service)) { - reject(`Service '${service}' not found in '${file}', or not running.`); + reject(`Service '${service}' not found in '${path.join(cwd, file)}', or not running.`); } exec(`${cmd} port --protocol=tcp ${service} ${internalPort}`, { cwd }, (error, stdout) => { @@ -503,7 +509,7 @@ export async function portFromDockerCompose(): Promise<{ port: number; docker: b } const [, port] = stdout.match(/:(\d+)/) || []; if (!port) { - reject(`Port ${internalPort} not published for service '${service}'.`); + reject(`Port ${internalPort} not published for service '${service}' in '${path.join(cwd, file)}'.`); } resolve({ port: parseInt(port, 10), docker: true, service }); });