emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/xref-find-extra 49c435914e4 4/7: Rename the xref-backend-extra-*


From: Dmitry Gutov
Subject: feature/xref-find-extra 49c435914e4 4/7: Rename the xref-backend-extra-* methods to use the term definition
Date: Fri, 24 Nov 2023 21:13:00 -0500 (EST)

branch: feature/xref-find-extra
commit 49c435914e4919dd213d641bb9e9c4f9f234ea60
Author: Dmitry Gutov <dmitry@gutov.dev>
Commit: Dmitry Gutov <dmitry@gutov.dev>

    Rename the xref-backend-extra-* methods to use the term definition
    
    Because they are not "extra", and to a large extent will contain
    "kinds" already included in the 'xref-find-definitions' output.
    
    * lisp/progmodes/eglot.el (eglot--xref-kinds-alist): Remove the entry
    for 'references' because of differing semantics.  Simplify the names
    of the keys as well (remove the 'eglot--xref-' prefix) because these
    are shown to the user.  They won't be sent to any other backend, so
    private names seem unnecessary.  Use strings, to ensure specific type.
    
    * lisp/progmodes/eglot.el (xref-backend-definitions-by-kind):
    Skip 'intern'.
    
    * lisp/progmodes/xref.el (xref-backend-definition-kinds):
    Rename from 'xref-backend-extra-kinds'.  Update all references.
    (xref-xref-backend-definitions-by-kind): Rename from
    'xref-backend-extra-defs'.  Update all references.
---
 lisp/progmodes/eglot.el      | 16 +++++++---------
 lisp/progmodes/elisp-mode.el |  4 ++--
 lisp/progmodes/xref.el       | 23 +++++++++++++----------
 3 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 1cca533f3a3..222a4e72103 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -2948,12 +2948,10 @@ If BUFFER, switch to it before."
        (if (vectorp response) response (and response (list response)))))))
 
 (defvar eglot--xref-kinds-alist
-  '((eglot--xref-declaration :declarationProvider :textDocument/declaration)
-    (eglot--xref-definition :definitionProvider :textDocument/definition)
-    (eglot--xref-implementation :implementationProvider 
:textDocument/implementation)
-    (eglot--xref-type-definition :typeDefinitionProvider 
:textDocument/typeDefinition)
-    (eglot--xref-references :referencesProvider :textDocument/references
-                            `(:context (:includeDeclaration t))))
+  '(("declaration" :declarationProvider :textDocument/declaration)
+    ("definition" :definitionProvider :textDocument/definition)
+    ("implementation" :implementationProvider :textDocument/implementation)
+    ("type-definition" :typeDefinitionProvider :textDocument/typeDefinition))
   "Alist of (KIND CAPABILITY METHOD EXTRA-PARAMS)")
 
 (defun eglot-find-declaration ()
@@ -2997,16 +2995,16 @@ If BUFFER, switch to it before."
                        :workspace/symbol
                        `(:query ,pattern))))))
 
