Skip to content

Render links for included env_file paths #441

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 1 commit into from
Aug 20, 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 5 additions & 1 deletion internal/compose/documentLink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
81 changes: 81 additions & 0 deletions internal/compose/documentLink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading