commit fc2771f952230a3246d5265879ed280302075b06 parent 5afe962ce78bbf0a0aa334e3c0f84656d337c25a Author: Vineet Kumar <git@vineetk.net> Date: Mon, 25 May 2026 20:05:16 -0400 split hl-get-anchors to be not monolithic Diffstat:
| M | llm-tools-hl.el | | | 38 | ++++++++++++++++++++++---------------- |
1 file changed, 22 insertions(+), 16 deletions(-)
diff --git a/llm-tools-hl.el b/llm-tools-hl.el @@ -267,28 +267,34 @@ and the cdr is the remainder of that section." (substring sec end)))) (nreverse sections)))))) +(defun llm-tools--hl-extract-anchors-from-op-line (line) + "Return a list of anchor strings from a single operation LINE. +Handles ranges by returning both endpoints." + (when (length> line 0) + (let ((op (char-to-string (elt line 0))) + (anchor (substring line 2))) + (pcase op + ((or "+" "<") (list anchor)) + ((or "-" "=") (split-string anchor "\\.\\.")))))) + +(defun llm-tools--hl-extract-anchors-from-section (section-body) + "Return all anchors from a section body (list of strings)." + (flatten-list + (mapcar #'llm-tools--hl-extract-anchors-from-op-line + (string-lines section-body)))) + (defun llm-tools--hl-get-anchors (patch) "Returns an alist of (FILENAME . ANCHORS) from PATCH. ANCHORS is a sorted, deduplicated list of all line anchors referenced by the operations in that file's sections. Each anchor is a string like \"5ff\" or a list of two strings from a range like (\"3gv\" \"6be\")." - (let ((sections (llm-tools--split-patch-sections patch))) - (delete-dups - (mapcar (lambda (patch) - (cons (car patch) - (delete-dups - (sort - (flatten-list - (mapcar (lambda (line) - (if (length> line 0) - (let ((op (char-to-string (elt line 0))) - (anchor (substring line 2))) - (pcase op - ((or "+" "<") anchor) - ((or "-" "=") (split-string anchor "\\.\\.")))))) - (string-lines (cdr patch)))))))) - sections)))) + (mapcar (lambda (section) + (cons (car section) + (delete-dups + (sort + (llm-tools--hl-extract-anchors-from-section (cdr section)))))) + (llm-tools--split-patch-sections patch))) (defun llm-tools--hl-verify-anchors (patch) "Verify that all anchors in PATCH match the current file contents.