diff options
| author | Paul Buetow <paul@buetow.org> | 2025-08-20 00:10:15 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-08-20 00:10:15 +0300 |
| commit | 9751271505527047ad6fd992534735dbbe4de1ff (patch) | |
| tree | f43d42d18a7adb1b8909f8877290fe5fcf8662b9 /internal/lsp/completion_throttle_test.go | |
| parent | 507b84f2442eecf7422738b66dc29417870cda52 (diff) | |
lsp: add tiny LRU cache for last 10 completions; ignore trailing whitespace in cache key; log cache hits; report busy with isIncomplete to prompt client retry
Diffstat (limited to 'internal/lsp/completion_throttle_test.go')
| -rw-r--r-- | internal/lsp/completion_throttle_test.go | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/internal/lsp/completion_throttle_test.go b/internal/lsp/completion_throttle_test.go index 9bd6e54..46975a0 100644 --- a/internal/lsp/completion_throttle_test.go +++ b/internal/lsp/completion_throttle_test.go @@ -41,9 +41,12 @@ func TestTryLLMCompletion_BusySkipsConcurrent(t *testing.T) { // Simulate another LLM request in flight s.llmBusy = true p := CompletionParams{ Position: Position{ Line: 0, Character: 4 }, TextDocument: TextDocumentIdentifier{URI: "file://x.go"} } - items, ok := s.tryLLMCompletion(p, "", "foo.", "", "", "", false, "") - if !ok { - t.Fatalf("expected ok=true when busy guard skips") + items, ok, busy := s.tryLLMCompletion(p, "", "foo.", "", "", "", false, "") + if ok { + t.Fatalf("expected ok=false when busy guard triggers") + } + if !busy { + t.Fatalf("expected busy=true when another request in flight") } if len(items) != 0 { t.Fatalf("expected zero items when busy, got %d", len(items)) @@ -59,7 +62,7 @@ func TestTryLLMCompletion_MinPrefixSkipsEarly(t *testing.T) { s.llmClient = fake // No trigger character -> skip regardless of prefix p := CompletionParams{ Position: Position{ Line: 0, Character: 1 }, TextDocument: TextDocumentIdentifier{URI: "file://x.go"} } - items, ok := s.tryLLMCompletion(p, "", "a", "", "", "", false, "") + items, ok, _ := s.tryLLMCompletion(p, "", "a", "", "", "", false, "") if !ok { t.Fatalf("expected ok=true when skipped by min-prefix heuristic") } @@ -76,11 +79,11 @@ func TestTryLLMCompletion_RequiresTriggerChar(t *testing.T) { fake := &countingLLM{} s.llmClient = fake // With trigger character '.' directly before cursor -> allowed - items, ok := s.tryLLMCompletion(CompletionParams{ Position: Position{ Line: 0, Character: 1 }, TextDocument: TextDocumentIdentifier{URI: "file://x.go"} }, "", ".", "", "", "", false, "") + items, ok, _ := s.tryLLMCompletion(CompletionParams{ Position: Position{ Line: 0, Character: 1 }, TextDocument: TextDocumentIdentifier{URI: "file://x.go"} }, "", ".", "", "", "", false, "") if !ok || len(items) == 0 || fake.calls == 0 { t.Fatalf("expected allowed with '.' trigger") } // Without trigger -> skipped fake.calls = 0 - items, ok = s.tryLLMCompletion(CompletionParams{ Position: Position{ Line: 0, Character: 1 }, TextDocument: TextDocumentIdentifier{URI: "file://y.go"} }, "", "a", "", "", "", false, "") + items, ok, _ = s.tryLLMCompletion(CompletionParams{ Position: Position{ Line: 0, Character: 1 }, TextDocument: TextDocumentIdentifier{URI: "file://y.go"} }, "", "a", "", "", "", false, "") if !ok || len(items) != 0 || fake.calls != 0 { t.Fatalf("expected skip without trigger; ok=%v len=%d calls=%d", ok, len(items), fake.calls) } } @@ -90,7 +93,7 @@ func TestTryLLMCompletion_AllowsSpaceTrigger(t *testing.T) { s.llmClient = fake line := "type Matrix " p := CompletionParams{ Position: Position{ Line: 0, Character: len(line) }, TextDocument: TextDocumentIdentifier{URI: "file://x.go"} } - items, ok := s.tryLLMCompletion(p, "", line, "", "", "", false, "") + items, ok, _ := s.tryLLMCompletion(p, "", line, "", "", "", false, "") if !ok || len(items) == 0 || fake.calls == 0 { t.Fatalf("expected allowed with space trigger; ok=%v len=%d calls=%d", ok, len(items), fake.calls) } |
