From c971c7f8a88d11f2b692a1bcd4d17b9b0c1a11d2 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 16 Aug 2025 23:41:12 +0300 Subject: fix(lsp): avoid duplicate assignment prefix in completions - Prompt: instruct model to only continue from cursor; do not repeat LHS already typed.\n- Add stripDuplicateAssignmentPrefix to drop duplicated 'name :=' or 'name =' when model repeats it.\n- Tests: cover := and = cases.\n- .gitignore: ignore built binary and go caches. --- internal/lsp/handlers_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'internal/lsp/handlers_test.go') diff --git a/internal/lsp/handlers_test.go b/internal/lsp/handlers_test.go index 0b12611..1b5080a 100644 --- a/internal/lsp/handlers_test.go +++ b/internal/lsp/handlers_test.go @@ -238,3 +238,19 @@ func TestInstructionFromSelection_HTMLAndLineComments(t *testing.T) { t.Fatalf("cleaned should remove html comment markers") } } + +func TestStripDuplicateAssignmentPrefix(t *testing.T) { + prefix := "matrix := " + sug := "matrix := NewMatrix(2,2)" + got := stripDuplicateAssignmentPrefix(prefix, sug) + if got != "NewMatrix(2,2)" { + t.Fatalf("dup strip failed: got %q", got) + } + // '=' variant + prefix2 := "x = " + sug2 := "x = y + 1" + got2 := stripDuplicateAssignmentPrefix(prefix2, sug2) + if got2 != "y + 1" { + t.Fatalf("dup strip '=' failed: got %q", got2) + } +} -- cgit v1.2.3