From 6f1c8bf7a36eb7044ed7aad30f84664cbbf0d303 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 17 Mar 2026 11:28:19 +0200 Subject: Fix bugs, remove duplication, and clean up code quality issues - Log swallowed JSON unmarshal errors in stats and LSP handlers - Fix debug log file handle leak in tmuxedit (return closer from initDebugLog) - Check f.Close() errors on write paths in promptstore and tmuxedit - Fix cacheGet TOCTOU race by using single write lock - Fix readInput to use passed stdin reader instead of os.Stdin.Stat() - Remove 45 'moved to' comment tombstones from lsp/handlers.go - Deduplicate canonicalProvider wrappers (use llmutils.CanonicalProvider directly) - Remove SetWindow side effect from stats.TakeSnapshot (pure read now) - Move duplicated splitLines to textutil.SplitLinesBytes - Collapse StatusSink.SetGlobal 10 params into GlobalStatus struct - Simplify LRU touchLocked to in-place delete-and-append Co-Authored-By: Claude Opus 4.6 (1M context) --- internal/textutil/textutil.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'internal/textutil') diff --git a/internal/textutil/textutil.go b/internal/textutil/textutil.go index 1e9da3c..e68353d 100644 --- a/internal/textutil/textutil.go +++ b/internal/textutil/textutil.go @@ -1,6 +1,30 @@ package textutil -import "strings" +import ( + "strings" +) + +// SplitLinesBytes splits data into lines, handling both \n and \r\n endings. +// The returned slices share the underlying data array. +func SplitLinesBytes(data []byte) [][]byte { + var lines [][]byte + start := 0 + for i := 0; i < len(data); i++ { + if data[i] == '\n' { + end := i + if end > start && data[end-1] == '\r' { + end-- + } + lines = append(lines, data[start:end]) + start = i + 1 + } + } + // Handle last line if it doesn't end with newline + if start < len(data) { + lines = append(lines, data[start:]) + } + return lines +} // RenderTemplate performs simple {{var}} replacement in a template string. func RenderTemplate(t string, vars map[string]string) string { -- cgit v1.2.3