applyContext sets context_line / pre_context / post_context around a 0-based line index, using sourceContextLines of surrounding context.
(fm map[string]any, lines []string, idx int)
| 209 | // applyContext sets context_line / pre_context / post_context around a 0-based |
| 210 | // line index, using sourceContextLines of surrounding context. |
| 211 | func applyContext(fm map[string]any, lines []string, idx int) { |
| 212 | fm["context_line"] = lines[idx] |
| 213 | |
| 214 | pre := make([]any, 0, sourceContextLines) |
| 215 | for i := max(0, idx-sourceContextLines); i < idx; i++ { |
| 216 | pre = append(pre, lines[i]) |
| 217 | } |
| 218 | post := make([]any, 0, sourceContextLines) |
| 219 | for i := idx + 1; i < min(len(lines), idx+1+sourceContextLines); i++ { |
| 220 | post = append(post, lines[i]) |
| 221 | } |
| 222 | fm["pre_context"] = pre |
| 223 | fm["post_context"] = post |
| 224 | } |
| 225 | |
| 226 | func toLineNumber(v any) (int, bool) { |
| 227 | switch n := v.(type) { |