From ef188388102b0377ed506b8767536233575965bb Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 19 Aug 2025 21:41:33 +0300 Subject: 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 --- internal/lsp/handlers.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'internal/lsp/handlers.go') 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}, -- cgit v1.2.3