Skip to content

Commit c80d677

Browse files
authored
Merge pull request #206 from docker/crlf-compose-hover-fix
Ensure hover results are returned for files with CRLFs
2 parents fe7cea3 + df63340 commit c80d677

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ All notable changes to the Docker Language Server will be documented in this fil
2626
- Compose
2727
- textDocument/completion
2828
- fix panic in code completion in an empty file ([#196](https://github.com/docker/docker-language-server/issues/196))
29+
- textDocument/hover
30+
- ensure results are returned even if the file has CRLFs ([#205](https://github.com/docker/docker-language-server/issues/205))
2931
- Bake
3032
- textDocument/publishDiagnostics
3133
- stop flagging `BUILDKIT_SYNTAX` as an unrecognized `ARG` ([#187](https://github.com/docker/docker-language-server/issues/187))

internal/compose/hover_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,45 @@ services:
451451
},
452452
},
453453
},
454+
{
455+
name: "container_name attribute on services",
456+
content: `
457+
services:
458+
test:
459+
container_name: abc`,
460+
line: 3,
461+
character: 7,
462+
result: &protocol.Hover{
463+
Contents: protocol.MarkupContent{
464+
Kind: protocol.MarkupKindMarkdown,
465+
Value: "Specify a custom container name, rather than a generated default name.\n\nSchema: [compose-spec.json](https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json)\n\n[Online documentation](https://docs.docker.com/reference/compose-file/services/#container_name)",
466+
},
467+
},
468+
},
469+
{
470+
name: "container_name attribute with a comment before it",
471+
content: "services:\n test:\n#\n container_name: abc",
472+
line: 3,
473+
character: 7,
474+
result: &protocol.Hover{
475+
Contents: protocol.MarkupContent{
476+
Kind: protocol.MarkupKindMarkdown,
477+
Value: "Specify a custom container name, rather than a generated default name.\n\nSchema: [compose-spec.json](https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json)\n\n[Online documentation](https://docs.docker.com/reference/compose-file/services/#container_name)",
478+
},
479+
},
480+
},
481+
{
482+
name: "container_name attribute with a comment before it (CRLF)",
483+
content: "services:\r\n test:\r\n#\r\n container_name: abc",
484+
line: 3,
485+
character: 7,
486+
result: &protocol.Hover{
487+
Contents: protocol.MarkupContent{
488+
Kind: protocol.MarkupKindMarkdown,
489+
Value: "Specify a custom container name, rather than a generated default name.\n\nSchema: [compose-spec.json](https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json)\n\n[Online documentation](https://docs.docker.com/reference/compose-file/services/#container_name)",
490+
},
491+
},
492+
},
454493
}
455494

456495
temporaryBakeFile := fmt.Sprintf("file:///%v", strings.TrimPrefix(filepath.ToSlash(filepath.Join(os.TempDir(), "compose.yaml")), "/"))

internal/pkg/document/dockerComposeDocument.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ func NewComposeDocument(mgr *Manager, u uri.URI, version int32, input []byte) Co
3737
uri: u,
3838
identifier: protocol.DockerComposeLanguage,
3939
version: version,
40-
input: input,
40+
// change all CRLF to LFs
41+
// https://github.com/goccy/go-yaml/issues/560
42+
// https://github.com/docker/docker-language-server/issues/205
43+
input: []byte(strings.Replace(string(input), "\r\n", "\n", -1)),
4144
},
4245
mgr: mgr,
4346
}

0 commit comments

Comments
 (0)