From f643ad53c766764270752b782f1d4ce47305dac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Mon, 19 Jan 2026 23:57:59 +0000 Subject: [PATCH] Eglot: set imenu-create-index-function without advice See https://github.com/joaotavora/eglot/issues/1569. * lisp/progmodes/eglot.el (eglot--managed-mode): Stomp on imenu-create-index-function conditionally. (eglot-imenu): Don't check eglot-server-capable here. * etc/EGLOT-NEWS: Mention change. --- etc/EGLOT-NEWS | 5 +++++ lisp/progmodes/eglot.el | 8 +++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/etc/EGLOT-NEWS b/etc/EGLOT-NEWS index f050e0bc294..201d782575f 100644 --- a/etc/EGLOT-NEWS +++ b/etc/EGLOT-NEWS @@ -45,6 +45,11 @@ thinks responses to inflight requests are no longer useful. The current 2026 LSP landscape (especially gopls and ocamllsp) suggests this is beneficial and helps servers avoid costly useless work. +** Imenu setup no longer uses advice (github#1569) + +Eglot now sets 'imenu-create-index-function' directly without using +advice, making the integration cleaner and more predictable. + * Changes in Eglot 1.21 (11/1/2026) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 6c10f9a5512..10a58c57989 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -2364,9 +2364,9 @@ the previous reports for TOKEN.") (eglot--setq-saving company-tooltip-align-annotations t) (eglot--setq-saving eldoc-documentation-strategy #'eldoc-documentation-compose) - (unless (eglot--stay-out-of-p 'imenu) - (add-function :before-until (local 'imenu-create-index-function) - #'eglot-imenu)) + (unless (or (eglot--stay-out-of-p 'imenu) + (not (eglot-server-capable :documentSymbolProvider))) + (eglot--setq-saving imenu-create-index-function #'eglot-imenu)) (unless (eglot--stay-out-of-p 'flymake) (flymake-mode 1)) (unless (eglot--stay-out-of-p 'eldoc) (dolist (f (list #'eglot-signature-eldoc-function @@ -4222,8 +4222,6 @@ for which LSP on-type-formatting should be requested." (cl-defun eglot-imenu () "Eglot's `imenu-create-index-function'. Returns a list as described in docstring of `imenu--index-alist'." - (unless (eglot-server-capable :documentSymbolProvider) - (cl-return-from eglot-imenu)) (let* ((res (eglot--request (eglot--current-server-or-lose) :textDocument/documentSymbol `(:textDocument