summaryrefslogtreecommitdiff
path: root/internal/lsp/completion_throttle_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-19 22:11:22 +0300
committerPaul Buetow <paul@buetow.org>2025-08-19 22:11:22 +0300
commit8fa3c76907c3e99e75c5828d9b5642646c81205c (patch)
tree75cf350ab4c01000603f7843c6427bc10710c68c /internal/lsp/completion_throttle_test.go
parent9f59e7acd647f9adc0903e9c9655c04495f13a53 (diff)
lsp: include space in trigger characters and allow space-triggered completions\n\n- Defaults now include space (" ") in trigger list\n- Prefix heuristic treats space as structural trigger (no min-prefix required)\n- README and config example updated\n- Tests: add coverage for space trigger
Diffstat (limited to 'internal/lsp/completion_throttle_test.go')
-rw-r--r--internal/lsp/completion_throttle_test.go38
1 files changed, 25 insertions, 13 deletions
diff --git a/internal/lsp/completion_throttle_test.go b/internal/lsp/completion_throttle_test.go
index f986562..9bd6e54 100644
--- a/internal/lsp/completion_throttle_test.go
+++ b/internal/lsp/completion_throttle_test.go
@@ -35,13 +35,13 @@ func TestDefaultTriggerChars_DoesNotIncludeSemicolonOrQuestion(t *testing.T) {
}
func TestTryLLMCompletion_BusySkipsConcurrent(t *testing.T) {
- s := &Server{ maxTokens: 32 }
+ s := &Server{ maxTokens: 32, triggerChars: []string{".", ":", "/", "_"} }
fake := &countingLLM{}
s.llmClient = fake
// 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, "")
+ 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")
}
@@ -54,32 +54,44 @@ func TestTryLLMCompletion_BusySkipsConcurrent(t *testing.T) {
}
func TestTryLLMCompletion_MinPrefixSkipsEarly(t *testing.T) {
- s := &Server{ maxTokens: 32 }
+ s := &Server{ maxTokens: 32, triggerChars: []string{".", ":", "/", "_"} }
fake := &countingLLM{}
s.llmClient = fake
- // 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, "")
+ // 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, "")
if !ok {
t.Fatalf("expected ok=true when skipped by min-prefix heuristic")
}
if len(items) != 0 {
- t.Fatalf("expected zero items when min-prefix not satisfied")
+ t.Fatalf("expected zero items when not triggered")
}
if fake.calls != 0 {
- t.Fatalf("LLM Chat should not be called when min-prefix not met; calls=%d", fake.calls)
+ t.Fatalf("LLM Chat should not be called when not triggered; calls=%d", fake.calls)
}
}
-func TestTryLLMCompletion_AllowsAfterTrailingSpace(t *testing.T) {
- s := &Server{ maxTokens: 32 }
+func TestTryLLMCompletion_RequiresTriggerChar(t *testing.T) {
+ s := &Server{ maxTokens: 32, triggerChars: []string{".", ":", "/", "_", " "} }
+ 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, "")
+ 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, "")
+ 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) }
+}
+
+func TestTryLLMCompletion_AllowsSpaceTrigger(t *testing.T) {
+ s := &Server{ maxTokens: 32, triggerChars: []string{".", ":", "/", "_", " "} }
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)
+ t.Fatalf("expected allowed with space trigger; ok=%v len=%d calls=%d", ok, len(items), fake.calls)
}
}