Skip to content

Commit f33bbc4

Browse files
authored
Merge pull request #455 from docker/compose-service-refs-volumes-from
Support searching for service references in volumes_from
2 parents f0a7498 + a4dca57 commit f33bbc4

File tree

3 files changed

+346
-1
lines changed

3 files changed

+346
-1
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ All notable changes to the Docker Language Server will be documented in this fil
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Compose
10+
- textDocument/definition
11+
- support jumping to service references in the `volumes_from` attribute of a service object ([#452](https://github.com/docker/docker-language-server/issues/452))
12+
- textDocument/documentHighlight
13+
- support highlighting service references in the `volumes_from` attribute of a service object ([#452](https://github.com/docker/docker-language-server/issues/452))
14+
- textDocument/prepareRename
15+
- support preparing renames for services in the `volumes_from` attribute of a service object ([#452](https://github.com/docker/docker-language-server/issues/452))
16+
- textDocument/rename
17+
- support renaming service referencesin the `volumes_from` attribute of a service object ([#452](https://github.com/docker/docker-language-server/issues/452))
18+
719
### Fixed
820

921
- Compose

internal/compose/documentHighlight.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ func extendedServiceReferences(servicesNode *ast.MappingNode) []*token.Token {
4545
for _, serviceNode := range servicesNode.Values {
4646
if serviceAttributes, ok := resolveAnchor(serviceNode.Value).(*ast.MappingNode); ok {
4747
for _, attributeNode := range serviceAttributes.Values {
48-
if resolveAnchor(attributeNode.Key).GetToken().Value == "extends" {
48+
switch resolveAnchor(attributeNode.Key).GetToken().Value {
49+
case "extends":
4950
attributeNodeValue := resolveAnchor(attributeNode.Value)
5051
if extendedValue, ok := attributeNodeValue.(*ast.StringNode); ok {
5152
tokens = append(tokens, extendedValue.GetToken())
@@ -66,6 +67,22 @@ func extendedServiceReferences(servicesNode *ast.MappingNode) []*token.Token {
6667
}
6768
}
6869
}
70+
case "volumes_from":
71+
if sequenceNode, ok := resolveAnchor(attributeNode.Value).(*ast.SequenceNode); ok {
72+
for _, volume := range sequenceNode.Values {
73+
volumeToken := resolveAnchor(volume).GetToken()
74+
split := strings.Split(volumeToken.Value, ":")
75+
if len(split) == 1 {
76+
tokens = append(tokens, volumeToken)
77+
} else if len(split[0]) > 0 && split[0] != "container" {
78+
tokens = append(tokens, &token.Token{
79+
Type: volumeToken.Type,
80+
Value: split[0],
81+
Position: volumeToken.Position,
82+
})
83+
}
84+
}
85+
}
6986
}
7087
}
7188
}

internal/compose/documentHighlight_test.go

Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,322 @@ services:
18031803
End: protocol.Position{Line: 6, Character: 8},
18041804
},
18051805
},
1806+
{
1807+
name: "undefined read highlight on a volumes_from array item",
1808+
content: `
1809+
services:
1810+
test:
1811+
volumes_from:
1812+
- server`,
1813+
line: 4,
1814+
character: 10,
1815+
locations: func(u protocol.DocumentUri) any { return nil },
1816+
links: func(u protocol.DocumentUri) any { return nil },
1817+
ranges: []protocol.DocumentHighlight{
1818+
documentHighlight(4, 8, 4, 14, protocol.DocumentHighlightKindRead),
1819+
},
1820+
renameEdits: func(u protocol.DocumentUri) *protocol.WorkspaceEdit {
1821+
return &protocol.WorkspaceEdit{
1822+
Changes: map[protocol.DocumentUri][]protocol.TextEdit{
1823+
u: {
1824+
{
1825+
NewText: "newName",
1826+
Range: protocol.Range{
1827+
Start: protocol.Position{Line: 4, Character: 8},
1828+
End: protocol.Position{Line: 4, Character: 14},
1829+
},
1830+
},
1831+
},
1832+
},
1833+
}
1834+
},
1835+
prepareRename: &protocol.Range{
1836+
Start: protocol.Position{Line: 4, Character: 8},
1837+
End: protocol.Position{Line: 4, Character: 14},
1838+
},
1839+
},
1840+
{
1841+
name: "undefined read highlight on a volumes_from array item (volumes_from attribute key is anchored)",
1842+
content: `
1843+
services:
1844+
test:
1845+
&anchor volumes_from:
1846+
- server`,
1847+
line: 4,
1848+
character: 10,
1849+
locations: func(u protocol.DocumentUri) any { return nil },
1850+
links: func(u protocol.DocumentUri) any { return nil },
1851+
ranges: []protocol.DocumentHighlight{
1852+
documentHighlight(4, 8, 4, 14, protocol.DocumentHighlightKindRead),
1853+
},
1854+
renameEdits: func(u protocol.DocumentUri) *protocol.WorkspaceEdit {
1855+
return &protocol.WorkspaceEdit{
1856+
Changes: map[protocol.DocumentUri][]protocol.TextEdit{
1857+
u: {
1858+
{
1859+
NewText: "newName",
1860+
Range: protocol.Range{
1861+
Start: protocol.Position{Line: 4, Character: 8},
1862+
End: protocol.Position{Line: 4, Character: 14},
1863+
},
1864+
},
1865+
},
1866+
},
1867+
}
1868+
},
1869+
prepareRename: &protocol.Range{
1870+
Start: protocol.Position{Line: 4, Character: 8},
1871+
End: protocol.Position{Line: 4, Character: 14},
1872+
},
1873+
},
1874+
{
1875+
name: "undefined read highlight on a volumes_from array item (volumes_from attribute value is anchored)",
1876+
content: `
1877+
services:
1878+
test:
1879+
volumes_from: &anchor
1880+
- server`,
1881+
line: 4,
1882+
character: 10,
1883+
locations: func(u protocol.DocumentUri) any { return nil },
1884+
links: func(u protocol.DocumentUri) any { return nil },
1885+
ranges: []protocol.DocumentHighlight{
1886+
documentHighlight(4, 8, 4, 14, protocol.DocumentHighlightKindRead),
1887+
},
1888+
renameEdits: func(u protocol.DocumentUri) *protocol.WorkspaceEdit {
1889+
return &protocol.WorkspaceEdit{
1890+
Changes: map[protocol.DocumentUri][]protocol.TextEdit{
1891+
u: {
1892+
{
1893+
NewText: "newName",
1894+
Range: protocol.Range{
1895+
Start: protocol.Position{Line: 4, Character: 8},
1896+
End: protocol.Position{Line: 4, Character: 14},
1897+
},
1898+
},
1899+
},
1900+
},
1901+
}
1902+
},
1903+
prepareRename: &protocol.Range{
1904+
Start: protocol.Position{Line: 4, Character: 8},
1905+
End: protocol.Position{Line: 4, Character: 14},
1906+
},
1907+
},
1908+
{
1909+
name: "undefined read highlight on a volumes_from array item (array item is anchored)",
1910+
content: `
1911+
services:
1912+
test:
1913+
volumes_from:
1914+
- &anchor server`,
1915+
line: 4,
1916+
character: 18,
1917+
locations: func(u protocol.DocumentUri) any { return nil },
1918+
links: func(u protocol.DocumentUri) any { return nil },
1919+
ranges: []protocol.DocumentHighlight{
1920+
documentHighlight(4, 16, 4, 22, protocol.DocumentHighlightKindRead),
1921+
},
1922+
renameEdits: func(u protocol.DocumentUri) *protocol.WorkspaceEdit {
1923+
return &protocol.WorkspaceEdit{
1924+
Changes: map[protocol.DocumentUri][]protocol.TextEdit{
1925+
u: {
1926+
{
1927+
NewText: "newName",
1928+
Range: protocol.Range{
1929+
Start: protocol.Position{Line: 4, Character: 16},
1930+
End: protocol.Position{Line: 4, Character: 22},
1931+
},
1932+
},
1933+
},
1934+
},
1935+
}
1936+
},
1937+
prepareRename: &protocol.Range{
1938+
Start: protocol.Position{Line: 4, Character: 16},
1939+
End: protocol.Position{Line: 4, Character: 22},
1940+
},
1941+
},
1942+
{
1943+
name: "undefined read highlight on a volumes_from array item with a :ro suffix",
1944+
content: `
1945+
services:
1946+
test:
1947+
volumes_from:
1948+
- server:ro`,
1949+
line: 4,
1950+
character: 10,
1951+
locations: func(u protocol.DocumentUri) any { return nil },
1952+
links: func(u protocol.DocumentUri) any { return nil },
1953+
ranges: []protocol.DocumentHighlight{
1954+
documentHighlight(4, 8, 4, 14, protocol.DocumentHighlightKindRead),
1955+
},
1956+
renameEdits: func(u protocol.DocumentUri) *protocol.WorkspaceEdit {
1957+
return &protocol.WorkspaceEdit{
1958+
Changes: map[protocol.DocumentUri][]protocol.TextEdit{
1959+
u: {
1960+
{
1961+
NewText: "newName",
1962+
Range: protocol.Range{
1963+
Start: protocol.Position{Line: 4, Character: 8},
1964+
End: protocol.Position{Line: 4, Character: 14},
1965+
},
1966+
},
1967+
},
1968+
},
1969+
}
1970+
},
1971+
prepareRename: &protocol.Range{
1972+
Start: protocol.Position{Line: 4, Character: 8},
1973+
End: protocol.Position{Line: 4, Character: 14},
1974+
},
1975+
},
1976+
{
1977+
name: "read highlight on a volumes_from array item pointing to a service",
1978+
content: `
1979+
services:
1980+
test:
1981+
volumes_from:
1982+
- server
1983+
server:`,
1984+
line: 4,
1985+
character: 10,
1986+
locations: func(u protocol.DocumentUri) any {
1987+
return types.CreateDefinitionResult(false, protocol.Range{
1988+
Start: protocol.Position{Line: 5, Character: 2},
1989+
End: protocol.Position{Line: 5, Character: 8},
1990+
}, nil, u)
1991+
},
1992+
links: func(u protocol.DocumentUri) any {
1993+
return types.CreateDefinitionResult(true, protocol.Range{
1994+
Start: protocol.Position{Line: 5, Character: 2},
1995+
End: protocol.Position{Line: 5, Character: 8},
1996+
}, &protocol.Range{
1997+
Start: protocol.Position{Line: 4, Character: 8},
1998+
End: protocol.Position{Line: 4, Character: 14},
1999+
}, u)
2000+
},
2001+
ranges: []protocol.DocumentHighlight{
2002+
documentHighlight(4, 8, 4, 14, protocol.DocumentHighlightKindRead),
2003+
documentHighlight(5, 2, 5, 8, protocol.DocumentHighlightKindWrite),
2004+
},
2005+
renameEdits: func(u protocol.DocumentUri) *protocol.WorkspaceEdit {
2006+
return &protocol.WorkspaceEdit{
2007+
Changes: map[protocol.DocumentUri][]protocol.TextEdit{
2008+
u: {
2009+
{
2010+
NewText: "newName",
2011+
Range: protocol.Range{
2012+
Start: protocol.Position{Line: 4, Character: 8},
2013+
End: protocol.Position{Line: 4, Character: 14},
2014+
},
2015+
},
2016+
{
2017+
NewText: "newName",
2018+
Range: protocol.Range{
2019+
Start: protocol.Position{Line: 5, Character: 2},
2020+
End: protocol.Position{Line: 5, Character: 8},
2021+
},
2022+
},
2023+
},
2024+
},
2025+
}
2026+
},
2027+
prepareRename: &protocol.Range{
2028+
Start: protocol.Position{Line: 4, Character: 8},
2029+
End: protocol.Position{Line: 4, Character: 14},
2030+
},
2031+
},
2032+
{
2033+
name: "write highlight on a volumes_from array item pointing to a service",
2034+
content: `
2035+
services:
2036+
test:
2037+
volumes_from:
2038+
- server
2039+
server:`,
2040+
line: 5,
2041+
character: 5,
2042+
locations: func(u protocol.DocumentUri) any {
2043+
return types.CreateDefinitionResult(false, protocol.Range{
2044+
Start: protocol.Position{Line: 5, Character: 2},
2045+
End: protocol.Position{Line: 5, Character: 8},
2046+
}, nil, u)
2047+
},
2048+
links: func(u protocol.DocumentUri) any {
2049+
return types.CreateDefinitionResult(true, protocol.Range{
2050+
Start: protocol.Position{Line: 5, Character: 2},
2051+
End: protocol.Position{Line: 5, Character: 8},
2052+
}, &protocol.Range{
2053+
Start: protocol.Position{Line: 5, Character: 2},
2054+
End: protocol.Position{Line: 5, Character: 8},
2055+
}, u)
2056+
},
2057+
ranges: []protocol.DocumentHighlight{
2058+
documentHighlight(4, 8, 4, 14, protocol.DocumentHighlightKindRead),
2059+
documentHighlight(5, 2, 5, 8, protocol.DocumentHighlightKindWrite),
2060+
},
2061+
renameEdits: func(u protocol.DocumentUri) *protocol.WorkspaceEdit {
2062+
return &protocol.WorkspaceEdit{
2063+
Changes: map[protocol.DocumentUri][]protocol.TextEdit{
2064+
u: {
2065+
{
2066+
NewText: "newName",
2067+
Range: protocol.Range{
2068+
Start: protocol.Position{Line: 4, Character: 8},
2069+
End: protocol.Position{Line: 4, Character: 14},
2070+
},
2071+
},
2072+
{
2073+
NewText: "newName",
2074+
Range: protocol.Range{
2075+
Start: protocol.Position{Line: 5, Character: 2},
2076+
End: protocol.Position{Line: 5, Character: 8},
2077+
},
2078+
},
2079+
},
2080+
},
2081+
}
2082+
},
2083+
prepareRename: &protocol.Range{
2084+
Start: protocol.Position{Line: 5, Character: 2},
2085+
End: protocol.Position{Line: 5, Character: 8},
2086+
},
2087+
},
2088+
{
2089+
name: "undefined read highlight on a volumes_from with no service just :ro",
2090+
content: `
2091+
services:
2092+
test:
2093+
volumes_from:
2094+
- :ro`,
2095+
line: 4,
2096+
character: 8,
2097+
locations: func(u protocol.DocumentUri) any { return nil },
2098+
links: func(u protocol.DocumentUri) any { return nil },
2099+
ranges: nil,
2100+
renameEdits: func(u protocol.DocumentUri) *protocol.WorkspaceEdit {
2101+
return nil
2102+
},
2103+
prepareRename: nil,
2104+
},
2105+
{
2106+
name: "undefined read highlight on a volumes_from array item pointing to a container",
2107+
content: `
2108+
services:
2109+
test:
2110+
volumes_from:
2111+
- container:ro`,
2112+
line: 4,
2113+
character: 10,
2114+
locations: func(u protocol.DocumentUri) any { return nil },
2115+
links: func(u protocol.DocumentUri) any { return nil },
2116+
ranges: nil,
2117+
renameEdits: func(u protocol.DocumentUri) *protocol.WorkspaceEdit {
2118+
return nil
2119+
},
2120+
prepareRename: nil,
2121+
},
18062122
{
18072123
name: "invalid services value",
18082124
content: `

0 commit comments

Comments
 (0)