Skip to content

Commit 010a5d4

Browse files
authored
Merge pull request #463 from docker/long-form-volume-file-bind-mount-link-support
Show links for long-form volume objects that are bind mounts
2 parents aaa51f0 + 5784d7b commit 010a5d4

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to the Docker Language Server will be documented in this fil
99
- Compose
1010
- textDocument/documentLink
1111
- return document links for files referenced in the short-form `volumes` attribute of a service object ([#460](https://github.com/docker/docker-language-server/issues/460))
12+
- return document links for files referenced in the long-form `volumes` attribute of a service object that has a bind mount ([#462](https://github.com/docker/docker-language-server/issues/462))
1213

1314
## [0.18.0] - 2025-08-25
1415

internal/compose/documentLink.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,32 @@ func createVolumeFileLinks(folderAbsolutePath string, wslDollarSign bool, servic
127127
})
128128
}
129129
}
130+
} else if m, ok := resolveAnchor(node).(*ast.MappingNode); ok {
131+
bindType := false
132+
for _, value := range m.Values {
133+
if resolveAnchor(value.Key).GetToken().Value == "type" && resolveAnchor(value.Value).GetToken().Value == "bind" {
134+
bindType = true
135+
break
136+
}
137+
}
138+
139+
if bindType {
140+
for _, value := range m.Values {
141+
if resolveAnchor(value.Key).GetToken().Value == "source" {
142+
sourceToken := resolveAnchor(value.Value).GetToken()
143+
uri, path := createLocalFileLink(folderAbsolutePath, sourceToken.Value, wslDollarSign)
144+
info, err := os.Stat(path)
145+
if err == nil && !info.IsDir() {
146+
links = append(links, protocol.DocumentLink{
147+
Range: createRange(sourceToken, len(sourceToken.Value)),
148+
Target: types.CreateStringPointer(uri),
149+
Tooltip: types.CreateStringPointer(path),
150+
})
151+
}
152+
break
153+
}
154+
}
155+
}
130156
}
131157
}
132158
return links

internal/compose/documentLink_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,91 @@ services:
21252125
End: protocol.Position{Line: 4, Character: protocol.UInteger(8 + len(tempFile))},
21262126
},
21272127
},
2128+
{
2129+
name: "mount local file with a complex volume object",
2130+
content: `
2131+
services:
2132+
test:
2133+
volumes:
2134+
- type: bind
2135+
source: ./a.txt
2136+
target: /mnt/a.txt`,
2137+
path: filepath.Join(testsFolder, "./a.txt"),
2138+
linkRange: protocol.Range{
2139+
Start: protocol.Position{Line: 5, Character: 16},
2140+
End: protocol.Position{Line: 5, Character: 23},
2141+
},
2142+
},
2143+
{
2144+
name: "mount local file with a complex volume object with the type's attribute name anchored",
2145+
content: `
2146+
services:
2147+
test:
2148+
volumes:
2149+
- &anchor type: bind
2150+
source: ./a.txt
2151+
target: /mnt/a.txt`,
2152+
path: filepath.Join(testsFolder, "./a.txt"),
2153+
linkRange: protocol.Range{
2154+
Start: protocol.Position{Line: 5, Character: 16},
2155+
End: protocol.Position{Line: 5, Character: 23},
2156+
},
2157+
},
2158+
{
2159+
name: "mount local file with a complex volume object with the type's attribute value anchored",
2160+
content: `
2161+
services:
2162+
test:
2163+
volumes:
2164+
- type: &anchor bind
2165+
source: ./a.txt
2166+
target: /mnt/a.txt`,
2167+
path: filepath.Join(testsFolder, "./a.txt"),
2168+
linkRange: protocol.Range{
2169+
Start: protocol.Position{Line: 5, Character: 16},
2170+
End: protocol.Position{Line: 5, Character: 23},
2171+
},
2172+
},
2173+
{
2174+
name: "mount local file with a complex volume object with the source's attribute name anchored",
2175+
content: `
2176+
services:
2177+
test:
2178+
volumes:
2179+
- type: bind
2180+
&anchor source: ./a.txt
2181+
target: /mnt/a.txt`,
2182+
path: filepath.Join(testsFolder, "./a.txt"),
2183+
linkRange: protocol.Range{
2184+
Start: protocol.Position{Line: 5, Character: 24},
2185+
End: protocol.Position{Line: 5, Character: 31},
2186+
},
2187+
},
2188+
{
2189+
name: "mount local file with a complex volume object with the source's attribute value anchored",
2190+
content: `
2191+
services:
2192+
test:
2193+
volumes:
2194+
- type: bind
2195+
source: &anchor ./a.txt
2196+
target: /mnt/a.txt`,
2197+
path: filepath.Join(testsFolder, "./a.txt"),
2198+
linkRange: protocol.Range{
2199+
Start: protocol.Position{Line: 5, Character: 24},
2200+
End: protocol.Position{Line: 5, Character: 31},
2201+
},
2202+
},
2203+
{
2204+
name: "mount local folder with a complex volume object",
2205+
content: `
2206+
services:
2207+
test:
2208+
volumes:
2209+
- type: bind
2210+
source: ./folder
2211+
target: /mount/folder`,
2212+
},
21282213
}
21292214

21302215
for _, tc := range testCases {

0 commit comments

Comments
 (0)