summaryrefslogtreecommitdiff
path: root/internal/lsp/completion_throttle_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-19 21:57:38 +0300
committerPaul Buetow <paul@buetow.org>2025-08-19 21:57:38 +0300
commit9f59e7acd647f9adc0903e9c9655c04495f13a53 (patch)
treeedef52111c7fa87227b3d3d14b3716f458a8e5ed /internal/lsp/completion_throttle_test.go
parentef188388102b0377ed506b8767536233575965bb (diff)
lsp: replace time throttle with in-flight guard; improve short-prefix heuristic\n\n- Prevent overlapping LLM requests via llmBusy guard\n- Remove time-based throttle and option plumbing\n- Short-prefix heuristic now skips over trailing whitespace and clamps index\n- Add tests for busy guard and trailing-space allowance
Diffstat (limited to 'internal/lsp/completion_throttle_test.go')
-rw-r--r--internal/lsp/completion_throttle_test.go34
1 files changed, 22 insertions, 12 deletions
diff --git a/internal/lsp/completion_throttle_test.go b/internal/lsp/completion_throttle_test.go
index 2de8edb..f986562 100644
--- a/internal/lsp/completion_throttle_test.go
+++ b/internal/lsp/completion_throttle_test.go
@@ -5,7 +5,6 @@ import (
"context"
"log"
"testing"
- "time"
"hexai/internal/llm"
)
@@ -35,24 +34,22 @@ func TestDefaultTriggerChars_DoesNotIncludeSemicolonOrQuestion(t *testing.T) {
}
}
-func TestTryLLMCompletion_ThrottleSkipsRapidCalls(t *testing.T) {
- // Build server with long min interval and set last completion to now
+func TestTryLLMCompletion_BusySkipsConcurrent(t *testing.T) {
s := &Server{ maxTokens: 32 }
- s.minCompletionInterval = time.Hour
- s.lastLLMCompletion = time.Now()
fake := &countingLLM{}
s.llmClient = fake
- // Position with adequate prefix to avoid prefix heuristic from skipping
+ // Simulate another LLM request in flight
+ s.llmBusy = true
p := CompletionParams{ Position: Position{ Line: 0, Character: 3 }, TextDocument: TextDocumentIdentifier{URI: "file://x.go"} }
items, ok := s.tryLLMCompletion(p, "", "foo", "", "", "", false, "")
if !ok {
- t.Fatalf("expected ok=true even when throttled")
+ t.Fatalf("expected ok=true when busy guard skips")
}
if len(items) != 0 {
- t.Fatalf("expected zero items when throttled, got %d", len(items))
+ t.Fatalf("expected zero items when busy, got %d", len(items))
}
if fake.calls != 0 {
- t.Fatalf("LLM Chat should not be called when throttled; calls=%d", fake.calls)
+ t.Fatalf("LLM Chat should not be called when busy; calls=%d", fake.calls)
}
}
@@ -60,9 +57,9 @@ func TestTryLLMCompletion_MinPrefixSkipsEarly(t *testing.T) {
s := &Server{ maxTokens: 32 }
fake := &countingLLM{}
s.llmClient = fake
- // Only 1 identifier character before cursor
- p := CompletionParams{ Position: Position{ Line: 0, Character: 1 }, TextDocument: TextDocumentIdentifier{URI: "file://x.go"} }
- items, ok := s.tryLLMCompletion(p, "", "a", "", "", "", false, "")
+ // Zero identifier characters before cursor
+ p := CompletionParams{ Position: Position{ Line: 0, Character: 0 }, TextDocument: TextDocumentIdentifier{URI: "file://x.go"} }
+ items, ok := s.tryLLMCompletion(p, "", "", "", "", "", false, "")
if !ok {
t.Fatalf("expected ok=true when skipped by min-prefix heuristic")
}
@@ -73,3 +70,16 @@ func TestTryLLMCompletion_MinPrefixSkipsEarly(t *testing.T) {
t.Fatalf("LLM Chat should not be called when min-prefix not met; calls=%d", fake.calls)
}
}
+
+func TestTryLLMCompletion_AllowsAfterTrailingSpace(t *testing.T) {
+ s := &Server{ maxTokens: 32 }
+ fake := &countingLLM{}
+ s.llmClient = fake
+ line := "type Matrix "
+ // Cursor after trailing space
+ 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 == 0 {
+ t.Fatalf("expected completion allowed after trailing space; ok=%v len=%d calls=%d", ok, len(items), fake.calls)
+ }
+}