Skip to content
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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ All notable changes to the Docker Language Server will be documented in this fil

### Fixed

- Compose
- textDocument/documentLink
- stop returning links for alias nodes in included paths ([#439](https://github.com/docker/docker-language-server/issues/439))
- Bake
- textDocument/completion
- check the type of the block before suggesting items ([#422](https://github.com/docker/docker-language-server/issues/422))
Expand Down
12 changes: 8 additions & 4 deletions internal/compose/documentLink.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func createModelLink(serviceNode *ast.MappingValueNode) *protocol.DocumentLink {
return nil
}

func includedFiles(nodes []ast.Node) []*token.Token {
func includedPaths(nodes []ast.Node) []*token.Token {
tokens := []*token.Token{}
for _, entry := range nodes {
if mappingNode, ok := resolveAnchor(entry).(*ast.MappingNode); ok {
Expand All @@ -140,14 +140,18 @@ func includedFiles(nodes []ast.Node) []*token.Token {
// - ../commons/compose.yaml
// - ./commons-override.yaml
for _, path := range paths.Values {
tokens = append(tokens, resolveAnchor(path).GetToken())
if _, ok := path.(*ast.AliasNode); !ok {
tokens = append(tokens, resolveAnchor(path).GetToken())
}
}
} else {
// include:
// - path: ../commons/compose.yaml
// project_directory: ..
// env_file: ../another/.env
tokens = append(tokens, resolveAnchor(value.Value).GetToken())
if _, ok := value.Value.(*ast.AliasNode); !ok {
tokens = append(tokens, resolveAnchor(value.Value).GetToken())
}
}
}
}
Expand All @@ -171,7 +175,7 @@ func scanForLinks(folderAbsolutePath string, wslDollarSign bool, n *ast.MappingV
switch s.Value {
case "include":
if sequence, ok := resolveAnchor(n.Value).(*ast.SequenceNode); ok {
for _, token := range includedFiles(sequence.Values) {
for _, token := range includedPaths(sequence.Values) {
link := createLink(folderAbsolutePath, wslDollarSign, token)
if link != nil {
links = append(links, *link)
Expand Down
15 changes: 15 additions & 0 deletions internal/compose/documentLink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,21 @@ include:
},
},
},
{
name: "alias on the path's string attribute",
content: `
include:
- path: *anchor`,
links: []protocol.DocumentLink{},
},
{
name: "alias on the path attribute's string array item value",
content: `
include:
- path:
- *anchor`,
links: []protocol.DocumentLink{},
},
}

for _, tc := range testCases {
Expand Down
37 changes: 37 additions & 0 deletions internal/compose/documentSymbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,43 @@ func findSymbols(value string, n *ast.MappingValueNode, mapping map[string]proto
return result
}

func includedFiles(nodes []ast.Node) []*token.Token {
tokens := []*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" {
if paths, ok := resolveAnchor(value.Value).(*ast.SequenceNode); ok {
// include:
// - path:
// - ../commons/compose.yaml
// - ./commons-override.yaml
for _, path := range paths.Values {
tokens = append(tokens, resolveAnchor(path).GetToken())
}
} else {
// include:
// - path: ../commons/compose.yaml
// project_directory: ..
// env_file: ../another/.env
tokens = append(tokens, resolveAnchor(value.Value).GetToken())
}
}
}
} else {
// include:
// - abc.yml
// - def.yml
stringNode := stringNode(entry)
if stringNode != nil {
tokens = append(tokens, stringNode.GetToken())
}

}
}
return tokens
}

func DocumentSymbol(ctx context.Context, doc document.ComposeDocument) (result []any, err error) {
file := doc.File()
if file == nil || len(file.Docs) == 0 {
Expand Down
Loading