Replies: 2 comments 4 replies
-
@nemethf I am not sure if we should add special support to EDIT: I just looked at the Eglot source and the breadcrumb properties actually come from Eglot. Why is it not possible for Eglot to create a compatible Imenu data structure where top level entries are duplicated such that they can be jumped to independently? |
Beta Was this translation helpful? Give feedback.
-
Hi, I also want (defun consult-imenu--create-key-name-eglot (prefix item types)
"Create a key-name with optional prefix and type annotations."
(let* ((name (copy-sequence (car item)))
(name-type (get-text-property 0 'breadcrumb-kind name))
(type (assoc name-type types))
(pos (consult-imenu--normalize (or (car (get-text-property 0 'breadcrumb-region name)) (cdr item))))
(key-name (concat (when prefix (concat prefix " ")) name)))
(when type
(add-face-text-property (if prefix (1+ (length prefix)) 0) (length key-name)
(nth 2 type) 'append key-name)
(setq key-name (concat (car type) " " key-name))
(put-text-property 0 (length (car type)) 'consult--type (nth 1 type) key-name))
(list (cons key-name pos))))
(defun consult-imenu--flatten-eglot (prefix face list types)
"Flatten imenu LIST.
PREFIX is prepended in front of all items.
FACE is the item face.
TYPES is the mode-specific types configuration."
(mapcan
(lambda (item)
(if (and (consp item) (stringp (car item)) (integer-or-marker-p (cdr item)))
(consult-imenu--create-key-name-eglot prefix item types)
(progn
(append
(consult-imenu--create-key-name-eglot prefix item types)
(let* ((name (concat (car item)))
(next-prefix (if prefix (concat prefix "/" name) name)))
(add-face-text-property 0 (length name)
'consult-imenu-prefix 'append name)
(consult-imenu--flatten-eglot next-prefix face (cdr item) types))))))
list))
(with-eval-after-load 'consult-imenu
(setq consult-imenu-config '((python-ts-mode :types
((?c "Class" font-lock-type-face)
(?C "Constant" font-lock-constant-face)
(?f "Function" font-lock-function-name-face)
(?m "Method" font-lock-function-name-face)
(?v "Variable" font-lock-variable-name-face)))))
;; HACK: for `breadcrumb' and `eglot'
(defun consult-imenu--compute ()
"Compute imenu candidates."
(consult--forbid-minibuffer)
(let* ((imenu-use-markers t)
;; Generate imenu, see `imenu--make-index-alist'.
(items (imenu--truncate-items
(save-excursion
(without-restriction
(funcall imenu-create-index-function)))))
(config (cdr (seq-find (lambda (x) (derived-mode-p (car x))) consult-imenu-config))))
;; Fix toplevel items, e.g., emacs-lisp-mode toplevel items are functions
(when-let (toplevel (plist-get config :toplevel))
(let ((tops (seq-remove (lambda (x) (listp (cdr x))) items))
(rest (seq-filter (lambda (x) (listp (cdr x))) items)))
(setq items (nconc rest (and tops (list (cons toplevel tops)))))))
;; Apply our flattening in order to ease searching the imenu.
(let ((fn (if (and (boundp 'eglot--managed-mode) eglot--managed-mode) #'consult-imenu--flatten-eglot #'consult-imenu--flatten)))
(funcall fn
nil nil items
(mapcar (pcase-lambda (`(,x ,y ,z)) (list y x z))
(plist-get config :types))))))) |
Beta Was this translation helpful? Give feedback.
-
I had a discussion with @sebastianpoeplau regarding a bug he reported against Eglot, which led me here. Although I do not use consult-imenu, it seems to me consult-imenu could take advantage of the text-properties provided by
breadcrumb
on top of the normal imenu interface.Eglot/breadcrumb sets the
imenu--index-alist
for the file above to this:What do you think?
Beta Was this translation helpful? Give feedback.
All reactions