From 439ebb14fa6fb43bfda2e0ee6811c37f96b15ecc Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 26 Sep 2025 08:07:35 +0300 Subject: Skip chat handling for inline prompts --- docs/coverage.html | 96 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 46 deletions(-) (limited to 'docs/coverage.html') diff --git a/docs/coverage.html b/docs/coverage.html index 686f831..a1db0c8 100644 --- a/docs/coverage.html +++ b/docs/coverage.html @@ -111,7 +111,7 @@ - + @@ -119,7 +119,7 @@ - + @@ -5693,9 +5693,13 @@ func (s *Server) detectAndHandleChat(uri string) { return } suffix, prefixes, _ := s.chatConfig() + _, _, openChar, closeChar := s.inlineMarkers() for i, raw := range d.lines { + if lineHasInlinePrompt(raw, openChar, closeChar) { + continue + } // Find last non-space character index - j := len(raw) - 1 + j := len(raw) - 1 for j >= 0 { if raw[j] == ' ' || raw[j] == '\t' { j-- @@ -6234,11 +6238,11 @@ func (s *Server) chatWithStats(ctx context.Context, msgs []llm.Message, opts ... // Inline prompt utilities -func lineHasInlinePrompt(line string, open, close byte) bool { +func lineHasInlinePrompt(line string, open, close byte) bool { if _, _, _, ok := findStrictInlineTag(line, open, close); ok { return true } - return hasDoubleOpenTrigger(line, open, close) + return hasDoubleOpenTrigger(line, open, close) } func leadingIndent(line string) string { @@ -6278,17 +6282,17 @@ func applyIndent(indent, suggestion string) string // findStrictInlineTag finds >text> (configurable), with no space after the first // opening marker and no space immediately before the closing marker. Returns the // text between markers, the start index, the end index just after closing, and ok. -func findStrictInlineTag(line string, open, close byte) (string, int, int, bool) { +func findStrictInlineTag(line string, open, close byte) (string, int, int, bool) { pos := 0 - for pos < len(line) { + for pos < len(line) { // find opening marker j := strings.IndexByte(line[pos:], open) - if j < 0 { + if j < 0 { return "", 0, 0, false } - j += pos + j += pos // ensure single open (not double) and non-space after - if j+1 >= len(line) || line[j+1] == open || line[j+1] == ' ' { + if j+1 >= len(line) || line[j+1] == open || line[j+1] == ' ' { pos = j + 1 continue } @@ -6310,7 +6314,7 @@ func findStrictInlineTag(line string, open, close byte) (string, int, int, bool) end := closeIdx + 1 return inner, j, end, true } - return "", 0, 0, false + return "", 0, 0, false } // isBareDoubleSemicolon reports whether the line contains a standalone @@ -6498,13 +6502,13 @@ func promptRemovalEditsForLine(line string, lineNum int, open, close byte) []Tex return collectSemicolonMarkers(line, lineNum, open, close) } -func hasDoubleOpenTrigger(line string, open, close byte) bool { +func hasDoubleOpenTrigger(line string, open, close byte) bool { pos := 0 - for pos < len(line) { + for pos < len(line) { // look for double-open sequence dbl := string([]byte{open, open}) j := strings.Index(line[pos:], dbl) - if j < 0 { + if j < 0 { return false } j += pos @@ -6529,7 +6533,7 @@ func hasDoubleOpenTrigger(line string, open, close byte) bool return true } - return false + return false } func collectSemicolonMarkers(line string, lineNum int, open, close byte) []TextEdit { @@ -6774,11 +6778,11 @@ func (s *Server) currentLLMClient() llm.Client { return s.llmClient } -func (s *Server) currentConfig() appconfig.App { - if s.configStore != nil { +func (s *Server) currentConfig() appconfig.App { + if s.configStore != nil { return s.configStore.Snapshot() } - s.mu.RLock() + s.mu.RLock() defer s.mu.RUnlock() return s.cfg } @@ -6848,25 +6852,25 @@ func (s *Server) completionThrottle() time.Duration return time.Duration(cfg.CompletionThrottleMs) * time.Millisecond } -func (s *Server) inlineMarkers() (open string, close string, openChar byte, closeChar byte) { +func (s *Server) inlineMarkers() (open string, close string, openChar byte, closeChar byte) { cfg := s.currentConfig() open = strings.TrimSpace(cfg.InlineOpen) - if open == "" { + if open == "" { open = ">" } - close = strings.TrimSpace(cfg.InlineClose) - if close == "" { + close = strings.TrimSpace(cfg.InlineClose) + if close == "" { close = ">" } - openChar = '>' - if len(open) > 0 { + openChar = '>' + if len(open) > 0 { openChar = open[0] } - closeChar = '>' - if len(close) > 0 { + closeChar = '>' + if len(close) > 0 { closeChar = close[0] } - return open, close, openChar, closeChar + return open, close, openChar, closeChar } func (s *Server) chatConfig() (suffix string, prefixes []string, suffixChar byte) { @@ -7051,7 +7055,7 @@ func New(cfg appconfig.App) *Store { } // Snapshot returns the current configuration snapshot. Callers must treat it as read-only. -func (s *Store) Snapshot() appconfig.App { +func (s *Store) Snapshot() appconfig.App { s.mu.RLock() defer s.mu.RUnlock() return s.cfg @@ -7220,9 +7224,9 @@ import ( "golang.org/x/sys/unix" ) -func tryLockFile(fd uintptr) error { - if err := unix.Flock(int(fd), unix.LOCK_EX|unix.LOCK_NB); err != nil { - if errors.Is(err, unix.EWOULDBLOCK) { +func tryLockFile(fd uintptr) error { + if err := unix.Flock(int(fd), unix.LOCK_EX|unix.LOCK_NB); err != nil { + if errors.Is(err, unix.EWOULDBLOCK) { return errLockWouldBlock } return err @@ -7390,30 +7394,30 @@ func Update(ctx context.Context, provider, model string, sentBytes, recvBytes in func acquireFileLock(ctx context.Context, f *os.File) (func() error, error) { fd := f.Fd() - for { + for { err := tryLockFile(fd) if err == nil { return func() error { return unlockFile(fd) }, nil } - if errors.Is(err, errLockWouldBlock) { + if errors.Is(err, errLockWouldBlock) { select { case <-ctx.Done(): return nil, ctx.Err() - case <-time.After(5 * time.Millisecond): + case <-time.After(5 * time.Millisecond): } - continue + continue } return nil, err } } // Snapshot reads and aggregates events within the configured window. -func TakeSnapshot() (Snapshot, error) { +func TakeSnapshot() (Snapshot, error) { dir, err := CacheDir() if err != nil { return Snapshot{}, err } - path := filepath.Join(dir, fileName) + path := filepath.Join(dir, fileName) b, err := os.ReadFile(path) if err != nil { if errors.Is(err, os.ErrNotExist) { @@ -7421,30 +7425,30 @@ func TakeSnapshot() (Snapshot, error) { } return Snapshot{}, err } - var sf File + var sf File if err := json.Unmarshal(b, &sf); err != nil { return Snapshot{}, err } - win := time.Duration(sf.WindowSeconds) * time.Second + win := time.Duration(sf.WindowSeconds) * time.Second if win <= 0 { win = Window() - } else { + } else { SetWindow(win) // align process with file window if changed elsewhere } - cutoff := time.Now().Add(-win) + cutoff := time.Now().Add(-win) snap := Snapshot{Providers: make(map[string]ProviderEntry), Window: win} - for _, ev := range sf.Events { + for _, ev := range sf.Events { if ev.TS.Before(cutoff) { continue } - snap.Global.Reqs++ + snap.Global.Reqs++ snap.Global.Sent += ev.Sent snap.Global.Recv += ev.Recv pe := snap.Providers[ev.Provider] if pe.Models == nil { pe.Models = make(map[string]Counters) } - pe.Totals.Reqs++ + pe.Totals.Reqs++ pe.Totals.Sent += ev.Sent pe.Totals.Recv += ev.Recv mc := pe.Models[ev.Model] @@ -7454,11 +7458,11 @@ func TakeSnapshot() (Snapshot, error) { pe.Models[ev.Model] = mc snap.Providers[ev.Provider] = pe } - mins := win.Minutes() + mins := win.Minutes() if mins <= 0 { mins = 0.001 } - snap.RPM = float64(snap.Global.Reqs) / mins + snap.RPM = float64(snap.Global.Reqs) / mins return snap, nil } -- cgit v1.2.3