diff --git a/CHANGELOG.md b/CHANGELOG.md index 6801053..b08a0b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/internal/compose/documentLink.go b/internal/compose/documentLink.go index 4e7e325..b1e7784 100644 --- a/internal/compose/documentLink.go +++ b/internal/compose/documentLink.go @@ -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 { @@ -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()) + } } } } @@ -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) diff --git a/internal/compose/documentLink_test.go b/internal/compose/documentLink_test.go index f58a886..e6842aa 100644 --- a/internal/compose/documentLink_test.go +++ b/internal/compose/documentLink_test.go @@ -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 { diff --git a/internal/compose/documentSymbol.go b/internal/compose/documentSymbol.go index 57de22b..54d8328 100644 --- a/internal/compose/documentSymbol.go +++ b/internal/compose/documentSymbol.go @@ -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 {