Skip to content

Commit

Permalink
Add override for xref-backend-references
Browse files Browse the repository at this point in the history
Which will take the provided identifier and only search for the last
segment (base name or method name), to synchronize with
xref-backend-identifier-at-point.
  • Loading branch information
dgutov committed Mar 26, 2024
1 parent e693fd3 commit 9605d18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Robe is a code assistance tool that uses a Ruby REPL subprocess with
your application or gem code loaded, to provide information about
loaded classes and modules, and where each method is defined.

Generally, you'll want to start with `M-x inf-ruby-console-auto`.
If there's no Ruby console running, most interactive commands provided
by Robe will offer to launch it automatically.
Generally, you'll want to start with `M-x inf-ruby-console-auto` or
with `M-x robe-start` (which will offer to call the former function as
well if there is no Ruby console running). Some interactive commands
provided by Robe will also offer to launch it first.

The exceptions are code completion and eldoc, which only work if the
server is already running. To launch it, type `M-x robe-start`.
Expand Down
11 changes: 6 additions & 5 deletions robe.el
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ Only works with Rails, see e.g. `rinari-console'."
(robe-complete-symbol-p (car bounds)))
(buffer-substring (car bounds) (cdr bounds)))))

(defun robe--xref-backend () 'robe)
(defun robe--xref-backend () (and (robe-running-p) 'robe))

(cl-defmethod xref-backend-identifier-completion-table ((_backend (eql 'robe)))
(let ((context (robe-context))
Expand Down Expand Up @@ -1379,8 +1379,6 @@ Only works with Rails, see e.g. `rinari-console'."
(cond
(at-pt
(or (robe--xref-variable-definition identifier (nth 3 context))
;; FIXME: Probably move this check to `robe--xref-backend'.
(ignore (robe-start))
(append
(robe--xref-method-definitions identifier context)
(robe--xref-module-definitions identifier (nth 1 context)))))
Expand Down Expand Up @@ -1431,6 +1429,11 @@ Only works with Rails, see e.g. `rinari-console'."
(list
(xref-make name var)))))

;; XXX: Search across the full LOAD_PATH as well?
(cl-defmethod xref-backend-references ((backend (eql 'robe)) identifier)
;; FIXME: Do more filtering by scope, to remove definite non-matches.
(cl-call-next-method backend (car (last (string-split identifier "::\\|#\\|\\.")))))

(cl-defmethod xref-location-marker ((var robe--variable))
(save-excursion
(save-restriction
Expand Down Expand Up @@ -1490,8 +1493,6 @@ Only works with Rails, see e.g. `rinari-console'."
(file-relative-name file dir)
file)))

;; TODO: `xref-backend-references' across LOAD_PATH.

(defvar robe-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-d") 'robe-doc)
Expand Down

0 comments on commit 9605d18

Please sign in to comment.