diff --git a/CHANGELOG.md b/CHANGELOG.md index d329752..2eafdbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ All notable changes to the Docker Language Server will be documented in this fil - Bake - textDocument/documentLink - convert links properly if a WSL URI with a dollar sign is used ([#378](https://github.com/docker/docker-language-server/issues/378)) + - textDocument/inlineCompletion + - convert links properly if a WSL URI with a dollar sign is used ([#384](https://github.com/docker/docker-language-server/issues/384)) ## [0.14.0] - 2025-07-16 diff --git a/internal/bake/hcl/inlineCompletion.go b/internal/bake/hcl/inlineCompletion.go index 309e9c6..b8487fc 100644 --- a/internal/bake/hcl/inlineCompletion.go +++ b/internal/bake/hcl/inlineCompletion.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "net/url" "slices" "strings" "unicode" @@ -47,7 +46,7 @@ func shouldSuggest(content []byte, body *hclsyntax.Body, position protocol.Posit } func InlineCompletion(ctx context.Context, params *protocol.InlineCompletionParams, manager *document.Manager, bakeDocument document.BakeHCLDocument) ([]protocol.InlineCompletionItem, error) { - url, err := url.Parse(params.TextDocument.URI) + documentPath, err := bakeDocument.DocumentPath() if err != nil { return nil, fmt.Errorf("LSP client sent invalid URI: %v", params.TextDocument.URI) } @@ -57,11 +56,7 @@ func InlineCompletion(ctx context.Context, params *protocol.InlineCompletionPara return nil, errors.New("unrecognized body in HCL document") } - dockerfilePath, err := types.LocalDockerfile(url) - if err != nil { - return nil, fmt.Errorf("invalid document path: %v", url.Path) - } - + documentURI, dockerfilePath := types.Concatenate(documentPath.Folder, "Dockerfile", documentPath.WSLDollarSignHost) if !shouldSuggest(bakeDocument.Input(), body, params.Position) { return nil, nil } @@ -90,7 +85,7 @@ func InlineCompletion(ctx context.Context, params *protocol.InlineCompletionPara argNames := []string{} args := map[string]string{} targets := []string{} - _, nodes := document.OpenDockerfile(ctx, manager, "", dockerfilePath) + _, nodes := document.OpenDockerfile(ctx, manager, documentURI, dockerfilePath) before := true for _, child := range nodes { if strings.EqualFold(child.Value, "ARG") && before { diff --git a/internal/bake/hcl/inlineCompletion_test.go b/internal/bake/hcl/inlineCompletion_test.go index f1e28cb..0010746 100644 --- a/internal/bake/hcl/inlineCompletion_test.go +++ b/internal/bake/hcl/inlineCompletion_test.go @@ -241,3 +241,47 @@ func TestInlineCompletion(t *testing.T) { }) } } +func TestInlineCompletion_WSL(t *testing.T) { + testCases := []struct { + name string + content string + dockerfileContent string + position protocol.Position + items []protocol.InlineCompletionItem + }{ + { + name: "one build stage", + content: "", + dockerfileContent: "FROM scratch AS simple", + position: protocol.Position{Line: 0, Character: 0}, + items: []protocol.InlineCompletionItem{ + { + InsertText: "target \"simple\" {\n target = \"simple\"\n}\n", + Range: &protocol.Range{ + Start: protocol.Position{Line: 0, Character: 0}, + End: protocol.Position{Line: 0, Character: 0}, + }, + }, + }, + }, + } + + bakeURI := "file://wsl%24/docker-desktop/tmp/docker-bake.hcl" + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + manager := document.NewDocumentManager() + changed, err := manager.Write(context.Background(), "file://wsl%24/docker-desktop/tmp/Dockerfile", protocol.DockerfileLanguage, 1, []byte(tc.dockerfileContent)) + require.NoError(t, err) + require.True(t, changed) + doc := document.NewBakeHCLDocument(uri.URI(bakeURI), 1, []byte(tc.content)) + items, err := InlineCompletion(context.Background(), &protocol.InlineCompletionParams{ + TextDocumentPositionParams: protocol.TextDocumentPositionParams{ + TextDocument: protocol.TextDocumentIdentifier{URI: bakeURI}, + Position: tc.position, + }, + }, manager, doc) + require.NoError(t, err) + require.Equal(t, tc.items, items) + }) + } +}