Fix #4771: give lsp-find-* precedence over fallbacks

LSP lookup handlers should have the highest precedence, but this wasn't
the case due to a regression in 430d628.
This commit is contained in:
Henrik Lissner 2021-03-27 21:41:15 -04:00
parent ce65645fb8
commit d4eb7e31ac
3 changed files with 31 additions and 5 deletions

View file

@ -212,11 +212,15 @@ This can be passed nil as its second argument to unset handlers for MODES. e.g.
(defun +lookup-xref-definitions-backend-fn (identifier)
"Non-interactive wrapper for `xref-find-definitions'"
(+lookup--xref-show 'xref-backend-definitions identifier #'xref--show-defs))
(condition-case _
(+lookup--xref-show 'xref-backend-definitions identifier #'xref--show-defs)
(cl-no-applicable-method nil)))
(defun +lookup-xref-references-backend-fn (identifier)
"Non-interactive wrapper for `xref-find-references'"
(+lookup--xref-show 'xref-backend-references identifier #'xref--show-xrefs))
(condition-case _
(+lookup--xref-show 'xref-backend-references identifier #'xref--show-xrefs)
(cl-no-applicable-method nil)))
(defun +lookup-dumb-jump-backend-fn (_identifier)
"Look up the symbol at point (or selection) with `dumb-jump', which conducts a

View file

@ -58,9 +58,9 @@ about it (it will be logged to *Messages* however).")
lsp-groovy-server-file (concat lsp-server-install-dir "groovy-language-server-all.jar"))
(set-popup-rule! "^\\*lsp-help" :size 0.35 :quit t :select t)
(set-lookup-handlers! 'lsp-mode :async t
;; NOTE :definitions and :references aren't needed. LSP is integrated into
;; xref, which the lookup module has first class support for.
(set-lookup-handlers! 'lsp-mode
:definition #'+lsp-lookup-definition-handler
:references #'+lsp-lookup-references-handler
:documentation #'lsp-describe-thing-at-point
:implementations #'lsp-find-implementation
:type-definition #'lsp-find-type-definition)

View file

@ -49,3 +49,25 @@
(car workspaces)))
(lsp-mode +1))
(setf (lsp--client-priority match) old-priority)))))
;;;###autoload
(defun +lsp-lookup-definition-handler ()
"Find definition of the symbol at point using LSP."
(interactive)
(when-let (loc (lsp-request "textDocument/definition"
(lsp--text-document-position-params)))
(lsp-show-xrefs (lsp--locations-to-xref-items loc) nil nil)
t))
;;;###autoload
(defun +lsp-lookup-references-handler (&optional include-declaration)
"Find project-wide references of the symbol at point using LSP."
(interactive "P")
(when-let
(loc (lsp-request "textDocument/references"
(append (lsp--text-document-position-params)
(list
:context `(:includeDeclaration
,(lsp-json-bool include-declaration))))))
(lsp-show-xrefs (lsp--locations-to-xref-items loc) nil t)
t))