Skip to content

Give priority to folder-specific docker-compose.yml once again #1464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/providers/DocumentContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) => {
Expand All @@ -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 });
});
Expand Down
Loading