summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-22 22:21:01 +0300
committerPaul Buetow <paul@buetow.org>2025-08-22 22:21:01 +0300
commit6ec565ce315a83dcd17c138d9347055000034bdd (patch)
treec6620f4916d65156b7866609f3169febb3c55a38
parentf9cf19b213aa5452cb30c88cdd2c8764848a22f8 (diff)
logging: log completion TriggerKind and TriggerCharacter for every request
-rw-r--r--internal/lsp/handlers.go46
1 files changed, 36 insertions, 10 deletions
diff --git a/internal/lsp/handlers.go b/internal/lsp/handlers.go
index 63b32d0..3f0f75d 100644
--- a/internal/lsp/handlers.go
+++ b/internal/lsp/handlers.go
@@ -468,14 +468,18 @@ func (s *Server) handleDidClose(req Request) {
}
func (s *Server) handleCompletion(req Request) {
- var p CompletionParams
- var docStr string
- if err := json.Unmarshal(req.Params, &p); err == nil {
- above, current, below, funcCtx := s.lineContext(p.TextDocument.URI, p.Position)
- docStr = s.buildDocString(p, above, current, below, funcCtx)
- if s.logContext {
- s.logCompletionContext(p, above, current, below, funcCtx)
- }
+ var p CompletionParams
+ var docStr string
+ if err := json.Unmarshal(req.Params, &p); err == nil {
+ // Log trigger information for every completion request from client
+ tk, tch := extractTriggerInfo(p)
+ logging.Logf("lsp ", "completion trigger kind=%d char=%q uri=%s line=%d char=%d",
+ tk, tch, p.TextDocument.URI, p.Position.Line, p.Position.Character)
+ above, current, below, funcCtx := s.lineContext(p.TextDocument.URI, p.Position)
+ docStr = s.buildDocString(p, above, current, below, funcCtx)
+ if s.logContext {
+ s.logCompletionContext(p, above, current, below, funcCtx)
+ }
if s.llmClient != nil {
newFunc := s.isDefiningNewFunction(p.TextDocument.URI, p.Position)
extra, has := s.buildAdditionalContext(newFunc, p.TextDocument.URI, p.Position)
@@ -501,6 +505,25 @@ func (s *Server) reply(id json.RawMessage, result any, err *RespError) {
s.writeMessage(resp)
}
+// extractTriggerInfo returns the LSP completion TriggerKind and TriggerCharacter
+// if provided by the client; when absent it returns zeros.
+func extractTriggerInfo(p CompletionParams) (kind int, ch string) {
+ if p.Context == nil {
+ return 0, ""
+ }
+ var ctx struct {
+ TriggerKind int `json:"triggerKind"`
+ TriggerCharacter string `json:"triggerCharacter,omitempty"`
+ }
+ if raw, ok := p.Context.(json.RawMessage); ok {
+ _ = json.Unmarshal(raw, &ctx)
+ } else {
+ b, _ := json.Marshal(p.Context)
+ _ = json.Unmarshal(b, &ctx)
+ }
+ return ctx.TriggerKind, ctx.TriggerCharacter
+}
+
// --- in-editor chat (";C ...") ---
// detectAndHandleChat scans the current document for any line that starts with
@@ -758,7 +781,7 @@ 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 || inlinePrompt {
+ if inlinePrompt {
allowNoPrefix = true
}
if idx > 0 {
@@ -776,7 +799,10 @@ func (s *Server) tryLLMCompletion(p CompletionParams, above, current, below, fun
break
}
start := computeWordStart(current, j)
- if j-start < 1 { // require at least 1 identifier char
+ // For manual invoke, require a configurable minimum prefix length
+ min := 1
+ if manualInvoke && s.manualInvokeMinPrefix >= 0 { min = s.manualInvokeMinPrefix }
+ if j-start < min { // require at least min identifier chars
logging.Logf("lsp ", "%scompletion skip=short-prefix line=%d char=%d current=%q%s", logging.AnsiYellow, p.Position.Line, p.Position.Character, trimLen(current), logging.AnsiBase)
return []CompletionItem{}, true, false
}