summaryrefslogtreecommitdiff
path: root/internal/lsp/handlers_document.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-19 22:52:48 +0300
committerPaul Buetow <paul@buetow.org>2025-09-19 22:52:48 +0300
commiteb72b06fe8e62cb77af73f6dc558d384a5a5fe80 (patch)
treeefeb1165b9fbcb69a4ee675dba7bdc8c28fee3aa /internal/lsp/handlers_document.go
parentacc400768153a7bfda1413f15579c9455b877c87 (diff)
fix
Diffstat (limited to 'internal/lsp/handlers_document.go')
-rw-r--r--internal/lsp/handlers_document.go29
1 files changed, 10 insertions, 19 deletions
diff --git a/internal/lsp/handlers_document.go b/internal/lsp/handlers_document.go
index 3897885..ca0cb8d 100644
--- a/internal/lsp/handlers_document.go
+++ b/internal/lsp/handlers_document.go
@@ -11,13 +11,6 @@ import (
"codeberg.org/snonux/hexai/internal/logging"
)
-// Package-level chat trigger vars for helpers without Server receiver.
-// NewServer assigns these from configuration on startup.
-var (
- chatSuffixChar byte = '>'
- chatPrefixSingles = []string{"?", "!", ":", ";"}
-)
-
func (s *Server) handleDidOpen(req Request) {
var p DidOpenTextDocumentParams
if err := json.Unmarshal(req.Params, &p); err == nil {
@@ -236,7 +229,7 @@ func (s *Server) buildChatHistory(uri string, lineIdx int, currentPrompt string)
break
}
q := strings.TrimSpace(d.lines[i])
- q = stripTrailingTrigger(q)
+ q = s.stripTrailingTrigger(q)
pairs = append([]pair{{q: q, a: strings.Join(replyLines, "\n")}}, pairs...)
i--
}
@@ -254,25 +247,23 @@ func (s *Server) buildChatHistory(uri string, lineIdx int, currentPrompt string)
}
// stripTrailingTrigger removes the trailing chat trigger punctuation from a line if present.
-func stripTrailingTrigger(sx string) string {
- s := strings.TrimRight(sx, " \t")
- if len(s) == 0 {
+func (s *Server) stripTrailingTrigger(sx string) string {
+ trim := strings.TrimRight(sx, " \t")
+ if len(trim) == 0 {
return sx
}
- // Configurable suffix removal when preceded by configured prefixes
- if len(s) >= 2 && s[len(s)-1] == chatSuffixChar {
- prev := string(s[len(s)-2])
- for _, pf := range chatPrefixSingles {
+ if len(trim) >= 2 && s.chatSuffixChar != 0 && trim[len(trim)-1] == s.chatSuffixChar {
+ prev := string(trim[len(trim)-2])
+ for _, pf := range s.chatPrefixes {
if prev == pf {
- return strings.TrimRight(s[:len(s)-1], " \t")
+ return strings.TrimRight(trim[:len(trim)-1], " \t")
}
}
}
- // Legacy: remove one trailing punctuation (?, !, :) to build history nicely
- last := s[len(s)-1]
+ last := trim[len(trim)-1]
switch last {
case '?', '!', ':':
- return strings.TrimRight(s[:len(s)-1], " \t")
+ return strings.TrimRight(trim[:len(trim)-1], " \t")
default:
return sx
}