commit 664c0b62450c7c6688b40f0ab6c68533778460ef
parent 32aaca5e6b88c777c4268499a94198e08b3f005e
Author: Lou Woell <lou.woell@posteo.de>
Date:   Sun,  5 Oct 2025 18:06:15 +0200

[haredoc.el] implement xref backend

Diffstat:
Mharedoc.el | 27+++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/haredoc.el b/haredoc.el @@ -30,13 +30,16 @@ ;; To enable the default keymap in hare-mode, add `haredoc-nav-mode' to your ;; `hare-mode-hook': -;; (add-hook 'hare-mode-hook #'haredoc-nav-mode) +;; `(add-hook 'hare-mode-hook #'haredoc-nav-mode)' + +;; To use the provided xref-backend: + +;; `(add-to-list 'xref-backend-functions 'hare-xref-backend)' ;;; TODO: ;; - melpa compatible setup ;; - imenu integration -;; - MAYBE: proper xref integration ;;; Code: @@ -330,5 +333,25 @@ declaration at point." :group 'haredoc (setq header-line-format `((:propertize ,haredoc-current-path face bold)))) +;;; xref backend + +;;;###autoload +(defun hare-xref-backend () + "Xref backend for hare." + (if (derived-mode-p 'hare-mode) + 'haredoc-xref + nil)) + +(cl-defmethod xref-backend-identifier-at-point ((_backend (eql 'haredoc-xref))) + (haredoc/identifier-at-point)) + +(cl-defmethod xref-backend-definitions ((_backend (eql 'haredoc-xref)) symbol) + (let* ((loc (haredoc/get-location symbol)) + (loc (split-string loc ":" t)) + (file (nth 0 loc)) + (line (string-to-number (nth 1 loc))) + (col (string-to-number (nth 2 loc)))) + (list (xref-make symbol (xref-make-file-location file line col))))) + (provide 'haredoc) ;;; haredoc.el ends here