summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--llm-tools-hl.el38
1 files changed, 22 insertions, 16 deletions
diff --git a/llm-tools-hl.el b/llm-tools-hl.el
index 128a947..fe45c58 100644
--- a/llm-tools-hl.el
+++ b/llm-tools-hl.el
@@ -267,28 +267,34 @@ and the cdr is the remainder of that section."
267 (substring sec end)))) 267 (substring sec end))))
268 (nreverse sections)))))) 268 (nreverse sections))))))
269 269
270(defun llm-tools--hl-extract-anchors-from-op-line (line)
271 "Return a list of anchor strings from a single operation LINE.
272Handles ranges by returning both endpoints."
273 (when (length> line 0)
274 (let ((op (char-to-string (elt line 0)))
275 (anchor (substring line 2)))
276 (pcase op
277 ((or "+" "<") (list anchor))
278 ((or "-" "=") (split-string anchor "\\.\\."))))))
279
280(defun llm-tools--hl-extract-anchors-from-section (section-body)
281 "Return all anchors from a section body (list of strings)."
282 (flatten-list
283 (mapcar #'llm-tools--hl-extract-anchors-from-op-line
284 (string-lines section-body))))
285
270(defun llm-tools--hl-get-anchors (patch) 286(defun llm-tools--hl-get-anchors (patch)
271 "Returns an alist of (FILENAME . ANCHORS) from PATCH. 287 "Returns an alist of (FILENAME . ANCHORS) from PATCH.
272ANCHORS is a sorted, deduplicated list of all line anchors referenced by 288ANCHORS is a sorted, deduplicated list of all line anchors referenced by
273the operations in that file's sections. Each anchor is a string like 289the operations in that file's sections. Each anchor is a string like
274\"5ff\" or a list of two strings from a range like 290\"5ff\" or a list of two strings from a range like
275(\"3gv\" \"6be\")." 291(\"3gv\" \"6be\")."
276 (let ((sections (llm-tools--split-patch-sections patch))) 292 (mapcar (lambda (section)
277 (delete-dups 293 (cons (car section)
278 (mapcar (lambda (patch) 294 (delete-dups
279 (cons (car patch) 295 (sort
280 (delete-dups 296 (llm-tools--hl-extract-anchors-from-section (cdr section))))))
281 (sort 297 (llm-tools--split-patch-sections patch)))
282 (flatten-list
283 (mapcar (lambda (line)
284 (if (length> line 0)
285 (let ((op (char-to-string (elt line 0)))
286 (anchor (substring line 2)))
287 (pcase op
288 ((or "+" "<") anchor)
289 ((or "-" "=") (split-string anchor "\\.\\."))))))
290 (string-lines (cdr patch))))))))
291 sections))))
292 298
293(defun llm-tools--hl-verify-anchors (patch) 299(defun llm-tools--hl-verify-anchors (patch)
294 "Verify that all anchors in PATCH match the current file contents. 300 "Verify that all anchors in PATCH match the current file contents.