emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/elpa e5cf30e 09/71: Close #435: create match xrefs when


From: João Távora
Subject: [elpa] externals/elpa e5cf30e 09/71: Close #435: create match xrefs when possible
Date: Wed, 16 Dec 2020 11:42:14 -0500 (EST)

branch: externals/elpa
commit e5cf30e26bd3107583418f2b4539c7385d37d6c8
Author: Trevor Murphy <trevormurphy@google.com>
Commit: GitHub <noreply@github.com>

    Close #435: create match xrefs when possible
    
    "Match xrefs" are created with `xref-make-match' instead of
    `xref-make'.  Match xrefs support `xref-query-replace-in-results' from
    the results buffer.
    
    * eglot.el (eglot--xref-make-match): Calculate xref match length from
      the eglot range.
---
 eglot.el | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/eglot.el b/eglot.el
index 3ea8391..c7c4551 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1833,8 +1833,8 @@ Calls REPORT-FN maybe if server publishes diagnostics in 
time."
        (maphash (lambda (_uri buf) (kill-buffer buf)) 
eglot--temp-location-buffers)
        (clrhash eglot--temp-location-buffers))))
 
-(defun eglot--xref-make (name uri range)
-  "Like `xref-make' but with LSP's NAME, URI and RANGE.
+(defun eglot--xref-make-match (name uri range)
+  "Like `xref-make-match' but with LSP's NAME, URI and RANGE.
 Try to visit the target file for a richer summary line."
   (pcase-let*
       ((file (eglot--uri-to-path uri))
@@ -1849,8 +1849,9 @@ Try to visit the target file for a richer summary line."
                                 (hi-end (- (min (point-at-eol) end) bol)))
                      (add-face-text-property hi-beg hi-end 'highlight
                                              t substring)
-                     (list substring (1+ (current-line)) 
(eglot-current-column))))))
-       (`(,summary ,line ,column)
+                     (list substring (1+ (current-line)) (eglot-current-column)
+                           (- end beg))))))
+       (`(,summary ,line ,column ,length)
         (cond
          (visiting (with-current-buffer visiting (funcall collect)))
          ((file-readable-p file) (with-current-buffer
@@ -1859,9 +1860,12 @@ Try to visit the target file for a richer summary line."
                                    (insert-file-contents file)
                                    (funcall collect)))
          (t ;; fall back to the "dumb strategy"
-          (let ((start (cl-getf range :start)))
-            (list name (1+ (cl-getf start :line)) (cl-getf start 
:character)))))))
-    (xref-make summary (xref-make-file-location file line column))))
+          (let* ((start (cl-getf range :start))
+                 (line (1+ (cl-getf start :line)))
+                 (start-pos (cl-getf start :character))
+                 (end-pos (cl-getf (cl-getf range :end) :character)))
+            (list name line start-pos (- end-pos start-pos)))))))
+    (xref-make-match summary (xref-make-file-location file line column) 
length)))
 
 (cl-defmethod xref-backend-identifier-completion-table ((_backend (eql eglot)))
   (eglot--error "cannot (yet) provide reliable completion table for LSP 
symbols"))
@@ -1892,7 +1896,7 @@ Try to visit the target file for a richer summary line."
     (eglot--collecting-xrefs (collect)
       (mapc
        (eglot--lambda ((Location) uri range)
-         (collect (eglot--xref-make (symbol-at-point) uri range)))
+         (collect (eglot--xref-make-match (symbol-at-point) uri range)))
        (if (vectorp response) response (list response))))))
 
 (cl-defun eglot--lsp-xref-helper (method &key extra-params capability )
@@ -1935,7 +1939,7 @@ Try to visit the target file for a richer summary line."
       (mapc
        (eglot--lambda ((SymbolInformation) name location)
          (eglot--dbind ((Location) uri range) location
-           (collect (eglot--xref-make name uri range))))
+           (collect (eglot--xref-make-match name uri range))))
        (jsonrpc-request (eglot--current-server-or-lose)
                         :workspace/symbol
                         `(:query ,pattern))))))



reply via email to

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