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_prefix_strip_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_prefix_strip_test.go')
| -rw-r--r-- | internal/lsp/completion_prefix_strip_test.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/internal/lsp/completion_prefix_strip_test.go b/internal/lsp/completion_prefix_strip_test.go index c8e2bd7..33eef7b 100644 --- a/internal/lsp/completion_prefix_strip_test.go +++ b/internal/lsp/completion_prefix_strip_test.go @@ -42,7 +42,7 @@ func TestStripDuplicateAssignmentPrefix_AssignAndWalrus(t *testing.T) { func TestTryLLMCompletion_ManualInvokeAfterWhitespace_Allows(t *testing.T) { s := newTestServer() - s.compCache = make(map[string]string) + s.completion.compCache = make(map[string]string) cfg := s.cfg cfg.MaxTokens = 32 cfg.TriggerCharacters = []string{".", ":", "/", "_"} @@ -52,7 +52,7 @@ func TestTryLLMCompletion_ManualInvokeAfterWhitespace_Allows(t *testing.T) { p := CompletionParams{Position: Position{Line: 0, Character: len(line)}, TextDocument: TextDocumentIdentifier{URI: "file://x.go"}} // Simulate manual user invocation (TriggerKind=1) p.Context = json.RawMessage([]byte(`{"triggerKind":1}`)) - items, ok, _ := s.tryLLMCompletion(p, "", line, "", "", "", false, "") + items, ok, _ := s.completion.tryLLMCompletion(p, "", line, "", "", "", false, "") if !ok { t.Fatalf("expected ok=true for manual invoke after whitespace") } @@ -63,7 +63,7 @@ func TestTryLLMCompletion_ManualInvokeAfterWhitespace_Allows(t *testing.T) { func TestTryLLMCompletion_InlinePromptAlwaysTriggers(t *testing.T) { s := newTestServer() - s.compCache = make(map[string]string) + s.completion.compCache = make(map[string]string) cfg := s.cfg cfg.MaxTokens = 32 cfg.TriggerCharacters = []string{".", ":", "/", "_"} @@ -72,7 +72,7 @@ func TestTryLLMCompletion_InlinePromptAlwaysTriggers(t *testing.T) { line := "prefix >!do something> suffix" // No trigger char immediately before cursor; place cursor at end p := CompletionParams{Position: Position{Line: 0, Character: len(line)}, TextDocument: TextDocumentIdentifier{URI: "file://inline.go"}} - items, ok, _ := s.tryLLMCompletion(p, "", line, "", "", "", false, "") + items, ok, _ := s.completion.tryLLMCompletion(p, "", line, "", "", "", false, "") if !ok || len(items) == 0 { t.Fatalf("expected completion to trigger on inline >!text> prompt") } @@ -80,7 +80,7 @@ func TestTryLLMCompletion_InlinePromptAlwaysTriggers(t *testing.T) { func TestTryLLMCompletion_DoubleOpenEmpty_DoesNotAutoTrigger(t *testing.T) { s := newTestServer() - s.compCache = make(map[string]string) + s.completion.compCache = make(map[string]string) cfg := s.cfg cfg.MaxTokens = 32 cfg.TriggerCharacters = []string{".", ":", "/", "_"} @@ -89,7 +89,7 @@ func TestTryLLMCompletion_DoubleOpenEmpty_DoesNotAutoTrigger(t *testing.T) { s.llmClient = fake line := ">>! " // empty content after double-open should not force-trigger p := CompletionParams{Position: Position{Line: 0, Character: len(line)}, TextDocument: TextDocumentIdentifier{URI: "file://empty-inline.go"}} - items, ok, _ := s.tryLLMCompletion(p, "", line, "", "", "", false, "") + items, ok, _ := s.completion.tryLLMCompletion(p, "", line, "", "", "", false, "") if !ok { t.Fatalf("expected ok=true for non-trigger path") } @@ -118,7 +118,7 @@ func TestHasDoubleSemicolonTrigger_Variants(t *testing.T) { func TestBareDoubleOpenPreventsAutoTriggerEvenWithOtherTriggers(t *testing.T) { s := newTestServer() - s.compCache = make(map[string]string) + s.completion.compCache = make(map[string]string) cfg := s.cfg cfg.MaxTokens = 32 cfg.TriggerCharacters = []string{".", ":", "/", "_"} @@ -128,7 +128,7 @@ func TestBareDoubleOpenPreventsAutoTriggerEvenWithOtherTriggers(t *testing.T) { // Place a '.' earlier but also include bare double-open at end; should not auto-trigger line := "obj. call >>!" p := CompletionParams{Position: Position{Line: 0, Character: len(line)}, TextDocument: TextDocumentIdentifier{URI: "file://bare-ds.go"}} - items, ok, _ := s.tryLLMCompletion(p, "", line, "", "", "", false, "") + items, ok, _ := s.completion.tryLLMCompletion(p, "", line, "", "", "", false, "") if !ok { t.Fatalf("expected ok=true (handled), but not auto-triggering") } @@ -142,7 +142,7 @@ func TestBareDoubleOpenPreventsAutoTriggerEvenWithOtherTriggers(t *testing.T) { func TestBareDoubleOpenOnNextLine_PreventsAutoTrigger(t *testing.T) { s := newTestServer() - s.compCache = make(map[string]string) + s.completion.compCache = make(map[string]string) cfg := s.cfg cfg.MaxTokens = 32 cfg.TriggerCharacters = []string{".", ":", "/", "_"} @@ -152,7 +152,7 @@ func TestBareDoubleOpenOnNextLine_PreventsAutoTrigger(t *testing.T) { current := "expression := flag.String(\"expression\", \"\", \"Expression to evaluate\")" below := ">>!" p := CompletionParams{Position: Position{Line: 0, Character: len(current)}, TextDocument: TextDocumentIdentifier{URI: "file://nextline.go"}} - items, ok, _ := s.tryLLMCompletion(p, "", current, below, "", "", false, "") + items, ok, _ := s.completion.tryLLMCompletion(p, "", current, below, "", "", false, "") if !ok { t.Fatalf("expected ok=true handled") } @@ -166,7 +166,7 @@ func TestBareDoubleOpenOnNextLine_PreventsAutoTrigger(t *testing.T) { func TestBareDoubleOpenPreventsManualInvoke(t *testing.T) { s := newTestServer() - s.compCache = make(map[string]string) + s.completion.compCache = make(map[string]string) cfg := s.cfg cfg.MaxTokens = 32 cfg.TriggerCharacters = []string{".", ":", "/", "_"} @@ -177,7 +177,7 @@ func TestBareDoubleOpenPreventsManualInvoke(t *testing.T) { p := CompletionParams{Position: Position{Line: 0, Character: len(line)}, TextDocument: TextDocumentIdentifier{URI: "file://bare-ds-manual.go"}} // Simulate manual invoke p.Context = json.RawMessage([]byte(`{"triggerKind":1}`)) - items, ok, _ := s.tryLLMCompletion(p, "", line, "", "", "", false, "") + items, ok, _ := s.completion.tryLLMCompletion(p, "", line, "", "", "", false, "") if !ok { t.Fatalf("expected ok=true (handled)") } |
