tools/lookup: Support implementations lookup handlers

This commit is contained in:
Seong Yong-ju 2020-05-12 00:43:16 +09:00
parent 1529dcaaf5
commit 13134726dc
3 changed files with 35 additions and 4 deletions

View file

@ -15,6 +15,9 @@ properties:
:definition FN
Run when jumping to a symbol's definition. Used by `+lookup/definition'.
:implementations FN
Run when looking for implementations of a symbol in the current project. Used
by `+lookup/implementations'.
:references FN
Run when looking for usage references of a symbol in the current project. Used
by `+lookup/references'.
@ -46,8 +49,8 @@ change the current buffer or window or return non-nil when it succeeds.
If it doesn't change the current buffer, or it returns nil, the lookup module
will fall back to the next handler in `+lookup-definition-functions',
`+lookup-references-functions', `+lookup-file-functions' or
`+lookup-documentation-functions'.
`+lookup-implementations-functions', `+lookup-references-functions',
`+lookup-file-functions' or `+lookup-documentation-functions'.
Consecutive `set-lookup-handlers!' calls will overwrite previously defined
handlers for MODES. If used on minor modes, they are stacked onto handlers
@ -57,7 +60,7 @@ This can be passed nil as its second argument to unset handlers for MODES. e.g.
(set-lookup-handlers! 'python-mode nil)
\(fn MODES &key DEFINITION REFERENCES DOCUMENTATION FILE XREF-BACKEND ASYNC)"
\(fn MODES &key DEFINITION IMPLEMENTATIONS REFERENCES DOCUMENTATION FILE XREF-BACKEND ASYNC)"
(declare (indent defun))
(dolist (mode (doom-enlist modes))
(let ((hook (intern (format "%s-hook" mode)))
@ -69,15 +72,17 @@ This can be passed nil as its second argument to unset handlers for MODES. e.g.
(fset
fn
(lambda ()
(cl-destructuring-bind (&key definition references documentation file xref-backend async)
(cl-destructuring-bind (&key definition implementations references documentation file xref-backend async)
plist
(cl-mapc #'+lookup--set-handler
(list definition
implementations
references
documentation
file
xref-backend)
(list '+lookup-definition-functions
'+lookup-implementations-functions
'+lookup-references-functions
'+lookup-documentation-functions
'+lookup-file-functions
@ -133,6 +138,7 @@ This can be passed nil as its second argument to unset handlers for MODES. e.g.
(let* ((origin (point-marker))
(handlers
(plist-get (list :definition '+lookup-definition-functions
:implementations '+lookup-implementations-functions
:references '+lookup-references-functions
:documentation '+lookup-documentation-functions
:file '+lookup-file-functions)
@ -241,6 +247,18 @@ evil-mode is active."
((+lookup--jump-to :definition identifier nil arg))
((error "Couldn't find the definition of %S" identifier))))
;;;###autoload
(defun +lookup/implementations (identifier &optional arg)
"Jump to the implementations of IDENTIFIER (defaults to the symbol at point).
Each function in `+lookup-implementations-functions' is tried until one changes
the point or current buffer."
(interactive (list (doom-thing-at-point-or-region)
current-prefix-arg))
(cond ((null identifier) (user-error "Nothing under point"))
((+lookup--jump-to :implementations identifier nil arg))
((error "Couldn't find the implementations of %S" identifier))))
;;;###autoload
(defun +lookup/references (identifier &optional arg)
"Show a list of usages of IDENTIFIER (defaults to the symbol at point)