Skip to content

Commit 51b000d

Browse files
committed
Update goccy/go-yaml to 1.17.1
We originally started using 1.11.3 due to an oversight so should update to the latest version instead. Unfortunately, this does mean we can no longer support malformed YAML files with two identical keys. Signed-off-by: Remy Suen <[email protected]>
1 parent eb15743 commit 51b000d

File tree

6 files changed

+67
-125
lines changed

6 files changed

+67
-125
lines changed

go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/bep/debounce v1.2.1
77
github.com/docker/buildx v0.23.0
88
github.com/go-git/go-git/v5 v5.14.0
9-
github.com/goccy/go-yaml v1.11.3
9+
github.com/goccy/go-yaml v1.17.1
1010
github.com/hashicorp/hcl-lang v0.0.0-20250210193002-b2ec3be7c1b8
1111
github.com/hashicorp/hcl/v2 v2.23.0
1212
github.com/moby/buildkit v0.21.0
@@ -70,7 +70,6 @@ require (
7070
github.com/docker/go-metrics v0.0.1 // indirect
7171
github.com/docker/go-units v0.5.0 // indirect
7272
github.com/emirpasic/gods v1.18.1 // indirect
73-
github.com/fatih/color v1.16.0 // indirect
7473
github.com/felixge/httpsnoop v1.0.4 // indirect
7574
github.com/fvbommel/sortorder v1.0.1 // indirect
7675
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
@@ -98,7 +97,6 @@ require (
9897
github.com/kevinburke/ssh_config v1.2.0 // indirect
9998
github.com/klauspost/compress v1.18.0 // indirect
10099
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
101-
github.com/mattn/go-colorable v0.1.13 // indirect
102100
github.com/mattn/go-isatty v0.0.20 // indirect
103101
github.com/mattn/go-runewidth v0.0.15 // indirect
104102
github.com/mattn/go-shellwords v1.0.12 // indirect
@@ -167,7 +165,6 @@ require (
167165
golang.org/x/text v0.24.0 // indirect
168166
golang.org/x/time v0.11.0 // indirect
169167
golang.org/x/tools v0.32.0 // indirect
170-
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
171168
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38 // indirect
172169
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
173170
google.golang.org/grpc v1.69.4 // indirect

go.sum

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o
140140
github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE=
141141
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
142142
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
143-
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
144-
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
145143
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
146144
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
147145
github.com/fvbommel/sortorder v1.0.1 h1:dSnXLt4mJYH25uDDGa3biZNQsozaUWDSWeKJ0qqFfzE=
@@ -169,8 +167,8 @@ github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
169167
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
170168
github.com/go-viper/mapstructure/v2 v2.0.0 h1:dhn8MZ1gZ0mzeodTG3jt5Vj/o87xZKuNAprG2mQfMfc=
171169
github.com/go-viper/mapstructure/v2 v2.0.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
172-
github.com/goccy/go-yaml v1.11.3 h1:B3W9IdWbvrUu2OYQGwvU1nZtvMQJPBKgBUuweJjLj6I=
173-
github.com/goccy/go-yaml v1.11.3/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU=
170+
github.com/goccy/go-yaml v1.17.1 h1:LI34wktB2xEE3ONG/2Ar54+/HJVBriAGJ55PHls4YuY=
171+
github.com/goccy/go-yaml v1.17.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
174172
github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E=
175173
github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0=
176174
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@@ -245,9 +243,6 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
245243
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
246244
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
247245
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
248-
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
249-
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
250-
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
251246
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
252247
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
253248
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
@@ -486,7 +481,6 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
486481
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
487482
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
488483
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
489-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
490484
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
491485
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
492486
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
@@ -512,8 +506,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
512506
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
513507
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
514508
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
515-
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
516-
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
517509
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
518510
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38 h1:2oV8dfuIkM1Ti7DwXc0BJfnwr9csz4TDXI9EmiI+Rbw=
519511
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38/go.mod h1:vuAjtvlwkDKF6L1GQ0SokiRLCGFfeBUXWr/aFFkHACc=

internal/compose/documentLink.go

Lines changed: 59 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -40,70 +40,85 @@ func createIncludeLink(u *url.URL, node *token.Token) *protocol.DocumentLink {
4040
}
4141

4242
func createImageLinks(serviceNode *ast.MappingValueNode) *protocol.DocumentLink {
43-
if service, ok := serviceNode.Value.(*ast.MappingValueNode); ok {
44-
if service.Key.GetToken().Value == "image" {
45-
value := service.Value.GetToken().Value
46-
linkedText, link := extractImageLink(value)
47-
return &protocol.DocumentLink{
48-
Range: protocol.Range{
49-
Start: protocol.Position{
50-
Line: protocol.UInteger(service.Value.GetToken().Position.Line) - 1,
51-
Character: protocol.UInteger(service.Value.GetToken().Position.Column) - 1,
52-
},
53-
End: protocol.Position{
54-
Line: protocol.UInteger(service.Value.GetToken().Position.Line) - 1,
55-
Character: protocol.UInteger(service.Value.GetToken().Position.Column - 1 + len(linkedText)),
56-
},
43+
if serviceNode.Key.GetToken().Value == "image" {
44+
value := serviceNode.Value.GetToken().Value
45+
linkedText, link := extractImageLink(value)
46+
return &protocol.DocumentLink{
47+
Range: protocol.Range{
48+
Start: protocol.Position{
49+
Line: protocol.UInteger(serviceNode.Value.GetToken().Position.Line) - 1,
50+
Character: protocol.UInteger(serviceNode.Value.GetToken().Position.Column) - 1,
5751
},
58-
Target: types.CreateStringPointer(link),
59-
Tooltip: types.CreateStringPointer(link),
60-
}
52+
End: protocol.Position{
53+
Line: protocol.UInteger(serviceNode.Value.GetToken().Position.Line) - 1,
54+
Character: protocol.UInteger(serviceNode.Value.GetToken().Position.Column - 1 + len(linkedText)),
55+
},
56+
},
57+
Target: types.CreateStringPointer(link),
58+
Tooltip: types.CreateStringPointer(link),
6159
}
6260
}
6361
return nil
6462
}
6563

64+
func includedFiles(nodes []ast.Node) []*token.Token {
65+
tokens := []*token.Token{}
66+
for _, entry := range nodes {
67+
if mappingNode, ok := entry.(*ast.MappingNode); ok {
68+
for _, value := range mappingNode.Values {
69+
if value.Key.GetToken().Value == "path" {
70+
if paths, ok := value.Value.(*ast.SequenceNode); ok {
71+
// include:
72+
// - path:
73+
// - ../commons/compose.yaml
74+
// - ./commons-override.yaml
75+
for _, path := range paths.Values {
76+
tokens = append(tokens, path.GetToken())
77+
}
78+
} else {
79+
// include:
80+
// - path: ../commons/compose.yaml
81+
// project_directory: ..
82+
// env_file: ../another/.env
83+
tokens = append(tokens, value.Value.GetToken())
84+
}
85+
}
86+
}
87+
} else if stringNode, ok := entry.(*ast.StringNode); ok {
88+
// include:
89+
// - abc.yml
90+
// - def.yml
91+
tokens = append(tokens, stringNode.GetToken())
92+
}
93+
}
94+
return tokens
95+
}
96+
6697
func scanForLinks(u *url.URL, n *ast.MappingValueNode) []protocol.DocumentLink {
6798
if s, ok := n.Key.(*ast.StringNode); ok {
6899
links := []protocol.DocumentLink{}
69100
switch s.Value {
70101
case "include":
71102
if sequence, ok := n.Value.(*ast.SequenceNode); ok {
72-
for _, entry := range sequence.Values {
73-
if mappingNode, ok := entry.(*ast.MappingValueNode); ok {
74-
if mappingNode.Key.GetToken().Value != "path" {
75-
continue
76-
}
77-
entry = mappingNode.Value
78-
}
79-
if sequenceNode, ok := entry.(*ast.SequenceNode); ok {
80-
for _, entry := range sequenceNode.Values {
81-
link := createIncludeLink(u, entry.GetToken())
82-
if link != nil {
83-
links = append(links, *link)
84-
}
85-
}
86-
} else {
87-
link := createIncludeLink(u, entry.GetToken())
88-
if link != nil {
89-
links = append(links, *link)
90-
}
103+
for _, token := range includedFiles(sequence.Values) {
104+
link := createIncludeLink(u, token)
105+
if link != nil {
106+
links = append(links, *link)
91107
}
92108
}
93109
}
94110
case "services":
95111
if mappingNode, ok := n.Value.(*ast.MappingNode); ok {
96112
for _, node := range mappingNode.Values {
97-
link := createImageLinks(node)
98-
if link != nil {
99-
links = append(links, *link)
113+
if serviceAttributes, ok := node.Value.(*ast.MappingNode); ok {
114+
for _, serviceAttribute := range serviceAttributes.Values {
115+
link := createImageLinks(serviceAttribute)
116+
if link != nil {
117+
links = append(links, *link)
118+
}
119+
}
100120
}
101121
}
102-
} else if serviceNode, ok := n.Value.(*ast.MappingValueNode); ok {
103-
link := createImageLinks(serviceNode)
104-
if link != nil {
105-
links = append(links, *link)
106-
}
107122
}
108123
}
109124
return links

internal/compose/documentLink_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestDocumentLink_IncludedFiles(t *testing.T) {
3838
{
3939
name: "empty file",
4040
content: "",
41-
links: nil,
41+
links: []protocol.DocumentLink{},
4242
},
4343
{
4444
name: "included files, string array",
@@ -382,10 +382,10 @@ services:
382382
content: `
383383
services:
384384
- `,
385-
links: nil,
385+
links: []protocol.DocumentLink{},
386386
},
387387
{
388-
name: "image: alpine",
388+
name: "two documents",
389389
content: `
390390
---
391391
services:

internal/compose/documentSymbol.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,8 @@ func findSymbols(value string, n *ast.MappingValueNode, mapping map[string]proto
2828
}
2929
} else if value == "include" {
3030
if sequenceNode, ok := n.Value.(*ast.SequenceNode); ok {
31-
for _, include := range sequenceNode.Values {
32-
if _, ok := include.(*ast.StringNode); ok {
33-
// include:
34-
// - abc.yml
35-
// - def.yml
36-
result = append(result, createSymbol(include.GetToken(), protocol.SymbolKindModule))
37-
} else if includeNode, ok := include.(*ast.MappingValueNode); ok {
38-
if includeNode.Key.GetToken().Value == "path" {
39-
// include:
40-
// - path:
41-
// - ../commons/compose.yaml
42-
// - ./commons-override.yaml
43-
if included, ok := includeNode.Value.(*ast.SequenceNode); ok {
44-
for _, path := range included.Values {
45-
result = append(result, createSymbol(path.GetToken(), protocol.SymbolKindModule))
46-
}
47-
}
48-
}
49-
} else if includeNode, ok := include.(*ast.MappingNode); ok {
50-
// include:
51-
// - path: ../commons/compose.yaml
52-
// project_directory: ..
53-
// env_file: ../another/.env
54-
for _, attribute := range includeNode.Values {
55-
if attribute.Key.GetToken().Value == "path" {
56-
result = append(result, createSymbol(attribute.Value.GetToken(), protocol.SymbolKindModule))
57-
}
58-
}
59-
}
31+
for _, token := range includedFiles(sequenceNode.Values) {
32+
result = append(result, createSymbol(token, protocol.SymbolKindModule))
6033
}
6134
}
6235
}

internal/compose/documentSymbol_test.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -59,41 +59,6 @@ func TestDocumentSymbol(t *testing.T) {
5959
},
6060
},
6161
},
62-
{
63-
name: "duplicated services block",
64-
content: `services:
65-
web:
66-
build: .
67-
services:
68-
redis:
69-
image: "redis:alpine"`,
70-
symbols: []*protocol.DocumentSymbol{
71-
{
72-
Name: "web",
73-
Kind: protocol.SymbolKindClass,
74-
Range: protocol.Range{
75-
Start: protocol.Position{Line: 1, Character: 2},
76-
End: protocol.Position{Line: 1, Character: 5},
77-
},
78-
SelectionRange: protocol.Range{
79-
Start: protocol.Position{Line: 1, Character: 2},
80-
End: protocol.Position{Line: 1, Character: 5},
81-
},
82-
},
83-
{
84-
Name: "redis",
85-
Kind: protocol.SymbolKindClass,
86-
Range: protocol.Range{
87-
Start: protocol.Position{Line: 4, Character: 2},
88-
End: protocol.Position{Line: 4, Character: 7},
89-
},
90-
SelectionRange: protocol.Range{
91-
Start: protocol.Position{Line: 4, Character: 2},
92-
End: protocol.Position{Line: 4, Character: 7},
93-
},
94-
},
95-
},
96-
},
9762
{
9863
name: "services block with a piped scalar value",
9964
content: `services:

0 commit comments

Comments
 (0)