From e5c80a793d416edbfa6e7e457f29cf249b654b11 Mon Sep 17 00:00:00 2001 From: Remy Suen Date: Fri, 21 Nov 2025 03:56:59 +0000 Subject: [PATCH] Ignore empty prefixes when processing image tag completions Signed-off-by: Remy Suen --- CHANGELOG.md | 3 +++ internal/compose/completion.go | 2 +- internal/compose/completion_test.go | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8f4aef..3d18067 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ All notable changes to the Docker Language Server will be documented in this fil ### Fixed +- Compose + - textDocument/completion + - check the prefix string before trying to use it for looking up image tags ([#486](https://github.com/docker/docker-language-server/issues/486)) - Bake - fix parsing error caused by referencing a variable with no value ([#490](https://github.com/docker/docker-language-server/issues/490)) diff --git a/internal/compose/completion.go b/internal/compose/completion.go index fb520c9..610fcfe 100644 --- a/internal/compose/completion.go +++ b/internal/compose/completion.go @@ -582,7 +582,7 @@ func buildTargetCompletionItems(params *protocol.CompletionParams, manager *docu } func serviceImageCompletionItems(hub hub.Service, path []*ast.MappingValueNode, prefix string) ([]protocol.CompletionItem, bool) { - if len(path) == 3 && path[0].Key.GetToken().Value == "services" && path[2].Key.GetToken().Value == "image" { + if len(path) == 3 && path[0].Key.GetToken().Value == "services" && path[2].Key.GetToken().Value == "image" && len(prefix) > 0 { if path[2].Value.GetToken().Type == token.DoubleQuoteType || path[2].Value.GetToken().Type == token.SingleQuoteType { prefix = prefix[1:] } diff --git a/internal/compose/completion_test.go b/internal/compose/completion_test.go index 6383370..5c46170 100644 --- a/internal/compose/completion_test.go +++ b/internal/compose/completion_test.go @@ -5509,6 +5509,26 @@ services: character: 15, list: nil, }, + { + name: "single quoted completion with whitespace preceding the character position", + content: ` +services: + test: + image: ' '`, + line: 3, + character: 13, + list: nil, + }, + { + name: "double quoted completion with whitespace preceding the character position", + content: ` +services: + test: + image: " "`, + line: 3, + character: 13, + list: nil, + }, } dir := createFileStructure(t)