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
13 changes: 5 additions & 8 deletions internal/compose/documentLink.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,15 @@ func createFileLink(u *url.URL, serviceNode *ast.MappingValueNode) *protocol.Doc
}

func stringNode(value ast.Node) *ast.StringNode {
if anchor, ok := value.(*ast.AnchorNode); ok {
value = anchor.Value
}
if s, ok := value.(*ast.StringNode); ok {
if s, ok := resolveAnchor(value).(*ast.StringNode); ok {
return s
}
return nil
}

func createDockerfileLink(u *url.URL, serviceNode *ast.MappingValueNode) *protocol.DocumentLink {
if serviceNode.Key.GetToken().Value == "build" {
if mappingNode, ok := serviceNode.Value.(*ast.MappingNode); ok {
if mappingNode, ok := resolveAnchor(serviceNode.Value).(*ast.MappingNode); ok {
for _, buildAttribute := range mappingNode.Values {
if buildAttribute.Key.GetToken().Value == "dockerfile" {
return createFileLink(u, buildAttribute)
Expand Down Expand Up @@ -153,7 +150,7 @@ func scanForLinks(u *url.URL, n *ast.MappingValueNode) []protocol.DocumentLink {
case "services":
if mappingNode, ok := n.Value.(*ast.MappingNode); ok {
for _, node := range mappingNode.Values {
if serviceAttributes, ok := node.Value.(*ast.MappingNode); ok {
if serviceAttributes, ok := resolveAnchor(node.Value).(*ast.MappingNode); ok {
for _, serviceAttribute := range serviceAttributes.Values {
link := createImageLink(serviceAttribute)
if link != nil {
Expand All @@ -171,7 +168,7 @@ func scanForLinks(u *url.URL, n *ast.MappingValueNode) []protocol.DocumentLink {
case "configs":
if mappingNode, ok := n.Value.(*ast.MappingNode); ok {
for _, node := range mappingNode.Values {
if configAttributes, ok := node.Value.(*ast.MappingNode); ok {
if configAttributes, ok := resolveAnchor(node.Value).(*ast.MappingNode); ok {
for _, configAttribute := range configAttributes.Values {
link := createObjectFileLink(u, configAttribute)
if link != nil {
Expand All @@ -184,7 +181,7 @@ func scanForLinks(u *url.URL, n *ast.MappingValueNode) []protocol.DocumentLink {
case "secrets":
if mappingNode, ok := n.Value.(*ast.MappingNode); ok {
for _, node := range mappingNode.Values {
if configAttributes, ok := node.Value.(*ast.MappingNode); ok {
if configAttributes, ok := resolveAnchor(node.Value).(*ast.MappingNode); ok {
for _, configAttribute := range configAttributes.Values {
link := createObjectFileLink(u, configAttribute)
if link != nil {
Expand Down
54 changes: 54 additions & 0 deletions internal/compose/documentLink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,23 @@ services:
},
},
},
{
name: "anchor on the service object",
content: `
services:
test: &anchor
image: alpine`,
links: []protocol.DocumentLink{
{
Range: protocol.Range{
Start: protocol.Position{Line: 3, Character: 11},
End: protocol.Position{Line: 3, Character: 17},
},
Target: types.CreateStringPointer("https://hub.docker.com/_/alpine"),
Tooltip: types.CreateStringPointer("https://hub.docker.com/_/alpine"),
},
},
},
{
name: "invalid services",
content: `
Expand Down Expand Up @@ -658,6 +675,19 @@ services:
End: protocol.Position{Line: 4, Character: 37},
},
},
{
name: "anchor on the build object",
content: `
services:
test:
build: &anchor
dockerfile: ./Dockerfile2`,
path: filepath.Join(testsFolder, "Dockerfile2"),
linkRange: protocol.Range{
Start: protocol.Position{Line: 4, Character: 18},
End: protocol.Position{Line: 4, Character: 31},
},
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -737,6 +767,18 @@ configs:
End: protocol.Position{Line: 3, Character: 34},
},
},
{
name: "anchor on the config object",
content: `
configs:
test: &anchor
file: ./httpd.conf`,
path: filepath.Join(testsFolder, "httpd.conf"),
linkRange: protocol.Range{
Start: protocol.Position{Line: 3, Character: 10},
End: protocol.Position{Line: 3, Character: 22},
},
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -816,6 +858,18 @@ secrets:
End: protocol.Position{Line: 3, Character: 35},
},
},
{
name: "anchor on the secret object",
content: `
secrets:
test: &anchor
file: ./server.cert`,
path: filepath.Join(testsFolder, "server.cert"),
linkRange: protocol.Range{
Start: protocol.Position{Line: 3, Character: 10},
End: protocol.Position{Line: 3, Character: 23},
},
},
}

for _, tc := range testCases {
Expand Down
Loading