summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-02 13:53:29 +0200
committerPaul Buetow <paul@buetow.org>2026-03-02 13:53:29 +0200
commitabfb1964fce8f742e1b02d83f4983656c49c7b95 (patch)
tree183f74220561944d626ad44576d6ef33a818e39e
parent81e79a1daf26475f020605dd92970c9bf5b112fe (diff)
lsp: extract completion/chat/codeaction server subtypes (task 406)
-rw-r--r--internal/lsp/document_test.go12
-rw-r--r--internal/lsp/ignore_test.go24
-rw-r--r--internal/lsp/server.go35
3 files changed, 42 insertions, 29 deletions
diff --git a/internal/lsp/document_test.go b/internal/lsp/document_test.go
index 95f0157..1a3f909 100644
--- a/internal/lsp/document_test.go
+++ b/internal/lsp/document_test.go
@@ -36,11 +36,13 @@ func newTestServer() *Server {
PromptCodeActionGoTestUser: "Function under test:\n{{function}}",
}
return &Server{
- logger: log.New(io.Discard, "", 0),
- docs: make(map[string]*document),
- cfg: cfg,
- altClients: make(map[string]llm.Client),
- llmProvider: canonicalProvider(cfg.Provider),
+ logger: log.New(io.Discard, "", 0),
+ docs: make(map[string]*document),
+ cfg: cfg,
+ codeActionSubsystem: codeActionSubsystem{
+ altClients: make(map[string]llm.Client),
+ llmProvider: canonicalProvider(cfg.Provider),
+ },
}
}
diff --git a/internal/lsp/ignore_test.go b/internal/lsp/ignore_test.go
index 5414137..f14daf5 100644
--- a/internal/lsp/ignore_test.go
+++ b/internal/lsp/ignore_test.go
@@ -23,11 +23,11 @@ func newIgnoreTestServer(gitRoot string, useGI bool, extra []string, notifyIgnor
ChatPrefixes: []string{"?", "!", ":", ";"},
}
s := &Server{
- logger: log.New(io.Discard, "", 0),
- docs: make(map[string]*document),
- cfg: cfg,
- altClients: make(map[string]llm.Client),
- ignoreChecker: ignore.New(gitRoot, useGI, extra),
+ logger: log.New(io.Discard, "", 0),
+ docs: make(map[string]*document),
+ cfg: cfg,
+ codeActionSubsystem: codeActionSubsystem{altClients: make(map[string]llm.Client)},
+ ignoreChecker: ignore.New(gitRoot, useGI, extra),
}
return s
}
@@ -127,9 +127,9 @@ func TestHandleDidOpen_IgnoredFile(t *testing.T) {
func TestIsFileIgnored_NoChecker(t *testing.T) {
s := &Server{
- logger: log.New(io.Discard, "", 0),
- docs: make(map[string]*document),
- altClients: make(map[string]llm.Client),
+ logger: log.New(io.Discard, "", 0),
+ docs: make(map[string]*document),
+ codeActionSubsystem: codeActionSubsystem{altClients: make(map[string]llm.Client)},
// ignoreChecker is nil
}
@@ -164,10 +164,10 @@ func TestUriToPath(t *testing.T) {
func TestIgnoreLSPNotifyEnabled_NilConfig(t *testing.T) {
// When IgnoreLSPNotify is nil, defaults to true
s := &Server{
- logger: log.New(io.Discard, "", 0),
- docs: make(map[string]*document),
- altClients: make(map[string]llm.Client),
- cfg: appconfig.App{},
+ logger: log.New(io.Discard, "", 0),
+ docs: make(map[string]*document),
+ codeActionSubsystem: codeActionSubsystem{altClients: make(map[string]llm.Client)},
+ cfg: appconfig.App{},
}
if !s.ignoreLSPNotifyEnabled() {
t.Error("expected notify enabled when config is nil (default)")
diff --git a/internal/lsp/server.go b/internal/lsp/server.go
index 730169f..fa3b375 100644
--- a/internal/lsp/server.go
+++ b/internal/lsp/server.go
@@ -32,25 +32,18 @@ type Server struct {
configStore *runtimeconfig.Store
cfg appconfig.App
llmClient llm.Client
- llmProvider string
- altClients map[string]llm.Client
- lastInput time.Time
+ codeActionSubsystem
+ chatSubsystem
// LLM request stats
llmReqTotal int64
llmSentBytesTotal int64
llmRespTotal int64
llmRespBytesTotal int64
startTime time.Time
- // Small LRU cache for recent code completion outputs (keyed by context)
- compCache map[string]string
- compCacheOrder []string // most-recent at end; cap ~10
- pendingCompletions map[string][]CompletionItem
- configLoadOpts appconfig.LoadOptions
+ completionSubsystem
+ configLoadOpts appconfig.LoadOptions
// Outgoing JSON-RPC id counter for server-initiated requests
- nextID int64
- lastLLMCall time.Time
-
- completionsDisabled bool
+ nextID int64
// Gitignore-aware file checker (nil when disabled)
ignoreChecker *ignore.Checker
@@ -59,6 +52,24 @@ type Server struct {
handlers map[string]func(Request)
}
+type completionSubsystem struct {
+ // Small LRU cache for recent code completion outputs (keyed by context)
+ compCache map[string]string
+ compCacheOrder []string // most-recent at end; cap ~10
+ pendingCompletions map[string][]CompletionItem
+ lastLLMCall time.Time
+ completionsDisabled bool
+}
+
+type chatSubsystem struct {
+ lastInput time.Time
+}
+
+type codeActionSubsystem struct {
+ llmProvider string
+ altClients map[string]llm.Client
+}
+
// ServerOptions collects configuration for NewServer to avoid long parameter lists.
type ServerOptions struct {
LogContext bool