summaryrefslogtreecommitdiff
path: root/internal/lsp/completion_cache_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-29 00:22:39 +0300
committerPaul Buetow <paul@buetow.org>2025-08-29 00:22:39 +0300
commit0c2994f0065090a4884b28dc27eb760db2dfaab3 (patch)
tree687ecd00584feb634a5853f5964028621f0fa1d5 /internal/lsp/completion_cache_test.go
parentd35aaa0227334ab0269b0907491c0682841b9cd5 (diff)
lsp: refactor dispatch to handler map; split handlers into feature files (completion, codeaction, init, document); decompose completion logic into small helpers; update review checklist
Diffstat (limited to 'internal/lsp/completion_cache_test.go')
-rw-r--r--internal/lsp/completion_cache_test.go64
1 files changed, 32 insertions, 32 deletions
diff --git a/internal/lsp/completion_cache_test.go b/internal/lsp/completion_cache_test.go
index a350281..779f89d 100644
--- a/internal/lsp/completion_cache_test.go
+++ b/internal/lsp/completion_cache_test.go
@@ -1,42 +1,42 @@
package lsp
import (
- "bytes"
- "log"
- "strings"
- "testing"
+ "bytes"
+ "log"
+ "strings"
+ "testing"
- "hexai/internal/logging"
+ "hexai/internal/logging"
)
func TestCompletionCache_IgnoresWhitespaceBeforeCursor(t *testing.T) {
- var buf bytes.Buffer
- logger := log.New(&buf, "", 0)
- s := NewServer(bytes.NewBuffer(nil), &buf, logger, ServerOptions{})
- logging.Bind(logger)
- s.triggerChars = []string{" ", "."}
- fake := &countingLLM{}
- s.llmClient = fake
+ var buf bytes.Buffer
+ logger := log.New(&buf, "", 0)
+ s := NewServer(bytes.NewBuffer(nil), &buf, logger, ServerOptions{})
+ logging.Bind(logger)
+ s.triggerChars = []string{" ", "."}
+ fake := &countingLLM{}
+ s.llmClient = fake
- // First request with trailing spaces before cursor
- line := "foo "
- p := CompletionParams{ Position: Position{ Line: 0, Character: len(line) }, TextDocument: TextDocumentIdentifier{URI: "file://x.go"} }
- items, ok := s.tryLLMCompletion(p, "", line, "", "", "", false, "")
- if !ok || len(items) == 0 || fake.calls != 1 {
- t.Fatalf("expected first call to invoke LLM; ok=%v len=%d calls=%d", ok, len(items), fake.calls)
- }
+ // First request with trailing spaces before cursor
+ line := "foo "
+ p := CompletionParams{Position: Position{Line: 0, Character: len(line)}, TextDocument: TextDocumentIdentifier{URI: "file://x.go"}}
+ items, ok := s.tryLLMCompletion(p, "", line, "", "", "", false, "")
+ if !ok || len(items) == 0 || fake.calls != 1 {
+ t.Fatalf("expected first call to invoke LLM; ok=%v len=%d calls=%d", ok, len(items), fake.calls)
+ }
- // Same logical context but with a different amount of trailing whitespace
- line2 := "foo "
- p2 := CompletionParams{ Position: Position{ Line: 0, Character: len(line2) }, TextDocument: TextDocumentIdentifier{URI: "file://x.go"} }
- items2, ok2 := s.tryLLMCompletion(p2, "", line2, "", "", "", false, "")
- if !ok2 || len(items2) == 0 {
- t.Fatalf("expected cache hit to still return items")
- }
- if fake.calls != 1 {
- t.Fatalf("expected cache hit to avoid LLM call; calls=%d", fake.calls)
- }
- if !strings.Contains(buf.String(), "completion cache hit") {
- t.Fatalf("expected log to contain cache hit message, got: %s", buf.String())
- }
+ // Same logical context but with a different amount of trailing whitespace
+ line2 := "foo "
+ p2 := CompletionParams{Position: Position{Line: 0, Character: len(line2)}, TextDocument: TextDocumentIdentifier{URI: "file://x.go"}}
+ items2, ok2 := s.tryLLMCompletion(p2, "", line2, "", "", "", false, "")
+ if !ok2 || len(items2) == 0 {
+ t.Fatalf("expected cache hit to still return items")
+ }
+ if fake.calls != 1 {
+ t.Fatalf("expected cache hit to avoid LLM call; calls=%d", fake.calls)
+ }
+ if !strings.Contains(buf.String(), "completion cache hit") {
+ t.Fatalf("expected log to contain cache hit message, got: %s", buf.String())
+ }
}