summaryrefslogtreecommitdiff
path: root/internal/lsp/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/lsp/server.go')
-rw-r--r--internal/lsp/server.go34
1 files changed, 17 insertions, 17 deletions
diff --git a/internal/lsp/server.go b/internal/lsp/server.go
index 5fae78a..e42179d 100644
--- a/internal/lsp/server.go
+++ b/internal/lsp/server.go
@@ -32,18 +32,24 @@ type Server struct {
statusSink StatusSink
exited atomic.Bool
inflight sync.WaitGroup // tracks background goroutines (inline prompt, chat, etc.)
- // mu protects docs, cfg, logContext, configLoadOpts, nextID, and chatSubsystem.lastInput.
- // It is never held while completionState.stateMu is held, and vice versa,
- // so there is no lock ordering concern between them.
+ // mu protects docs, cfg, logContext, configLoadOpts, and nextID.
+ // It is never held while completionState.stateMu (owned by the completion
+ // service) is held, and vice versa, so there is no lock ordering concern
+ // between them.
mu sync.RWMutex
docs map[string]*document
logContext bool
configStore *runtimeconfig.Store
cfg appconfig.App
codeActionSubsystem
- chatSubsystem
llmStatsSubsystem
- completionSubsystem
+ // chat and completion own the two large feature subsystems that were
+ // previously inlined on Server (the "God Object"). Server now delegates
+ // in-editor chat and code-completion behavior to these cohesive services,
+ // each of which holds a back-reference to the Server for shared
+ // infrastructure (config, LLM clients, stats, document access).
+ chat *chatService
+ completion *completionService
configLoadOpts appconfig.LoadOptions
// Outgoing JSON-RPC id counter for server-initiated requests
nextID int64
@@ -55,14 +61,6 @@ type Server struct {
handlers map[string]func(Request)
}
-type completionSubsystem struct {
- completionState
-}
-
-type chatSubsystem struct {
- lastInput time.Time
-}
-
type codeActionSubsystem struct {
llmClientRegistry
}
@@ -125,10 +123,12 @@ func NewServer(r io.Reader, w io.Writer, logger *log.Logger, opts ServerOptions)
codeActionSubsystem: codeActionSubsystem{
llmClientRegistry: llmClientRegistry{},
},
- completionSubsystem: completionSubsystem{
- completionState: completionState{},
- },
}
+ // Wire up the chat and completion services with a back-reference to the
+ // server so they can reach shared infrastructure while owning their own
+ // feature-specific state and logic.
+ s.chat = newChatService(s)
+ s.completion = newCompletionService(s)
s.startTime = time.Now()
s.applyOptions(opts)
// Initialize dispatch table
@@ -140,7 +140,7 @@ func NewServer(r io.Reader, w io.Writer, logger *log.Logger, opts ServerOptions)
"textDocument/didOpen": s.handleDidOpen,
"textDocument/didChange": s.handleDidChange,
"textDocument/didClose": s.handleDidClose,
- "textDocument/completion": s.handleCompletion,
+ "textDocument/completion": s.completion.handleCompletion,
"textDocument/codeAction": s.handleCodeAction,
"codeAction/resolve": s.handleCodeActionResolve,
"workspace/executeCommand": s.handleExecuteCommand,