summaryrefslogtreecommitdiff
path: root/internal/lsp/completion_messages_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_messages_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_messages_test.go')
-rw-r--r--internal/lsp/completion_messages_test.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/internal/lsp/completion_messages_test.go b/internal/lsp/completion_messages_test.go
index bc02645..cd42155 100644
--- a/internal/lsp/completion_messages_test.go
+++ b/internal/lsp/completion_messages_test.go
@@ -7,7 +7,7 @@ import (
func TestBuildCompletionMessages_InlinePromptOverridesSys(t *testing.T) {
s := newTestServer()
p := CompletionParams{TextDocument: TextDocumentIdentifier{URI: "file:///x"}, Position: Position{Line: 0, Character: 1}}
- msgs := s.buildCompletionMessages(true, false, "", false, p, "above", "current", "below", "func f")
+ msgs := s.completion.buildCompletionMessages(true, false, "", false, p, "above", "current", "below", "func f")
if len(msgs) < 2 {
t.Fatalf("expected messages")
}
@@ -22,7 +22,7 @@ func TestBuildCompletionMessages_InlinePromptOverridesSys(t *testing.T) {
func TestBuildCompletionMessages_ExtraContextIncluded(t *testing.T) {
s := newTestServer()
p := CompletionParams{TextDocument: TextDocumentIdentifier{URI: "file:///x"}, Position: Position{Line: 0, Character: 1}}
- msgs := s.buildCompletionMessages(false, true, "EXTRA", false, p, "a", "b", "c", "f")
+ msgs := s.completion.buildCompletionMessages(false, true, "EXTRA", false, p, "a", "b", "c", "f")
found := false
for _, m := range msgs {
if m.Role == "user" && contains(m.Content, "Additional context:") {
@@ -40,11 +40,11 @@ func TestPrefixHeuristic_AllVariants(t *testing.T) {
s.cfg.ManualInvokeMinPrefix = 2
cur := "a"
p := CompletionParams{Position: Position{Line: 0, Character: 1}}
- if s.prefixHeuristicAllows(false, cur, p, true) {
+ if s.completion.prefixHeuristicAllows(false, cur, p, true) {
t.Fatalf("should require >=2 prefix on manual invoke")
}
// structural triggers 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")
}
}
@@ -52,7 +52,7 @@ func TestPrefixHeuristic_AllVariants(t *testing.T) {
func TestBuildDocString_Contents(t *testing.T) {
s := newTestServer()
p := CompletionParams{TextDocument: TextDocumentIdentifier{URI: "file:///x"}, Position: Position{Line: 3, Character: 7}}
- got := s.buildDocString(p, "above", "current", "below", "func ctx")
+ got := s.completion.buildDocString(p, "above", "current", "below", "func ctx")
if !contains(got, "file: file:///x") || !contains(got, "line: 3") || !contains(got, "function: func ctx") {
t.Fatalf("unexpected doc string: %q", got)
}
@@ -61,7 +61,7 @@ func TestBuildDocString_Contents(t *testing.T) {
func TestBuildCompletionMessages_InParams_UsesParamPrompts(t *testing.T) {
s := newTestServer()
p := CompletionParams{TextDocument: TextDocumentIdentifier{URI: "file:///x"}, Position: Position{Line: 0, Character: 5}}
- msgs := s.buildCompletionMessages(false, false, "", true, p, "a", "func f(x)", "c", "func f(x)")
+ msgs := s.completion.buildCompletionMessages(false, false, "", true, p, "a", "func f(x)", "c", "func f(x)")
if len(msgs) < 2 || msgs[0].Role != "system" || msgs[1].Role != "user" {
t.Fatalf("unexpected messages")
}
@@ -73,12 +73,12 @@ func TestBuildCompletionMessages_InParams_UsesParamPrompts(t *testing.T) {
func TestPostProcessCompletion_CodeFencesAndDuplicates(t *testing.T) {
s := newTestServer()
// code fences
- cleaned := s.postProcessCompletion("```go\nname := value\n```", "", "")
+ cleaned := s.completion.postProcessCompletion("```go\nname := value\n```", "", "")
if cleaned == "" {
t.Fatalf("expected non-empty after fence removal")
}
// duplicate assignment prefix strip
- cleaned2 := s.postProcessCompletion("name := other", "name := ", "name := ")
+ cleaned2 := s.completion.postProcessCompletion("name := other", "name := ", "name := ")
if cleaned2 == "" || cleaned2 == "name := other" {
t.Fatalf("expected duplicate assignment prefix stripped: %q", cleaned2)
}