omnisharp-emacs
omnisharp-emacs copied to clipboard
Support xref in emacs
Emacs includes a consistent way to look up (cross reference) identifiers: https://www.gnu.org/software/emacs/manual/html_node/emacs/Xref.html
It would be great if, instead of omnisharp-specific commands like omnisharp-go-to-definition
and omnisharp-find-usages
, we could delegate to xref
and it's standard keybindings across modes.
A simple implementation might be somthing like this:
(add-hook 'xref-backend-functions 'omnisharp--xref-backend)
(defun omnisharp--xref-backend () (when omnisharp-mode 'omnisharp))
(cl-defmethod xref-backend-definitions ((_backend (eql omnisharp)) symbol)
(omnisharp--xref-find-definitions symbol))
(defun omnisharp---xref-definitions (symbol)
"Return definitions for symbol."
...
(xref-make ""
(xref-make-file-location
(omnisharp--get-filename response)
(cdr (assoc 'Line json-result))
I tried implementing omnisharp---xref-definitions
, but it seems a bit tricky to mix the sync-style behaviour that xref expects from the async style omnisharp generally uses.
For what it's worth, I have bound:
:bind (:map omnisharp-mode-map
([remap xref-find-definitions] . omnisharp-go-to-definition)
([remap xref-find-references] . omnisharp-find-usages)
;; `xref-pop-marker-stack' works as expected.)
To get xref-like behaviors.