[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 1.3 a653dcb 04/26: Fix #52: Use entire line as xref summary when
From: |
Christian Johansson |
Subject: |
[elpa] 1.3 a653dcb 04/26: Fix #52: Use entire line as xref summary when available |
Date: |
Thu, 29 Apr 2021 15:09:12 -0400 (EDT) |
tag: 1.3
commit a653dcba0d583a036a5531b35b1f7f808d44d744
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Fix #52: Use entire line as xref summary when available
After an original implementation by Michael Livshin. Also close #127.
* eglot.el (eglot--xref-make): Rework.
(xref-backend-definitions, xref-backend-references)
(xref-backend-apropos): Simplify call to `eglot--xref-make'.
---
eglot.el | 38 ++++++++++++++++++++++++++++----------
1 file changed, 28 insertions(+), 10 deletions(-)
diff --git a/eglot.el b/eglot.el
index 4996f5b..8ba483b 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1478,13 +1478,31 @@ DUMMY is ignored."
(advice-add 'xref-find-definitions :after #'eglot--xref-reset-known-symbols)
(advice-add 'xref-find-references :after #'eglot--xref-reset-known-symbols)
-(defun eglot--xref-make (name uri position)
- "Like `xref-make' but with LSP's NAME, URI and POSITION."
- (cl-destructuring-bind (&key line character) position
- (xref-make name (xref-make-file-location
- (eglot--uri-to-path uri)
- ;; F!@(#*&#$)CKING OFF-BY-ONE again
- (1+ line) character))))
+(defun eglot--xref-make (name uri range)
+ "Like `xref-make' but with LSP's NAME, URI and RANGE.
+Try to visit the target file for a richer summary line."
+ (pcase-let*
+ ((`(,beg . ,end) (eglot--range-region range))
+ (file (eglot--uri-to-path uri))
+ (visiting (find-buffer-visiting file))
+ (collect (lambda ()
+ (eglot--widening
+ (pcase-let* ((`(,beg . ,end) (eglot--range-region range))
+ (bol (progn (goto-char beg) (point-at-bol)))
+ (substring (buffer-substring bol
(point-at-eol)))
+ (tab-width 1))
+ (add-face-text-property (- beg bol) (- end bol) 'highlight
+ t substring)
+ (list substring (1+ (current-line)) (current-column))))))
+ (`(,summary ,line ,column)
+ (cond
+ (visiting (with-current-buffer visiting (funcall collect)))
+ ((file-readable-p file) (with-temp-buffer (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))))
(defun eglot--sort-xrefs (xrefs)
(sort xrefs
@@ -1537,7 +1555,7 @@ DUMMY is ignored."
(if (vectorp definitions) definitions (vector definitions)))))
(eglot--sort-xrefs
(mapcar (jsonrpc-lambda (&key uri range)
- (eglot--xref-make identifier uri (plist-get range :start)))
+ (eglot--xref-make identifier uri range))
locations))))
(cl-defmethod xref-backend-references ((_backend (eql eglot)) identifier)
@@ -1552,7 +1570,7 @@ DUMMY is ignored."
(eglot--sort-xrefs
(mapcar
(jsonrpc-lambda (&key uri range)
- (eglot--xref-make identifier uri (plist-get range :start)))
+ (eglot--xref-make identifier uri range))
(jsonrpc-request (eglot--current-server-or-lose)
:textDocument/references
(append
@@ -1566,7 +1584,7 @@ DUMMY is ignored."
(mapcar
(jsonrpc-lambda (&key name location &allow-other-keys)
(cl-destructuring-bind (&key uri range) location
- (eglot--xref-make name uri (plist-get range :start))))
+ (eglot--xref-make name uri range)))
(jsonrpc-request (eglot--current-server-or-lose)
:workspace/symbol
`(:query ,pattern))))))
- [elpa] 1.3 updated (23accee -> c3d2000), Christian Johansson, 2021/04/29
- [elpa] 1.3 bad07bd 01/26: Per #144, #156: control strictness towards incoming LSP messages, Christian Johansson, 2021/04/29
- [elpa] 1.3 591210f 13/26: Close #173: support completionContext to help servers like ccls, Christian Johansson, 2021/04/29
- [elpa] 1.3 8829655 10/26: Per #171,#156: Introduce eglot--dcase, Christian Johansson, 2021/04/29
- [elpa] 1.3 245493c 23/26: Handle array params to server notification or requests, Christian Johansson, 2021/04/29
- [elpa] 1.3 1a45d87 03/26: Revert "Fix #164: CodeAction command can be a Command object (#165)", Christian Johansson, 2021/04/29
- [elpa] 1.3 a653dcb 04/26: Fix #52: Use entire line as xref summary when available,
Christian Johansson <=
- [elpa] 1.3 dadc5a2 15/26: Fix #159: Properly clear old diagnostics when making new ones, Christian Johansson, 2021/04/29
- [elpa] 1.3 e22d4d3 09/26: Simplify interface of eglot--dbind macro, Christian Johansson, 2021/04/29
- [elpa] 1.3 8c71a1a 18/26: Per #173: fix bug introduced by previous fix, Christian Johansson, 2021/04/29
- [elpa] 1.3 84a271c 08/26: Robustify tests against (M)ELPA eglot installations, Christian Johansson, 2021/04/29
- [elpa] 1.3 0f74616 07/26: Touch up last commit, Christian Johansson, 2021/04/29
- [elpa] 1.3 dc84ff6 06/26: * eglot.el (eglot--current-column): New helper., Christian Johansson, 2021/04/29
- [elpa] 1.3 5595a75 12/26: Fix #116, #150: don't break in indirect buffers, Christian Johansson, 2021/04/29
- [elpa] 1.3 72e06ea 14/26: Use javascript-typescript-langserver for typescript-mode (#174), Christian Johansson, 2021/04/29
- [elpa] 1.3 4fbbe9c 19/26: Per #173: adjust previous fix, Christian Johansson, 2021/04/29
- [elpa] 1.3 8a2008f 21/26: Warn about suspicious interface usage at compile-time, Christian Johansson, 2021/04/29