summaryrefslogtreecommitdiff
path: root/internal/lsp/server.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-29 00:22:39 +0300
committerPaul Buetow <paul@buetow.org>2025-08-29 00:22:39 +0300
commit0c2994f0065090a4884b28dc27eb760db2dfaab3 (patch)
tree687ecd00584feb634a5853f5964028621f0fa1d5 /internal/lsp/server.go
parentd35aaa0227334ab0269b0907491c0682841b9cd5 (diff)
lsp: refactor dispatch to handler map; split handlers into feature files (completion, codeaction, init, document); decompose completion logic into small helpers; update review checklist
Diffstat (limited to 'internal/lsp/server.go')
-rw-r--r--internal/lsp/server.go28
1 files changed, 22 insertions, 6 deletions
diff --git a/internal/lsp/server.go b/internal/lsp/server.go
index 54efdf7..624c2cd 100644
--- a/internal/lsp/server.go
+++ b/internal/lsp/server.go
@@ -40,13 +40,16 @@ type Server struct {
// Small LRU cache for recent code completion outputs (keyed by context)
compCache map[string]string
compCacheOrder []string // most-recent at end; cap ~10
- // Outgoing JSON-RPC id counter for server-initiated requests
- nextID int64
- // Minimum identifier chars required for manual invoke to bypass prefix checks
- manualInvokeMinPrefix int
+ // Outgoing JSON-RPC id counter for server-initiated requests
+ nextID int64
+ // Minimum identifier chars required for manual invoke to bypass prefix checks
+ manualInvokeMinPrefix int
- // LLM concurrency guard: allow at most one in-flight request
- llmBusy bool
+ // LLM concurrency guard: allow at most one in-flight request
+ llmBusy bool
+
+ // Dispatch table for JSON-RPC methods → handler functions
+ handlers map[string]func(Request)
}
// ServerOptions collects configuration for NewServer to avoid long parameter lists.
@@ -97,6 +100,19 @@ func NewServer(r io.Reader, w io.Writer, logger *log.Logger, opts ServerOptions)
s.codingTemperature = opts.CodingTemperature
s.compCache = make(map[string]string)
s.manualInvokeMinPrefix = opts.ManualInvokeMinPrefix
+ // Initialize dispatch table
+ s.handlers = map[string]func(Request){
+ "initialize": s.handleInitialize,
+ "initialized": func(_ Request) { s.handleInitialized() },
+ "shutdown": s.handleShutdown,
+ "exit": func(_ Request) { s.handleExit() },
+ "textDocument/didOpen": s.handleDidOpen,
+ "textDocument/didChange": s.handleDidChange,
+ "textDocument/didClose": s.handleDidClose,
+ "textDocument/completion": s.handleCompletion,
+ "textDocument/codeAction": s.handleCodeAction,
+ "codeAction/resolve": s.handleCodeActionResolve,
+ }
return s
}