[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 8c9078e 19/54: Fix #343: Let other imenu function
From: |
João Távora |
Subject: |
[elpa] externals/eglot 8c9078e 19/54: Fix #343: Let other imenu functions work if LSP server's doesn't |
Date: |
Thu, 16 Apr 2020 05:31:47 -0400 (EDT) |
branch: externals/eglot
commit 8c9078e5005ff22a2958af8e768c6c06b8c19bca
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Fix #343: Let other imenu functions work if LSP server's doesn't
* eglot.el (eglot--stay-out-of-p): New helper.
(eglot--setq-saving): Use it.
(eglot--managed-mode): Use add-function :before-until for
imenu-create-index-function.
(eglot-imenu): Don't error. Fix indentation.
---
eglot.el | 81 ++++++++++++++++++++++++++++++++--------------------------------
1 file changed, 40 insertions(+), 41 deletions(-)
diff --git a/eglot.el b/eglot.el
index a7b5d59..51d0dee 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1208,17 +1208,16 @@ For example, to keep your Company customization use
(add-to-list 'eglot-stay-out-of 'company)")
+(defun eglot--stay-out-of-p (symbol)
+ "Tell if EGLOT should stay of of SYMBOL."
+ (cl-find (symbol-name symbol) eglot-stay-out-of
+ :test (lambda (s thing)
+ (let ((re (if (symbolp thing) (symbol-name thing) thing)))
+ (string-match re s)))))
+
(defmacro eglot--setq-saving (symbol binding)
- `(when (and (boundp ',symbol)
- (not (cl-find (symbol-name ',symbol)
- eglot-stay-out-of
- :test
- (lambda (s thing)
- (let ((re (if (symbolp thing) (symbol-name thing)
- thing)))
- (string-match re s))))))
- (push (cons ',symbol (symbol-value ',symbol))
- eglot--saved-bindings)
+ `(unless (or (not (boundp ',symbol)) (eglot--stay-out-of-p ',symbol))
+ (push (cons ',symbol (symbol-value ',symbol)) eglot--saved-bindings)
(setq-local ,symbol ,binding)))
(define-minor-mode eglot--managed-mode
@@ -1245,7 +1244,8 @@ For example, to keep your Company customization use
(eglot--setq-saving flymake-diagnostic-functions '(eglot-flymake-backend
t))
(eglot--setq-saving company-backends '(company-capf))
(eglot--setq-saving company-tooltip-align-annotations t)
- (eglot--setq-saving imenu-create-index-function #'eglot-imenu)
+ (unless (eglot--stay-out-of-p 'imenu)
+ (add-function :before-until imenu-create-index-function #'eglot-imenu))
(flymake-mode 1)
(eldoc-mode 1)
(cl-pushnew (current-buffer) (eglot--managed-buffers
eglot--cached-current-server)))
@@ -2298,37 +2298,36 @@ If SKIP-SIGNATURE, don't try to send
textDocument/signatureHelp."
(defun eglot-imenu ()
"EGLOT's `imenu-create-index-function'."
- (unless (eglot--server-capable :documentSymbolProvider)
- (eglot--error "Server isn't a :documentSymbolProvider"))
(let ((entries
- (mapcar
- (eglot--lambda
- ((SymbolInformation) name kind location containerName)
- (cons (propertize
- name
- :kind (alist-get kind eglot--symbol-kind-names
- "Unknown")
- :containerName (and (stringp containerName)
- (not (string-empty-p containerName))
- containerName))
- (eglot--lsp-position-to-point
- (plist-get (plist-get location :range) :start))))
- (jsonrpc-request (eglot--current-server-or-lose)
- :textDocument/documentSymbol
- `(:textDocument
,(eglot--TextDocumentIdentifier))))))
- (mapcar
- (pcase-lambda (`(,kind . ,syms))
- (let ((syms-by-scope (seq-group-by
- (lambda (e)
- (get-text-property 0 :containerName (car
e)))
- syms)))
- (cons kind (cl-loop for (scope . elems) in syms-by-scope
- append (if scope
- (list (cons scope elems))
- elems)))))
- (seq-group-by (lambda (e) (get-text-property 0 :kind (car e)))
- entries)))
- )
+ (and
+ (eglot--server-capable :documentSymbolProvider)
+ (mapcar
+ (eglot--lambda
+ ((SymbolInformation) name kind location containerName)
+ (cons (propertize
+ name
+ :kind (alist-get kind eglot--symbol-kind-names
+ "Unknown")
+ :containerName (and (stringp containerName)
+ (not (string-empty-p containerName))
+ containerName))
+ (eglot--lsp-position-to-point
+ (plist-get (plist-get location :range) :start))))
+ (jsonrpc-request (eglot--current-server-or-lose)
+ :textDocument/documentSymbol
+ `(:textDocument
,(eglot--TextDocumentIdentifier)))))))
+ (mapcar
+ (pcase-lambda (`(,kind . ,syms))
+ (let ((syms-by-scope (seq-group-by
+ (lambda (e)
+ (get-text-property 0 :containerName (car e)))
+ syms)))
+ (cons kind (cl-loop for (scope . elems) in syms-by-scope
+ append (if scope
+ (list (cons scope elems))
+ elems)))))
+ (seq-group-by (lambda (e) (get-text-property 0 :kind (car e)))
+ entries))))
(defun eglot--apply-text-edits (edits &optional version)
"Apply EDITS for current buffer if at VERSION, or if it's nil."
- [elpa] externals/eglot 6dd5de9 05/54: Unbreak imenu, (continued)
- [elpa] externals/eglot 6dd5de9 05/54: Unbreak imenu, João Távora, 2020/04/16
- [elpa] externals/eglot 243788d 04/54: Force Company to align completion annotations in Eglot sessions, João Távora, 2020/04/16
- [elpa] externals/eglot d5859b5 03/54: Per #319: fix race condition when company-completing quickly, João Távora, 2020/04/16
- [elpa] externals/eglot 576ea2e 02/54: Unbreak M-x vc-revert, which reverts preserving modes, João Távora, 2020/04/16
- [elpa] externals/eglot 32ba9d0 06/54: Expand README.md section on handling quirky servers, João Távora, 2020/04/16
- [elpa] externals/eglot 3d480d1 01/54: Fix #259 (again): fix issue with replace-buffer-contents, João Távora, 2020/04/16
- [elpa] externals/eglot 83b2acb 09/54: Support markdown for textDocument/hover (#329), João Távora, 2020/04/16
- [elpa] externals/eglot de7631d 17/54: Fix #345: set nobreak-char-display to nil in *eglot-help*, João Távora, 2020/04/16
- [elpa] externals/eglot 179a56d 13/54: Only set eglot--cached-current-server by (more aggressive) caching, João Távora, 2020/04/16
- [elpa] externals/eglot 146108a 15/54: Fix #342: Provide stable eglot-current-server helper, João Távora, 2020/04/16
- [elpa] externals/eglot 8c9078e 19/54: Fix #343: Let other imenu functions work if LSP server's doesn't,
João Távora <=
- [elpa] externals/eglot 4bd8773 23/54: Fix #339: fail when eglot-find-* finds no references, João Távora, 2020/04/16
- [elpa] externals/eglot 76d8f49 10/54: Per #50: use completionItem/resolve more abundantly, João Távora, 2020/04/16
- [elpa] externals/eglot a6fa773 25/54: Resolve compilation warnings, João Távora, 2020/04/16
- [elpa] externals/eglot b2e4687 29/54: Close #376: add metals as the language server for Scala, João Távora, 2020/04/16
- [elpa] externals/eglot 097eed5 31/54: Close #382: new eglot-confirm-server-initiated-edits defcustom, João Távora, 2020/04/16
- [elpa] externals/eglot 2ab8b59 08/54: Don't run mode hooks in eglot--format-markup, João Távora, 2020/04/16
- [elpa] externals/eglot 88311a2 12/54: Simplify "maybe"-activation, dump "server" arg, João Távora, 2020/04/16
- [elpa] externals/eglot 7f9784c 11/54: Merge -onoff proxy code into minor mode function, João Távora, 2020/04/16
- [elpa] externals/eglot 9eac9de 16/54: Fix #341: protect against empty-string insertText in completions, João Távora, 2020/04/16
- [elpa] externals/eglot b406818 07/54: Fix #326: support workspace/configuration, João Távora, 2020/04/16