From 40e4c88dd3461136e7a447e96a0d8af9732f10f8 Mon Sep 17 00:00:00 2001 From: Michal Krzywkowski Date: Sun, 4 Nov 2018 16:34:58 +0100 Subject: [PATCH] Make imenu hierarchical * eglot.el (eglot-imenu): Use :containerName to build a nested imenu index alist. --- lisp/progmodes/eglot.el | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index f11a14e11c5..22f509b81b2 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1670,20 +1670,29 @@ If SKIP-SIGNATURE, don't try to send textDocument/signatureHelp." (jsonrpc-lambda (&key name kind location containerName _deprecated) (cons (propertize - (concat - (and (stringp containerName) - (not (string-empty-p containerName)) - (concat containerName "::")) - name) + name :kind (alist-get kind eglot--symbol-kind-names - "(Unknown)")) + "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)))))) - (seq-group-by (lambda (e) (get-text-property 0 :kind (car e))) - entries)) + (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))) (funcall oldfun))) (defun eglot--apply-text-edits (edits &optional version) -- 2.39.2