diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-26 08:07:35 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-26 08:07:35 +0300 |
| commit | 439ebb14fa6fb43bfda2e0ee6811c37f96b15ecc (patch) | |
| tree | b2d2e4052106cf0dfc8ecdde9673e0b327ee8173 /docs/coverage.html | |
| parent | 2efcd2c4dda97831058851e8911281d5db5ce1c6 (diff) | |
Skip chat handling for inline prompts
Diffstat (limited to 'docs/coverage.html')
| -rw-r--r-- | docs/coverage.html | 96 |
1 files changed, 50 insertions, 46 deletions
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 @@ <option value="file27">codeberg.org/snonux/hexai/internal/lsp/handlers_completion.go (88.8%)</option> - <option value="file28">codeberg.org/snonux/hexai/internal/lsp/handlers_document.go (89.7%)</option> + <option value="file28">codeberg.org/snonux/hexai/internal/lsp/handlers_document.go (89.4%)</option> <option value="file29">codeberg.org/snonux/hexai/internal/lsp/handlers_execute.go (75.0%)</option> @@ -119,7 +119,7 @@ <option value="file31">codeberg.org/snonux/hexai/internal/lsp/handlers_utils.go (89.9%)</option> - <option value="file32">codeberg.org/snonux/hexai/internal/lsp/server.go (85.4%)</option> + <option value="file32">codeberg.org/snonux/hexai/internal/lsp/server.go (86.8%)</option> <option value="file33">codeberg.org/snonux/hexai/internal/lsp/transport.go (73.0%)</option> @@ -5693,9 +5693,13 @@ func (s *Server) detectAndHandleChat(uri string) <span class="cov7" title="11">{ return }</span> <span class="cov7" title="11">suffix, prefixes, _ := s.chatConfig() + _, _, openChar, closeChar := s.inlineMarkers() for i, raw := range d.lines </span><span class="cov10" title="23">{ + if lineHasInlinePrompt(raw, openChar, closeChar) </span><span class="cov0" title="0">{ + continue</span> + } // Find last non-space character index - j := len(raw) - 1 + <span class="cov10" title="23">j := len(raw) - 1 for j >= 0 </span><span class="cov9" title="20">{ if raw[j] == ' ' || raw[j] == '\t' </span><span class="cov0" title="0">{ 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 <span class="cov6" title="21">{ +func lineHasInlinePrompt(line string, open, close byte) bool <span class="cov8" title="44">{ if _, _, _, ok := findStrictInlineTag(line, open, close); ok </span><span class="cov3" title="4">{ return true }</span> - <span class="cov6" title="17">return hasDoubleOpenTrigger(line, open, close)</span> + <span class="cov8" title="40">return hasDoubleOpenTrigger(line, open, close)</span> } func leadingIndent(line string) string <span class="cov3" title="4">{ @@ -6278,17 +6282,17 @@ func applyIndent(indent, suggestion string) string <span class="cov3" title="4"> // 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) <span class="cov8" title="52">{ +func findStrictInlineTag(line string, open, close byte) (string, int, int, bool) <span class="cov9" title="75">{ pos := 0 - for pos < len(line) </span><span class="cov9" title="66">{ + for pos < len(line) </span><span class="cov9" title="87">{ // find opening marker j := strings.IndexByte(line[pos:], open) - if j < 0 </span><span class="cov7" title="28">{ + if j < 0 </span><span class="cov8" title="39">{ return "", 0, 0, false }</span> - <span class="cov8" title="38">j += pos + <span class="cov8" title="48">j += pos // ensure single open (not double) and non-space after - if j+1 >= len(line) || line[j+1] == open || line[j+1] == ' ' </span><span class="cov6" title="21">{ + if j+1 >= len(line) || line[j+1] == open || line[j+1] == ' ' </span><span class="cov7" title="31">{ pos = j + 1 continue</span> } @@ -6310,7 +6314,7 @@ func findStrictInlineTag(line string, open, close byte) (string, int, int, bool) <span class="cov6" title="15">end := closeIdx + 1 return inner, j, end, true</span> } - <span class="cov5" title="8">return "", 0, 0, false</span> + <span class="cov6" title="20">return "", 0, 0, false</span> } // isBareDoubleSemicolon reports whether the line contains a standalone @@ -6498,13 +6502,13 @@ func promptRemovalEditsForLine(line string, lineNum int, open, close byte) []Tex <span class="cov5" title="12">return collectSemicolonMarkers(line, lineNum, open, close)</span> } -func hasDoubleOpenTrigger(line string, open, close byte) bool <span class="cov9" title="64">{ +func hasDoubleOpenTrigger(line string, open, close byte) bool <span class="cov9" title="87">{ pos := 0 - for pos < len(line) </span><span class="cov9" title="66">{ + for pos < len(line) </span><span class="cov9" title="86">{ // look for double-open sequence dbl := string([]byte{open, open}) j := strings.Index(line[pos:], dbl) - if j < 0 </span><span class="cov8" title="42">{ + if j < 0 </span><span class="cov9" title="62">{ return false }</span> <span class="cov7" title="24">j += pos @@ -6529,7 +6533,7 @@ func hasDoubleOpenTrigger(line string, open, close byte) bool <span class="cov9" } <span class="cov5" title="10">return true</span> } - <span class="cov3" title="4">return false</span> + <span class="cov4" title="7">return false</span> } func collectSemicolonMarkers(line string, lineNum int, open, close byte) []TextEdit <span class="cov6" title="14">{ @@ -6774,11 +6778,11 @@ func (s *Server) currentLLMClient() llm.Client <span class="cov8" title="199">{ return s.llmClient }</span> -func (s *Server) currentConfig() appconfig.App <span class="cov10" title="409">{ - if s.configStore != nil </span><span class="cov3" title="4">{ +func (s *Server) currentConfig() appconfig.App <span class="cov10" title="420">{ + if s.configStore != nil </span><span class="cov3" title="5">{ return s.configStore.Snapshot() }</span> - <span class="cov9" title="405">s.mu.RLock() + <span class="cov9" title="415">s.mu.RLock() defer s.mu.RUnlock() return s.cfg</span> } @@ -6848,25 +6852,25 @@ func (s *Server) completionThrottle() time.Duration <span class="cov6" title="41 <span class="cov2" title="3">return time.Duration(cfg.CompletionThrottleMs) * time.Millisecond</span> } -func (s *Server) inlineMarkers() (open string, close string, openChar byte, closeChar byte) <span class="cov7" title="88">{ +func (s *Server) inlineMarkers() (open string, close string, openChar byte, closeChar byte) <span class="cov7" title="99">{ cfg := s.currentConfig() open = strings.TrimSpace(cfg.InlineOpen) - if open == "" </span><span class="cov0" title="0">{ + if open == "" </span><span class="cov2" title="2">{ open = ">" }</span> - <span class="cov7" title="88">close = strings.TrimSpace(cfg.InlineClose) - if close == "" </span><span class="cov0" title="0">{ + <span class="cov7" title="99">close = strings.TrimSpace(cfg.InlineClose) + if close == "" </span><span class="cov2" title="2">{ close = ">" }</span> - <span class="cov7" title="88">openChar = '>' - if len(open) > 0 </span><span class="cov7" title="88">{ + <span class="cov7" title="99">openChar = '>' + if len(open) > 0 </span><span class="cov7" title="99">{ openChar = open[0] }</span> - <span class="cov7" title="88">closeChar = '>' - if len(close) > 0 </span><span class="cov7" title="88">{ + <span class="cov7" title="99">closeChar = '>' + if len(close) > 0 </span><span class="cov7" title="99">{ closeChar = close[0] }</span> - <span class="cov7" title="88">return open, close, openChar, closeChar</span> + <span class="cov7" title="99">return open, close, openChar, closeChar</span> } func (s *Server) chatConfig() (suffix string, prefixes []string, suffixChar byte) <span class="cov6" title="46">{ @@ -7051,7 +7055,7 @@ func New(cfg appconfig.App) *Store <span class="cov4" title="13">{ }</span> // Snapshot returns the current configuration snapshot. Callers must treat it as read-only. -func (s *Store) Snapshot() appconfig.App <span class="cov3" title="6">{ +func (s *Store) Snapshot() appconfig.App <span class="cov3" title="7">{ 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 <span class="cov10" title="231">{ - if err := unix.Flock(int(fd), unix.LOCK_EX|unix.LOCK_NB); err != nil </span><span class="cov9" title="154">{ - if errors.Is(err, unix.EWOULDBLOCK) </span><span class="cov9" title="154">{ +func tryLockFile(fd uintptr) error <span class="cov10" title="199">{ + if err := unix.Flock(int(fd), unix.LOCK_EX|unix.LOCK_NB); err != nil </span><span class="cov9" title="122">{ + if errors.Is(err, unix.EWOULDBLOCK) </span><span class="cov9" title="122">{ return errLockWouldBlock }</span> <span class="cov0" title="0">return err</span> @@ -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) <span class="cov5" title="77">{ fd := f.Fd() - for </span><span class="cov6" title="231">{ + for </span><span class="cov5" title="199">{ err := tryLockFile(fd) if err == nil </span><span class="cov5" title="77">{ return func() error </span><span class="cov5" title="77">{ return unlockFile(fd) }</span>, nil } - <span class="cov5" title="154">if errors.Is(err, errLockWouldBlock) </span><span class="cov5" title="154">{ + <span class="cov5" title="122">if errors.Is(err, errLockWouldBlock) </span><span class="cov5" title="122">{ select </span>{ case <-ctx.Done():<span class="cov0" title="0"> return nil, ctx.Err()</span> - case <-time.After(5 * time.Millisecond):<span class="cov5" title="154"></span> + case <-time.After(5 * time.Millisecond):<span class="cov5" title="122"></span> } - <span class="cov5" title="154">continue</span> + <span class="cov5" title="122">continue</span> } <span class="cov0" title="0">return nil, err</span> } } // Snapshot reads and aggregates events within the configured window. -func TakeSnapshot() (Snapshot, error) <span class="cov5" title="69">{ +func TakeSnapshot() (Snapshot, error) <span class="cov4" title="69">{ dir, err := CacheDir() if err != nil </span><span class="cov0" title="0">{ return Snapshot{}, err }</span> - <span class="cov5" title="69">path := filepath.Join(dir, fileName) + <span class="cov4" title="69">path := filepath.Join(dir, fileName) b, err := os.ReadFile(path) if err != nil </span><span class="cov0" title="0">{ if errors.Is(err, os.ErrNotExist) </span><span class="cov0" title="0">{ @@ -7421,30 +7425,30 @@ func TakeSnapshot() (Snapshot, error) <span class="cov5" title="69">{ }</span> <span class="cov0" title="0">return Snapshot{}, err</span> } - <span class="cov5" title="69">var sf File + <span class="cov4" title="69">var sf File if err := json.Unmarshal(b, &sf); err != nil </span><span class="cov0" title="0">{ return Snapshot{}, err }</span> - <span class="cov5" title="69">win := time.Duration(sf.WindowSeconds) * time.Second + <span class="cov4" title="69">win := time.Duration(sf.WindowSeconds) * time.Second if win <= 0 </span><span class="cov0" title="0">{ win = Window() - }</span> else<span class="cov5" title="69"> { + }</span> else<span class="cov4" title="69"> { SetWindow(win) // align process with file window if changed elsewhere }</span> - <span class="cov5" title="69">cutoff := time.Now().Add(-win) + <span class="cov4" title="69">cutoff := time.Now().Add(-win) snap := Snapshot{Providers: make(map[string]ProviderEntry), Window: win} - for _, ev := range sf.Events </span><span class="cov10" title="10992">{ + for _, ev := range sf.Events </span><span class="cov10" title="14622">{ if ev.TS.Before(cutoff) </span><span class="cov0" title="0">{ continue</span> } - <span class="cov10" title="10992">snap.Global.Reqs++ + <span class="cov10" title="14622">snap.Global.Reqs++ snap.Global.Sent += ev.Sent snap.Global.Recv += ev.Recv pe := snap.Providers[ev.Provider] if pe.Models == nil </span><span class="cov6" title="465">{ pe.Models = make(map[string]Counters) }</span> - <span class="cov10" title="10992">pe.Totals.Reqs++ + <span class="cov10" title="14622">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) <span class="cov5" title="69">{ pe.Models[ev.Model] = mc snap.Providers[ev.Provider] = pe</span> } - <span class="cov5" title="69">mins := win.Minutes() + <span class="cov4" title="69">mins := win.Minutes() if mins <= 0 </span><span class="cov0" title="0">{ mins = 0.001 }</span> - <span class="cov5" title="69">snap.RPM = float64(snap.Global.Reqs) / mins + <span class="cov4" title="69">snap.RPM = float64(snap.Global.Reqs) / mins return snap, nil</span> } |
