-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharei-xref.el
70 lines (55 loc) · 2.32 KB
/
arei-xref.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
;;; arei-xref.el --- Arei's Backend for xref -*- lexical-binding: t; -*-
;; Copyright © 2023, 2024 Andrew Tropin <[email protected]>
;; Copyright © 2024 Nikita Domnitskii
;; Author: Andrew Tropin <[email protected]>
;; Nikita Domnitskii <[email protected]>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Arei's Backend for xref
;;; Code:
(require 'arei-nrepl)
(require 'arei-client)
(require 'arei-syntax)
(require 'xref)
(defun arei--xref-backend () 'arei)
(defun arei-xref--request-lookup (sym)
(let ((request (arei-nrepl-dict
"op" "lookup"
"sym" sym)))
(when-let* ((module (arei-current-module)))
(arei-nrepl-dict-put request "ns" module))
(arei-nrepl-dict-get
(arei-client-send-sync-request request (arei--tooling-session-id))
"info")))
(defun arei-xref--make-xref-loc (identifier)
(when-let* ((info (arei-xref--request-lookup identifier))
(file (arei-nrepl-dict-get info "file"))
(line (arei-nrepl-dict-get info "line"))
(column (arei-nrepl-dict-get info "column"))
(buffer (find-file-noselect file)))
(xref-make-buffer-location
buffer
(with-current-buffer buffer
(save-excursion
(goto-char 0)
(forward-line (1- line))
(move-to-column column)
(point))))))
(cl-defmethod xref-backend-identifier-at-point ((_backend (eql arei)))
"Return the relevant identifier at point."
(thing-at-point 'symbol t))
(cl-defmethod xref-backend-definitions ((_backend (eql arei)) identifier)
(when (arei-connected-p)
(when-let* ((loc (arei-xref--make-xref-loc identifier)))
(list (xref-make identifier loc)))))
(provide 'arei-xref)
;;; arei-xref.el ends here