-(cl-defmethod xref-backend-extra-kinds ((_backend (eql eglot)) _identifier)
+(cl-defmethod xref-backend-definition-kinds ((_backend (eql eglot)) 
_identifier)
   (cl-loop for (kind capability _method _extra) in eglot--xref-kinds-alist
            when (eglot-server-capable capability) collect kind))
 
-(cl-defmethod xref-backend-extra-defs ((_backend (eql eglot)) identifier kind)
+(cl-defmethod xref-backend-definitions-by-kind ((_backend (eql eglot)) 
identifier kind)
   (cond ((eq kind 'eglot--xref-definition)
          (xref-backend-definitions 'eglot identifier))
         (t
          (pcase-let ((`(,_ ,capability ,method ,extra-params)
-                      (assoc (intern kind) eglot--xref-kinds-alist)))
+                      (assoc kind eglot--xref-kinds-alist)))
            (eglot--lsp-xrefs-for-method method :capability capability
                                         :extra-params extra-params)))))
 
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index e4e21bc565a..71f9c32f48e 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -1212,7 +1212,7 @@ namespace but with lower confidence."
 
     xrefs))
 
-(cl-defmethod xref-backend-extra-kinds ((_backend (eql 'elisp)) identifier)
+(cl-defmethod xref-backend-definition-kinds ((_backend (eql 'elisp)) 
identifier)
   ;; The file name is not known when `symbol' is defined via interactive eval.
   (let ((symbol (intern-soft identifier))
         kinds)
@@ -1252,7 +1252,7 @@ namespace but with lower confidence."
       (push "feature" kinds))
     (nreverse kinds)))
 
-(cl-defmethod xref-backend-extra-defs ((_backend (eql 'elisp)) identifier kind)
+(cl-defmethod xref-backend-definitions-by-kind ((_backend (eql 'elisp)) 
identifier kind)
   (require 'find-func)
   (let ((sym (intern-soft identifier)))
     (when sym
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index f7059c9f08c..5f76ec440b4 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -314,12 +314,15 @@ recognize and then delegate the work to an external 
process."
   "Return t if case is not significant in identifier completion."
   completion-ignore-case)
 
-(cl-defgeneric xref-backend-extra-kinds (_backend _identifier)
-  "Return the other definition types BACKEND could show for IDENTIFIER."
-  (user-error "Extra definitions not supported by the backend"))
+(cl-defgeneric xref-backend-definition-kinds (_backend _identifier)
+  "Return all definition kinds BACKEND could show for IDENTIFIER.
 
-(cl-defgeneric xref-backend-extra-defs (_backend _identifier _kind)
-  "Find definitions of extra KIND for IDENTIFIER.
+These can include both kinds returned by `xref-backend-definitions'
+(possibly split into categories) and some additional ones."
+  (user-error "Definitions kinds not supported by the backend"))
+
+(cl-defgeneric xref-backend-definitions-by-kind (_backend _identifier _kind)
+  "Find definitions of specific KIND for IDENTIFIER.
 
 The result must be a list of xref objects.  Refer to
 `xref-backend-definitions' for other details."
@@ -1637,7 +1640,7 @@ Use \\[xref-go-back] to return back to where you invoked 
this command."
   (xref--find-definitions identifier 'frame))
 
 ;;;###autoload
-(defun xref-find-extra (identifier &optional kind)
+(defun xref-find-definitions-by-kind (identifier &optional kind)
   "Find definitions of specific KIND for IDENTIFIER.
 Interactively with prefix argument, or when there's no identifier
 at point, prompt for the identifier.  Interactively, always
@@ -1650,9 +1653,9 @@ buffer where the user can select from the list.
 Use \\[xref-go-back] to return back to where you invoked this command."
   (interactive
    (let* ((id (xref--read-identifier "Find definitions of: "))
-          ;; XXX: Choose kind of "extra" first? That would fail
+          ;; XXX: Choose the definition kind first? That would fail
           ;; to take advantage of the symbol-at-point, though.
-          (kinds (xref-backend-extra-kinds (xref-find-backend) id))
+          (kinds (xref-backend-definition-kinds (xref-find-backend) id))
           ;; FIXME: We should probably skip asking when there's just
           ;; one available kind, but let's keep completing-read while
           ;; collecting the initial feedback about the interface.
@@ -1664,7 +1667,7 @@ Use \\[xref-go-back] to return back to where you invoked 
this command."
      (unless kind (user-error "No supported kinds"))
      (list id kind)))
   (xref--show-defs
-   (xref--create-fetcher identifier 'extra-defs identifier kind)
+   (xref--create-fetcher identifier 'definitions-by-kind identifier kind)
    nil))
 
 ;;;###autoload
@@ -1767,7 +1770,7 @@ output of this command when the backend is etags."
 ;;;###autoload (define-key esc-map [?\C-,] #'xref-go-forward)
 ;;;###autoload (define-key esc-map "?" #'xref-find-references)
 ;;;###autoload (define-key esc-map [?\C-.] #'xref-find-apropos)
-;;;###autoload (define-key esc-map "'" #'xref-find-extra)
+;;;###autoload (define-key esc-map "'" #'xref-find-definitions-by-kind)
 ;;;###autoload (define-key ctl-x-4-map "." 
#'xref-find-definitions-other-window)
 ;;;###autoload (define-key ctl-x-5-map "." #'xref-find-definitions-other-frame)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]