Skip to content

Commit 254f478

Browse files
authored
Merge pull request #114 from docker/compose-hover-fix
Return hover results for Compose files
2 parents b7964ef + 91990cd commit 254f478

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to the Docker Language Server will be documented in this file.
44

5+
## [Unreleased]
6+
7+
### Fixed
8+
9+
- Compose
10+
- textDocument/hover
11+
- return the hover results for Compose files
12+
513
## [0.4.1] - 2025-04-29
614

715
### Fixed
@@ -174,7 +182,8 @@ All notable changes to the Docker Language Server will be documented in this fil
174182
- textDocument/semanticTokens/full
175183
- provide syntax highlighting for Bake files
176184

177-
[Unreleased]: https://github.com/docker/docker-language-server/compare/v0.4.0...main
185+
[Unreleased]: https://github.com/docker/docker-language-server/compare/v0.4.1...main
186+
[0.4.1]: https://github.com/docker/docker-language-server/compare/v0.4.0...v0.4.1
178187
[0.4.0]: https://github.com/docker/docker-language-server/compare/v0.3.8...v0.4.0
179188
[0.3.8]: https://github.com/docker/docker-language-server/compare/v0.3.7...v0.3.8
180189
[0.3.7]: https://github.com/docker/docker-language-server/compare/v0.3.6...v0.3.7

e2e-tests/hover_test.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,46 @@ func TestHover(t *testing.T) {
6161
name string
6262
content string
6363
position protocol.Position
64-
value string
64+
result *protocol.Hover
6565
}{
6666
{
6767
languageID: protocol.DockerBakeLanguage,
6868
fileExtensionSuffix: ".hcl",
6969
name: "hover over target block type",
7070
content: "target \"api\" {}",
7171
position: protocol.Position{Line: 0, Character: 3},
72-
value: "**target** _Block_\n\nA target reflects a single `docker build` invocation.",
72+
result: &protocol.Hover{
73+
Contents: protocol.MarkupContent{
74+
Kind: protocol.MarkupKindMarkdown,
75+
Value: "**target** _Block_\n\nA target reflects a single `docker build` invocation.",
76+
},
77+
},
7378
},
7479
{
7580
languageID: protocol.DockerfileLanguage,
7681
fileExtensionSuffix: "",
7782
name: "hover over alpine:3.16.1",
7883
content: "FROM alpine:3.16.1",
7984
position: protocol.Position{Line: 0, Character: 8},
80-
value: "Current image vulnerabilities: 1C 3H 9M 0L \r\n\r\nRecommended tags:\n\n<table>\n<tr><td><code>3.21.3</code></td><td align=\"right\"> 0C</td><td align=\"right\"> 0H</td><td align=\"right\"> 0M</td><td align=\"right\"> 0L</td><td align=\"right\"></td></tr>\n<tr><td><code>3.20.6</code></td><td align=\"right\"> 0C</td><td align=\"right\"> 0H</td><td align=\"right\"> 0M</td><td align=\"right\"> 0L</td><td align=\"right\"></td></tr>\n<tr><td><code>3.18.12</code></td><td align=\"right\"> 0C</td><td align=\"right\"> 0H</td><td align=\"right\"> 0M</td><td align=\"right\"> 0L</td><td align=\"right\"></td></tr>\n</table>\n",
85+
result: &protocol.Hover{
86+
Contents: protocol.MarkupContent{
87+
Kind: protocol.MarkupKindMarkdown,
88+
Value: "Current image vulnerabilities: 1C 3H 9M 0L \r\n\r\nRecommended tags:\n\n<table>\n<tr><td><code>3.21.3</code></td><td align=\"right\"> 0C</td><td align=\"right\"> 0H</td><td align=\"right\"> 0M</td><td align=\"right\"> 0L</td><td align=\"right\"></td></tr>\n<tr><td><code>3.20.6</code></td><td align=\"right\"> 0C</td><td align=\"right\"> 0H</td><td align=\"right\"> 0M</td><td align=\"right\"> 0L</td><td align=\"right\"></td></tr>\n<tr><td><code>3.18.12</code></td><td align=\"right\"> 0C</td><td align=\"right\"> 0H</td><td align=\"right\"> 0M</td><td align=\"right\"> 0L</td><td align=\"right\"></td></tr>\n</table>\n",
89+
},
90+
},
91+
},
92+
{
93+
languageID: protocol.DockerComposeLanguage,
94+
fileExtensionSuffix: ".yaml",
95+
name: "version description",
96+
content: "version: 1.2.3",
97+
position: protocol.Position{Line: 0, Character: 4},
98+
result: &protocol.Hover{
99+
Contents: protocol.MarkupContent{
100+
Kind: protocol.MarkupKindPlainText,
101+
Value: "declared for backward compatibility, ignored.",
102+
},
103+
},
81104
},
82105
}
83106

@@ -95,11 +118,7 @@ func TestHover(t *testing.T) {
95118
},
96119
}, &hover)
97120
require.NoError(t, err)
98-
require.Nil(t, hover.Range)
99-
markupContent, ok := hover.Contents.(protocol.MarkupContent)
100-
require.True(t, ok)
101-
require.Equal(t, protocol.MarkupKindMarkdown, markupContent.Kind)
102-
require.Equal(t, tc.value, markupContent.Value)
121+
require.Equal(t, tc.result, hover)
103122
})
104123
}
105124

internal/pkg/server/hover.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/docker/docker-language-server/internal/bake/hcl"
8+
"github.com/docker/docker-language-server/internal/compose"
89
"github.com/docker/docker-language-server/internal/pkg/document"
910
"github.com/docker/docker-language-server/internal/tliron/glsp"
1011
"github.com/docker/docker-language-server/internal/tliron/glsp/protocol"
@@ -21,7 +22,7 @@ func (s *Server) TextDocumentHover(ctx *glsp.Context, params *protocol.HoverPara
2122
if language == protocol.DockerBakeLanguage {
2223
return hcl.Hover(ctx.Context, params, doc.(document.BakeHCLDocument))
2324
} else if language == protocol.DockerComposeLanguage {
24-
return nil, nil
25+
return compose.Hover(ctx.Context, params, doc.(document.ComposeDocument))
2526
}
2627

2728
dockerfileDocument, ok := doc.(document.DockerfileDocument)

0 commit comments

Comments
 (0)