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/chat_commands.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/chat_commands.go')
| -rw-r--r-- | internal/lsp/chat_commands.go | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/internal/lsp/chat_commands.go b/internal/lsp/chat_commands.go index 11e5a28..480643a 100644 --- a/internal/lsp/chat_commands.go +++ b/internal/lsp/chat_commands.go @@ -11,27 +11,27 @@ type chatCommandResult struct { message string } -func (s *Server) chatCommandResponse(uri string, lineIdx int, prompt string) (chatCommandResult, bool) { - trimmed := strings.TrimSpace(s.stripTrailingTrigger(prompt)) +func (c *chatService) chatCommandResponse(uri string, lineIdx int, prompt string) (chatCommandResult, bool) { + trimmed := strings.TrimSpace(c.stripTrailingTrigger(prompt)) if trimmed == "" || !strings.HasPrefix(trimmed, "/") { return chatCommandResult{}, false } switch { case strings.HasPrefix(trimmed, "/reload"): - return s.handleReloadCommand(), true + return c.handleReloadCommand(), true case strings.HasPrefix(trimmed, "/help"): - return s.handleHelpCommand(), true + return c.handleHelpCommand(), true case strings.HasPrefix(trimmed, "/disable"): - return s.handleDisableCompletionCommand(), true + return c.handleDisableCompletionCommand(), true case strings.HasPrefix(trimmed, "/enable"): - return s.handleEnableCompletionCommand(), true + return c.handleEnableCompletionCommand(), true default: return chatCommandResult{message: fmt.Sprintf("Unknown command %q. Try /help?>", trimmed)}, true } } -func (s *Server) handleHelpCommand() chatCommandResult { +func (c *chatService) handleHelpCommand() chatCommandResult { lines := []string{ "Available slash commands:", "- /reload?> reload configuration from file (ignores env overrides)", @@ -41,7 +41,8 @@ func (s *Server) handleHelpCommand() chatCommandResult { return chatCommandResult{message: strings.Join(lines, "\n")} } -func (s *Server) handleReloadCommand() chatCommandResult { +func (c *chatService) handleReloadCommand() chatCommandResult { + s := c.srv if s.configStore == nil { return chatCommandResult{message: "Reload unavailable: no config store"} } @@ -57,16 +58,16 @@ func (s *Server) handleReloadCommand() chatCommandResult { return chatCommandResult{message: summary} } -func (s *Server) handleDisableCompletionCommand() chatCommandResult { - prev := s.setCompletionsDisabled(true) +func (c *chatService) handleDisableCompletionCommand() chatCommandResult { + prev := c.srv.setCompletionsDisabled(true) if prev { return chatCommandResult{message: "Auto-completions were already disabled."} } return chatCommandResult{message: "Auto-completions disabled. Use /enable?> to restore."} } -func (s *Server) handleEnableCompletionCommand() chatCommandResult { - prev := s.setCompletionsDisabled(false) +func (c *chatService) handleEnableCompletionCommand() chatCommandResult { + prev := c.srv.setCompletionsDisabled(false) if !prev { return chatCommandResult{message: "Auto-completions are already enabled."} } |
