-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please make it to work with eglot #63
Comments
Maybe related to #58 |
It seems so, especially taking into account this reply from eglot author in another issue. |
Thanks for raising this issue. Indeed it is a continuation of #58. I'd like to add a case for Eglot in I think for detection, I can use the condition @arbv suggested: (and (fboundp #'eglot-managed-p) (eglot-managed-p)) And the translator function will handle both Eglot and default imenu entries: (defun get-eglot-position (pos)
;; when Eglot is in charge of Imenu, then the index is created by `eglot-imenu', with a fallback to
;; `imenu-default-create-index-function' when `eglot-imenu' returns nil. If POS is an array, it means
;; it was created by `eglot-imenu' and we need to extract its position. Otherwise, it was created by
;; `imenu-default-create-index-function' and we should return it as-is.
(if (arrayp pos)
(eglot--lsp-position-to-point (plist-get (plist-get (aref pos 0) :range) :start) t)
pos)) |
I don't use Eglot. Can both of you test that #65 solves this issue? The code is liable to break with future changes of Eglot, but hopefully it won't happen often and the fixes will be simple. |
@bmag Thanks! But why you rely on eglot? I think you can just call function with arguments if the element is looks like |
@muffinmad that function jumps to the entry's location, so using it means jumping to each entry and then jumping back, which I suspect will have a performance impact in buffers with a large index (especially when point is towards the end of the buffer). If you want to try this approach, evaluate the following code: (defun imenu-list--current-entry-via-excursion ()
(let ((point-pos (point-marker))
(offset (point-min-marker))
match-entry)
(dolist (entry imenu-list--line-entries match-entry)
(unless (imenu--subalist-p entry)
(let ((entry-pos (save-mark-and-excursion
(imenu entry)
(point))))
(when (imenu-list-<= offset entry-pos point-pos)
(setq offset entry-pos)
(setq match-entry entry)))))))
(advice-add #'imenu-list--current-entry :override #'imenu-list--current-entry-via-excursion)
;; to disable:
;; (advice-remove #'imenu-list--current-entry #'imenu-list--current-entry-via-excursion) |
@bmag Right, I've completely forgot about the current function highlighting. |
When being used with Eglot the current version fails with the following error message:
I needed to write my own custom position translator. Here are the relevant parts of my config:
Please adapt the code to include it into a forthcoming version.
The text was updated successfully, but these errors were encountered: