summaryrefslogtreecommitdiff
path: root/internal/lsp/completion_cache_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-11 00:16:27 +0300
committerPaul Buetow <paul@buetow.org>2026-06-11 00:16:27 +0300
commit236f6543b093e54157f40ec0c021b35177e1713e (patch)
treec6214c549739c997c8b572bb8904159c85fd2140 /internal/lsp/completion_cache_test.go
parent247b79114d83e13cdfb2136333a949ff4dbe385b (diff)
Refactor lsp.Server God Object: extract chat and completion subsystems
The Server type accumulated two large, tangled feature subsystems (in-editor chat and code completion) alongside its core LSP dispatch role. Pull them into cohesive types that own their state and logic while delegating shared infrastructure back to Server via a back-reference. - Add completionService (completion_service.go): owns the completion cache/throttle state (completionState) and all completion request-handling logic (handleCompletion, plan/jobs/execute, provider-native path, post-processing, message building, prefix heuristics). Methods moved off Server in handlers_completion.go to completionService. - Add chatService (chat_service.go + chat_handlers.go): owns the input-activity clock (lastInput, with its own mutex instead of Server.mu) and all in-editor chat logic (detection, transcript history, message building, edit application, inline prompts) plus the slash-command handlers (chat_commands.go). - Server now holds chat/completion fields, wires them in NewServer, and delegates (dispatch table, didChange, debounce gate) to them. Thin Server shims preserve the existing completion-state API for callers/tests. Pure refactor: no behavior or LSP protocol changes. Tests adjusted only to reach the relocated methods/state via the services. All tests pass with -race; coverage 86.1%. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'internal/lsp/completion_cache_test.go')
-rw-r--r--internal/lsp/completion_cache_test.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/internal/lsp/completion_cache_test.go b/internal/lsp/completion_cache_test.go
index ff85906..ee51016 100644
--- a/internal/lsp/completion_cache_test.go
+++ b/internal/lsp/completion_cache_test.go
@@ -25,7 +25,7 @@ func TestCompletionCache_IgnoresWhitespaceBeforeCursor(t *testing.T) {
// 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, "")
+ items, ok, _ := s.completion.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)
}
@@ -33,7 +33,7 @@ func TestCompletionCache_IgnoresWhitespaceBeforeCursor(t *testing.T) {
// 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, "")
+ items2, ok2, _ := s.completion.tryLLMCompletion(p2, "", line2, "", "", "", false, "")
if !ok2 || len(items2) == 0 {
t.Fatalf("expected cache hit to still return items")
}