···4747 "More": func(orig int) int {
4848 return orig * 3
4949 },
5050+ "AddLineNumbers": func(content string, lineNum int, isBefore bool) []lineMatch {
5151+ return AddLineNumbers(content, lineNum, isBefore)
5252+ },
5053 "HumanUnit": func(orig int64) string {
5154 b := orig
5255 suffix := ""
···7881 "TrimTrailingNewline": func(s string) string {
7982 return strings.TrimSuffix(s, "\n")
8083 },
8484+}
8585+8686+// lineMatch represents a line of content with its associated line number
8787+type lineMatch struct {
8888+ LineNum int
8989+ Content string
9090+}
9191+9292+// AddLineNumbers adds line numbers to the beginning of each line in the given content string.
9393+// The line numbers are relative to the current line number (lineNum).
9494+// For 'before' content, numbers will count backwards from lineNum-1.
9595+// For 'after' content, numbers will count forwards from lineNum+1.
9696+func AddLineNumbers(content string, lineNum int, isBefore bool) []lineMatch {
9797+ if content == "" {
9898+ return nil
9999+ }
100100+101101+ lines := strings.Split(content, "\n")
102102+ var result []lineMatch
103103+104104+ for i, line := range lines {
105105+ if i == len(lines)-1 && line == "" {
106106+ continue
107107+ }
108108+109109+ var num int
110110+ if isBefore {
111111+ num = lineNum - len(lines) + i
112112+ } else {
113113+ num = lineNum + i + 1
114114+ }
115115+116116+ // Add the line number and content to the result
117117+ result = append(result, lineMatch{LineNum: num, Content: line})
118118+ }
119119+ return result
81120}
8212183122const defaultNumResults = 50