From da61fbee298ae267cd3ee4f842373f17d340ac4f Mon Sep 17 00:00:00 2001 From: Remy Suen Date: Wed, 20 Aug 2025 10:03:28 -0400 Subject: [PATCH] Render links for included env_file paths Signed-off-by: Remy Suen --- CHANGELOG.md | 3 +- internal/compose/documentLink.go | 6 +- internal/compose/documentLink_test.go | 81 +++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b08a0b6..035e04b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,8 @@ All notable changes to the Docker Language Server will be documented in this fil - textDocument/completion - suggest image tags for images from Docker Hub ([#375](https://github.com/docker/docker-language-server/issues/375)) - textDocument/documentLink - - support providing links for the `env_file` attribute of a service object ([#436](https://github.com/docker/docker-language-server/issues/436)) + - support providing links for the `env_file` attribute of a service object ([#436](https://github.com/docker/docker-language-server/issues/436)) + - support providing links for the `env_file` for included paths ([#438](https://github.com/docker/docker-language-server/issues/438)) - Bake - textDocument/completion - provide local file and folder name suggestions ([#414](https://github.com/docker/docker-language-server/issues/414)) diff --git a/internal/compose/documentLink.go b/internal/compose/documentLink.go index b1e7784..02c3070 100644 --- a/internal/compose/documentLink.go +++ b/internal/compose/documentLink.go @@ -133,12 +133,16 @@ func includedPaths(nodes []ast.Node) []*token.Token { for _, entry := range nodes { if mappingNode, ok := resolveAnchor(entry).(*ast.MappingNode); ok { for _, value := range mappingNode.Values { - if resolveAnchor(value.Key).GetToken().Value == "path" { + attributeName := resolveAnchor(value.Key).GetToken().Value + if attributeName == "path" || attributeName == "env_file" { if paths, ok := resolveAnchor(value.Value).(*ast.SequenceNode); ok { // include: // - path: // - ../commons/compose.yaml // - ./commons-override.yaml + // - env_file: + // - ../another/.env + // - ../another/dev.env for _, path := range paths.Values { if _, ok := path.(*ast.AliasNode); !ok { tokens = append(tokens, resolveAnchor(path).GetToken()) diff --git a/internal/compose/documentLink_test.go b/internal/compose/documentLink_test.go index e6842aa..9930b12 100644 --- a/internal/compose/documentLink_test.go +++ b/internal/compose/documentLink_test.go @@ -397,6 +397,87 @@ include: - *anchor`, links: []protocol.DocumentLink{}, }, + { + name: "env_file string attribute", + content: ` +include: + - env_file: .env`, + links: []protocol.DocumentLink{ + { + Range: protocol.Range{ + Start: protocol.Position{Line: 2, Character: 14}, + End: protocol.Position{Line: 2, Character: 18}, + }, + Target: documentLinkTarget(testsFolder, ".env"), + Tooltip: documentLinkTooltip(testsFolder, ".env"), + }, + }, + }, + { + name: "env_file string attribute with an anchor", + content: ` +include: + - env_file: &anchor .env`, + links: []protocol.DocumentLink{ + { + Range: protocol.Range{ + Start: protocol.Position{Line: 2, Character: 22}, + End: protocol.Position{Line: 2, Character: 26}, + }, + Target: documentLinkTarget(testsFolder, ".env"), + Tooltip: documentLinkTooltip(testsFolder, ".env"), + }, + }, + }, + { + name: "env_file string attribute with an alias", + content: ` +include: + - env_file: *alias`, + links: []protocol.DocumentLink{}, + }, + { + name: "env_file array attribute", + content: ` +include: + - env_file: + - .env`, + links: []protocol.DocumentLink{ + { + Range: protocol.Range{ + Start: protocol.Position{Line: 3, Character: 6}, + End: protocol.Position{Line: 3, Character: 10}, + }, + Target: documentLinkTarget(testsFolder, ".env"), + Tooltip: documentLinkTooltip(testsFolder, ".env"), + }, + }, + }, + { + name: "env_file array attribute with an anchor", + content: ` +include: + - env_file: + - &anchor .env`, + links: []protocol.DocumentLink{ + { + Range: protocol.Range{ + Start: protocol.Position{Line: 3, Character: 14}, + End: protocol.Position{Line: 3, Character: 18}, + }, + Target: documentLinkTarget(testsFolder, ".env"), + Tooltip: documentLinkTooltip(testsFolder, ".env"), + }, + }, + }, + { + name: "env_file array attribute with an alias", + content: ` +include: + - env_file: + - *alias`, + links: []protocol.DocumentLink{}, + }, } for _, tc := range testCases {