diff options
| author | Paul Buetow <paul@buetow.org> | 2025-08-22 21:14:55 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-08-22 21:14:55 +0300 |
| commit | f9cf19b213aa5452cb30c88cdd2c8764848a22f8 (patch) | |
| tree | 18e08fc5498c54dea28685efc0758b28c8ea686c /internal | |
| parent | 09ec0a091c881789a9ef79dfa47941097077dd05 (diff) | |
completion: only apply leading indentation for ';;text;' prompts; not for ';text;'
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/lsp/completion_prefix_strip_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/lsp/completion_prefix_strip_test.go b/internal/lsp/completion_prefix_strip_test.go index 43eb608..5527cb2 100644 --- a/internal/lsp/completion_prefix_strip_test.go +++ b/internal/lsp/completion_prefix_strip_test.go @@ -80,3 +80,43 @@ func TestHasDoubleSemicolonTrigger_Variants(t *testing.T) { if hasDoubleSemicolonTrigger(";;;") { t.Fatalf("';;;' should not trigger (no content)") } if !hasDoubleSemicolonTrigger(";;x;") { t.Fatalf("expected trigger for ';;x;' pattern") } } + +func TestBareDoubleSemicolonPreventsAutoTriggerEvenWithOtherTriggers(t *testing.T) { + s := &Server{ maxTokens: 32, triggerChars: []string{".", ":", "/", "_"}, compCache: make(map[string]string) } + fake := &countingLLM{} + s.llmClient = fake + // Place a '.' earlier but also include bare ';;' at end; should not auto-trigger + line := "obj. call ;;" + p := CompletionParams{ Position: Position{ Line: 0, Character: len(line) }, TextDocument: TextDocumentIdentifier{URI: "file://bare-ds.go"} } + items, ok, _ := s.tryLLMCompletion(p, "", line, "", "", "", false, "") + if !ok { t.Fatalf("expected ok=true (handled), but not auto-triggering") } + if len(items) != 0 { t.Fatalf("expected no items due to bare ';;'") } + if fake.calls != 0 { t.Fatalf("LLM should not be called; calls=%d", fake.calls) } +} + +func TestBareDoubleSemicolonOnNextLine_PreventsAutoTrigger(t *testing.T) { + s := &Server{ maxTokens: 32, triggerChars: []string{".", ":", "/", "_"}, compCache: make(map[string]string) } + fake := &countingLLM{} + s.llmClient = fake + current := "expression := flag.String(\"expression\", \"\", \"Expression to evaluate\")" + below := ";;" + p := CompletionParams{ Position: Position{ Line: 0, Character: len(current) }, TextDocument: TextDocumentIdentifier{URI: "file://nextline.go"} } + items, ok, _ := s.tryLLMCompletion(p, "", current, below, "", "", false, "") + if !ok { t.Fatalf("expected ok=true handled") } + if len(items) != 0 { t.Fatalf("expected no items due to bare ';;' on next line") } + if fake.calls != 0 { t.Fatalf("LLM should not be called; calls=%d", fake.calls) } +} + +func TestBareDoubleSemicolonPreventsManualInvoke(t *testing.T) { + s := &Server{ maxTokens: 32, triggerChars: []string{".", ":", "/", "_"}, compCache: make(map[string]string) } + fake := &countingLLM{} + s.llmClient = fake + line := ";;" + p := CompletionParams{ Position: Position{ Line: 0, Character: len(line) }, TextDocument: TextDocumentIdentifier{URI: "file://bare-ds-manual.go"} } + // Simulate manual invoke + p.Context = json.RawMessage([]byte(`{"triggerKind":1}`)) + items, ok, _ := s.tryLLMCompletion(p, "", line, "", "", "", false, "") + if !ok { t.Fatalf("expected ok=true (handled)") } + if len(items) != 0 { t.Fatalf("expected no items for bare ';;' even with manual invoke") } + if fake.calls != 0 { t.Fatalf("LLM should not be called; calls=%d", fake.calls) } +} |
