summaryrefslogtreecommitdiff
path: root/internal/lsp/server.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-03 16:00:26 +0300
committerPaul Buetow <paul@buetow.org>2025-09-03 16:00:26 +0300
commitffe9ed5531b6e62706ea555c48964ea0e560b780 (patch)
tree81974f771543827f4c0743f5f1d66f5fbd06a2bd /internal/lsp/server.go
parent71f0d04bd558433cebf1b05845c9fa0e2957eba8 (diff)
Phase 2: add configurable completion debounce\n\n- App config: completion_debounce_ms (default 200)\n- Server: wait until no input for debounce before LLM calls\n- Applies to chat and provider-native completion paths\n- Tests: add debounce and adjust to verify behavior\n\nAll unit tests pass.
Diffstat (limited to 'internal/lsp/server.go')
-rw-r--r--internal/lsp/server.go45
1 files changed, 29 insertions, 16 deletions
diff --git a/internal/lsp/server.go b/internal/lsp/server.go
index 2f834ba..8af64ec 100644
--- a/internal/lsp/server.go
+++ b/internal/lsp/server.go
@@ -26,8 +26,8 @@ type Server struct {
maxTokens int
contextMode string
windowLines int
- maxContextTokens int
- triggerChars []string
+ maxContextTokens int
+ triggerChars []string
// If set, used as the LSP coding temperature for all LLM calls
codingTemperature *float64
// LLM request stats
@@ -39,27 +39,34 @@ 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
+ // Outgoing JSON-RPC id counter for server-initiated requests
+ nextID int64
// Minimum identifier chars required for manual invoke to bypass prefix checks
manualInvokeMinPrefix int
+ // Debounce and throttle settings
+ completionDebounce time.Duration
+ throttleInterval time.Duration
+ lastLLMCall time.Time
+
// Dispatch table for JSON-RPC methods → handler functions
handlers map[string]func(Request)
}
// ServerOptions collects configuration for NewServer to avoid long parameter lists.
type ServerOptions struct {
- LogContext bool
- MaxTokens int
- ContextMode string
- WindowLines int
- MaxContextTokens int
+ LogContext bool
+ MaxTokens int
+ ContextMode string
+ WindowLines int
+ MaxContextTokens int
- Client llm.Client
- TriggerCharacters []string
- CodingTemperature *float64
- ManualInvokeMinPrefix int
+ Client llm.Client
+ TriggerCharacters []string
+ CodingTemperature *float64
+ ManualInvokeMinPrefix int
+ CompletionDebounceMs int
+ CompletionThrottleMs int
}
func NewServer(r io.Reader, w io.Writer, logger *log.Logger, opts ServerOptions) *Server {
@@ -93,9 +100,15 @@ func NewServer(r io.Reader, w io.Writer, logger *log.Logger, opts ServerOptions)
} else {
s.triggerChars = append([]string{}, opts.TriggerCharacters...)
}
- s.codingTemperature = opts.CodingTemperature
- s.compCache = make(map[string]string)
- s.manualInvokeMinPrefix = opts.ManualInvokeMinPrefix
+ s.codingTemperature = opts.CodingTemperature
+ s.compCache = make(map[string]string)
+ s.manualInvokeMinPrefix = opts.ManualInvokeMinPrefix
+ if opts.CompletionDebounceMs > 0 {
+ s.completionDebounce = time.Duration(opts.CompletionDebounceMs) * time.Millisecond
+ }
+ if opts.CompletionThrottleMs > 0 {
+ s.throttleInterval = time.Duration(opts.CompletionThrottleMs) * time.Millisecond
+ }
// Initialize dispatch table
s.handlers = map[string]func(Request){
"initialize": s.handleInitialize,