summaryrefslogtreecommitdiff
path: root/internal/lsp/chat_history_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/chat_history_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/chat_history_test.go')
-rw-r--r--internal/lsp/chat_history_test.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/internal/lsp/chat_history_test.go b/internal/lsp/chat_history_test.go
index 70080f3..a6d6266 100644
--- a/internal/lsp/chat_history_test.go
+++ b/internal/lsp/chat_history_test.go
@@ -4,19 +4,19 @@ import "testing"
func TestStripTrailingTrigger(t *testing.T) {
s := newTestServer()
- if got := s.stripTrailingTrigger("what?"); got != "what" {
+ if got := s.chatSvc().stripTrailingTrigger("what?"); got != "what" {
t.Fatalf("should remove trailing ?")
}
- if got := s.stripTrailingTrigger("what?>"); got != "what?" {
+ if got := s.chatSvc().stripTrailingTrigger("what?>"); got != "what?" {
t.Fatalf("should drop trailing > when preceded by ?")
}
- if got := s.stripTrailingTrigger("ok!>"); got != "ok!" {
+ if got := s.chatSvc().stripTrailingTrigger("ok!>"); got != "ok!" {
t.Fatalf("should drop > after !")
}
- if got := s.stripTrailingTrigger("note:>"); got != "note:" {
+ if got := s.chatSvc().stripTrailingTrigger("note:>"); got != "note:" {
t.Fatalf("should drop > after :")
}
- if got := s.stripTrailingTrigger("go;>"); got != "go;" {
+ if got := s.chatSvc().stripTrailingTrigger("go;>"); got != "go;" {
t.Fatalf("should drop > after ;")
}
}
@@ -27,7 +27,7 @@ func TestBuildChatHistory_OrderAndLimit(t *testing.T) {
// Conversation: q1, > a1, blank, q2, > a2 lines, then current prompt
doc := "q1\n> a1\n\nq2\n> a2\n\n"
s.setDocument(uri, doc)
- msgs := s.buildChatHistory(uri, 5, "q3")
+ msgs := s.chatSvc().buildChatHistory(uri, 5, "q3")
// Expect: user q1, assistant a1, user q2, assistant a2, user q3
if len(msgs) != 5 || msgs[0].Role != "user" || msgs[1].Role != "assistant" || msgs[2].Role != "user" || msgs[3].Role != "assistant" || msgs[4].Role != "user" {
t.Fatalf("unexpected roles: %+v", msgs)