From da350b02d395d0135d9193015f969706c7d257a7 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 22 Aug 2025 17:18:25 +0300 Subject: lsp: relax short-prefix check for manual invoke and after ')' in signatures --- internal/lsp/handlers.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'internal/lsp') diff --git a/internal/lsp/handlers.go b/internal/lsp/handlers.go index f054cc9..cb8b0e4 100644 --- a/internal/lsp/handlers.go +++ b/internal/lsp/handlers.go @@ -714,6 +714,23 @@ func (s *Server) tryLLMCompletion(p CompletionParams, above, current, below, fun inParams := inParamList(current, p.Position.Character) + // Detect manual invoke so we can relax prefix heuristics when user pressed completion key. + manualInvoke := false + if p.Context != nil { + var c struct{ + TriggerKind int `json:"triggerKind"` + } + if raw, ok := p.Context.(json.RawMessage); ok { + _ = json.Unmarshal(raw, &c) + } else { + b, _ := json.Marshal(p.Context) + _ = json.Unmarshal(b, &c) + } + if c.TriggerKind == 1 { // Invoked + manualInvoke = true + } + } + // Build a cache key for this completion context (ignore trailing whitespace // before the cursor when forming the key) and try cache before any LLM call. key := s.completionCacheKey(p, above, current, below, funcCtx, inParams, hasExtra, extraText) @@ -733,9 +750,12 @@ func (s *Server) tryLLMCompletion(p CompletionParams, above, current, below, fun if idx > len(current) { idx = len(current) } // Structural triggers allow no prefix allowNoPrefix := false + if manualInvoke { + allowNoPrefix = true + } if idx > 0 { ch := current[idx-1] - if ch == '.' || ch == ':' || ch == '/' || ch == '_' { + if ch == '.' || ch == ':' || ch == '/' || ch == '_' || ch == ')' { allowNoPrefix = true } } -- cgit v1.2.3