diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-11 00:16:27 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-11 00:16:27 +0300 |
| commit | 236f6543b093e54157f40ec0c021b35177e1713e (patch) | |
| tree | c6214c549739c997c8b572bb8904159c85fd2140 /internal/lsp/completion_helpers_more_test.go | |
| parent | 247b79114d83e13cdfb2136333a949ff4dbe385b (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_helpers_more_test.go')
| -rw-r--r-- | internal/lsp/completion_helpers_more_test.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/internal/lsp/completion_helpers_more_test.go b/internal/lsp/completion_helpers_more_test.go index 79d2523..9e4cdac 100644 --- a/internal/lsp/completion_helpers_more_test.go +++ b/internal/lsp/completion_helpers_more_test.go @@ -26,10 +26,10 @@ func TestShouldSuppressForChatTriggerEOL(t *testing.T) { s := newTestServer() p := CompletionParams{TextDocument: TextDocumentIdentifier{URI: "file:///x"}, Position: Position{Line: 0, Character: 10}} line := "say hi;>" - if !s.shouldSuppressForChatTriggerEOL(line, p) { + if !s.completion.shouldSuppressForChatTriggerEOL(line, p) { t.Fatalf("expected suppression when ;> at EOL") } - if s.shouldSuppressForChatTriggerEOL("plain>", p) { + if s.completion.shouldSuppressForChatTriggerEOL("plain>", p) { t.Fatalf("should not suppress for plain >") } } @@ -37,15 +37,15 @@ func TestShouldSuppressForChatTriggerEOL(t *testing.T) { func TestPrefixHeuristicAllows(t *testing.T) { s := newTestServer() // inline prompt allows zero prefix - if !s.prefixHeuristicAllows(true, "", CompletionParams{Position: Position{Line: 0, Character: 0}}, false) { + if !s.completion.prefixHeuristicAllows(true, "", CompletionParams{Position: Position{Line: 0, Character: 0}}, false) { t.Fatalf("inline prompt should allow") } // structural triggers like '.' allow without prefix - if !s.prefixHeuristicAllows(false, "fmt.", CompletionParams{Position: Position{Line: 0, Character: 4}}, false) { + if !s.completion.prefixHeuristicAllows(false, "fmt.", CompletionParams{Position: Position{Line: 0, Character: 4}}, false) { t.Fatalf("dot trigger should allow") } // otherwise need at least minimal prefix (default min=1) - if s.prefixHeuristicAllows(false, " ", CompletionParams{Position: Position{Line: 0, Character: 0}}, false) { + if s.completion.prefixHeuristicAllows(false, " ", CompletionParams{Position: Position{Line: 0, Character: 0}}, false) { t.Fatalf("should not allow with no prefix") } } |
