[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot f62b641b5c 05/15: Per #131, #314: Guess the "LSP
From: |
ELPA Syncer |
Subject: |
[elpa] externals/eglot f62b641b5c 05/15: Per #131, #314: Guess the "LSP identifier at point" |
Date: |
Sun, 24 Jul 2022 14:57:34 -0400 (EDT) |
branch: externals/eglot
commit f62b641b5c5fb985b9846584a5e02048c7356ca4
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Per #131, #314: Guess the "LSP identifier at point"
* eglot.el (eglot--workspace-symbols): New helper.
(xref-backend-identifier-completion-table): Rework.
(xref-backend-identifier-at-point): Rework.
---
eglot.el | 101 ++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 51 insertions(+), 50 deletions(-)
diff --git a/eglot.el b/eglot.el
index 6f9c4f50f2..22eff41f53 100644
--- a/eglot.el
+++ b/eglot.el
@@ -2396,52 +2396,52 @@ Try to visit the target file for a richer summary line."
(eglot--current-server-or-lose))
(xref-make-match summary (xref-make-file-location file line column)
length)))
+(defun eglot--workspace-symbols (pat &optional buffer)
+ "Ask for :workspace/symbol on PAT, return list of formatted strings.
+If BUFFER, switch to it before."
+ (with-current-buffer (or buffer (current-buffer))
+ (unless (eglot--server-capable :workspaceSymbolProvider)
+ (eglot--error "This LSP server isn't a :workspaceSymbolProvider"))
+ (mapcar
+ (lambda (wss)
+ (eglot--dbind ((WorkspaceSymbol) name containerName kind) wss
+ (propertize
+ (format "%s%s %s"
+ (if (zerop (length containerName)) ""
+ (concat (propertize containerName 'face 'shadow) " "))
+ name
+ (propertize (alist-get kind eglot--symbol-kind-names
"Unknown")
+ 'face 'shadow))
+ 'eglot--lsp-workspaceSymbol wss)))
+ (jsonrpc-request (eglot--current-server-or-lose) :workspace/symbol
+ `(:query ,pat)))))
+
(cl-defmethod xref-backend-identifier-completion-table ((_backend (eql eglot)))
- (if (eglot--server-capable :workspaceSymbolProvider)
- (let ((buf (current-buffer)))
- (clrhash eglot--workspace-symbols-cache)
- (cl-labels ((refresh (pat)
- (mapcar
- (lambda (wss)
- (eglot--dbind
- ((WorkspaceSymbol) name containerName kind) wss
- (propertize
- (format "%s%s %s"
- (if (zerop (length containerName)) ""
- (concat (propertize containerName
- 'face 'shadow)
- " "))
- name
- (propertize (alist-get
- kind
- eglot--symbol-kind-names
- "Unknown")
- 'face 'shadow))
- 'eglot--lsp-workspaceSymbol wss)))
- (with-current-buffer buf
- (jsonrpc-request (eglot--current-server-or-lose)
- :workspace/symbol
- `(:query ,pat)))))
- (lookup (pat) ;; check cache, else refresh
- (let* ((cache eglot--workspace-symbols-cache)
- (probe (gethash pat cache :missing)))
- (if (eq probe :missing) (puthash pat (refresh pat)
cache)
- probe)))
- (score (c)
- (cl-getf (get-text-property
- 0 'eglot--lsp-workspaceSymbol c)
- :score 0)))
- (lambda (string _pred action)
- (pcase action
- (`metadata `(metadata
- (cycle-sort-function
- . ,(lambda (completions)
- (cl-sort completions #'> :key #'score)))
- (category . eglot-indirection-joy)))
- (`(eglot--lsp-tryc . ,point) `(eglot--lsp-tryc . (,string .
,point)))
- (`(eglot--lsp-allc . ,_point) `(eglot--lsp-allc . ,(lookup
string)))
- (_ nil)))))
- (eglot--error "This LSP server isn't a :workspaceSymbolProvider")))
+ "Yet another tricky connection between LSP and Elisp completion semantics."
+ (let ((buf (current-buffer)) (cache eglot--workspace-symbols-cache))
+ (cl-labels ((refresh (pat) (eglot--workspace-symbols pat buf))
+ (lookup-1 (pat) ;; check cache, else refresh
+ (let ((probe (gethash pat cache :missing)))
+ (if (eq probe :missing) (puthash pat (refresh pat) cache)
+ probe)))
+ (lookup (pat)
+ (let ((res (lookup-1 pat))
+ (def (and (string= pat "") (gethash :default cache))))
+ (append def res nil)))
+ (score (c)
+ (cl-getf (get-text-property
+ 0 'eglot--lsp-workspaceSymbol c)
+ :score 0)))
+ (lambda (string _pred action)
+ (pcase action
+ (`metadata `(metadata
+ (cycle-sort-function
+ . ,(lambda (completions)
+ (cl-sort completions #'> :key #'score)))
+ (category . eglot-indirection-joy)))
+ (`(eglot--lsp-tryc . ,point) `(eglot--lsp-tryc . (,string . ,point)))
+ (`(eglot--lsp-allc . ,_point) `(eglot--lsp-allc . ,(lookup string)))
+ (_ nil))))))
(defun eglot--recover-workspace-symbol-meta (string)
"Search `eglot--workspace-symbols-cache' for rich entry of STRING."
@@ -2457,11 +2457,12 @@ Try to visit the target file for a richer summary line."
'(eglot-indirection-joy (styles . (eglot--lsp-backend-style))))
(cl-defmethod xref-backend-identifier-at-point ((_backend (eql eglot)))
- ;; JT@19/10/09: This is a totally dummy identifier that isn't even
- ;; passed to LSP. The reason for this particular wording is to
- ;; construct a readable message "No references for LSP identifier at
- ;; point.". See https://github.com/joaotavora/eglot/issues/314
- "LSP identifier at point")
+ (let ((attempt
+ (puthash :default
+ (ignore-errors
+ (eglot--workspace-symbols (symbol-name (symbol-at-point))))
+ eglot--workspace-symbols-cache)))
+ (if attempt (car attempt) "LSP identifier at point")))
(defvar eglot--lsp-xref-refs nil
"`xref' objects for overriding `xref-backend-references''s.")
- [elpa] externals/eglot 6cc6fcc0fa 15/15: Merge commit 'c558fd6a24' to fix fallout of force-push in GNU ELPA, (continued)
- [elpa] externals/eglot 6cc6fcc0fa 15/15: Merge commit 'c558fd6a24' to fix fallout of force-push in GNU ELPA, ELPA Syncer, 2022/07/24
- [elpa] externals/eglot 33c464f658 06/15: Per #131, #314: Be more conservative with the LSP identifier guess, ELPA Syncer, 2022/07/24
- [elpa] externals/eglot 29690e88e3 13/15: Always default eglot-strict-mode to nil, ELPA Syncer, 2022/07/24
- [elpa] externals/eglot 1db95974a7 07/15: Per #967: eglot-workspace-configuration can be a function, ELPA Syncer, 2022/07/24
- [elpa] externals/eglot 87e6de3cdf 08/15: Appease byte-compiler warnings about wrong use of quotes, ELPA Syncer, 2022/07/24
- [elpa] externals/eglot a62a388021 11/15: Fix README.md typos and rework section about Workspace configuration, ELPA Syncer, 2022/07/24
- [elpa] externals/eglot 2f71de72e3 01/15: Fix #131: Make C-u M-. work half decently, ELPA Syncer, 2022/07/24
- [elpa] externals/eglot c64fe76e86 03/15: Per #131: Cosmetic decisions guaranteed to tick off someone somewhere (tm), ELPA Syncer, 2022/07/24
- [elpa] externals/eglot a2d9e18945 09/15: Reply more reasonably to server's workspace/applyEdit, ELPA Syncer, 2022/07/24
- [elpa] externals/eglot c962f6e5f6 12/15: Rework table of contents in README.md again, ELPA Syncer, 2022/07/24
- [elpa] externals/eglot f62b641b5c 05/15: Per #131, #314: Guess the "LSP identifier at point",
ELPA Syncer <=
- [elpa] externals/eglot eed9a65515 10/15: Fix embarrassing paren-matching blunder in eglot.el, ELPA Syncer, 2022/07/24
- [elpa] externals/eglot 2387026d67 14/15: Tweak bug-reporting templates yet again, ELPA Syncer, 2022/07/24