From de5029e6d4a7efffcccfb08d98770b1c1c4f54fe Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 10 Mar 2026 19:34:02 +0200 Subject: task bf088a70: extract LSP client and completion state --- internal/lsp/handlers_completion.go | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) (limited to 'internal/lsp/handlers_completion.go') diff --git a/internal/lsp/handlers_completion.go b/internal/lsp/handlers_completion.go index 3009d50..7c293b0 100644 --- a/internal/lsp/handlers_completion.go +++ b/internal/lsp/handlers_completion.go @@ -63,7 +63,7 @@ func (s *Server) handleCompletion(req Request) { if s.logContext { s.logCompletionContext(p, above, current, below, funcCtx) } - if s.llmClient != nil { + if s.currentLLMClient() != nil { newFunc := s.isDefiningNewFunction(p.TextDocument.URI, p.Position) extra, has := s.buildAdditionalContext(newFunc, p.TextDocument.URI, p.Position) items, ok, incomplete := s.tryLLMCompletion(p, above, current, below, funcCtx, docStr, has, extra) @@ -512,38 +512,6 @@ func (s *Server) waitForDebounce(ctx context.Context) { } } -// waitForThrottle enforces a minimum spacing between LLM calls. Returns false -// if the context is canceled while waiting. -func (s *Server) waitForThrottle(ctx context.Context) bool { - interval := s.completionThrottle() - if interval <= 0 { - return true - } - var wait time.Duration - for { - s.mu.Lock() - next := s.lastLLMCall.Add(interval) - now := time.Now() - if now.Before(next) { - wait = next.Sub(now) - s.mu.Unlock() - timer := time.NewTimer(wait) - select { - case <-ctx.Done(): - timer.Stop() - return false - case <-timer.C: - // try again to set the next call time - continue - } - } - // we are allowed to proceed now; record this call as the latest - s.lastLLMCall = now - s.mu.Unlock() - return true - } -} - // buildCompletionMessages constructs the LLM messages for completion. func (s *Server) buildCompletionMessages(inlinePrompt, hasExtra bool, extraText string, inParams bool, p CompletionParams, above, current, below, funcCtx string) []llm.Message { vars := map[string]string{ -- cgit v1.2.3