summaryrefslogtreecommitdiff
path: root/internal/lsp/handlers.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-19 21:41:33 +0300
committerPaul Buetow <paul@buetow.org>2025-08-19 21:41:33 +0300
commitef188388102b0377ed506b8767536233575965bb (patch)
tree837fa426d8f2cc65a1bc144630f968bf2cab5c1a /internal/lsp/handlers.go
parent526e40a54ba325a6f75f35817799614d7b5997b7 (diff)
lsp: reduce eager completions and add throttling\n\n- Defaults: remove ';' and '?' from trigger characters\n- Add min-typed-prefix heuristic for LLM completions (>=2 chars)\n- Add simple time-based throttle between LLM completions (default 900ms)\n- Tests: verify default triggers and skip logic (throttle + min prefix)\n- Config example: update trigger_characters list
Diffstat (limited to 'internal/lsp/handlers.go')
-rw-r--r--internal/lsp/handlers.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/internal/lsp/handlers.go b/internal/lsp/handlers.go
index cfd71ea..95656df 100644
--- a/internal/lsp/handlers.go
+++ b/internal/lsp/handlers.go
@@ -451,7 +451,27 @@ func (s *Server) tryLLMCompletion(p CompletionParams, above, current, below, fun
ctx, cancel := context.WithTimeout(context.Background(), 6*time.Second)
defer cancel()
- inParams := inParamList(current, p.Position.Character)
+ inParams := inParamList(current, p.Position.Character)
+ // Heuristic 1: Require a minimal typed identifier prefix to avoid early triggers
+ if !inParams {
+ start := computeWordStart(current, p.Position.Character)
+ if p.Position.Character-start < 2 { // fewer than 2 identifier chars
+ return []CompletionItem{}, true
+ }
+ }
+ // Heuristic 2: Throttle LLM calls to avoid rapid-fire requests
+ if s.minCompletionInterval > 0 {
+ s.mu.Lock()
+ tooSoon := time.Since(s.lastLLMCompletion) < s.minCompletionInterval
+ // Preemptively update timestamp to coalesce bursts
+ if !tooSoon {
+ s.lastLLMCompletion = time.Now()
+ }
+ s.mu.Unlock()
+ if tooSoon {
+ return []CompletionItem{}, true
+ }
+ }
sysPrompt, userPrompt := buildPrompts(inParams, p, above, current, below, funcCtx)
messages := []llm.Message{
{Role: "system", Content: sysPrompt},