-
Notifications
You must be signed in to change notification settings - Fork 201
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
Support the which-func package, i.e. which-function-mode #758
Conversation
which-func assumes that imenu is enabled and determines which function your current point is in using imenu--index-alist. However, it doesn’t understand special elements in imenu--index-alist so those entries must be handled by a hook installed in which-func-functions. * eglot.el (eglot-which-func): Hook to determine the function which your current point is in, based on Eglot’s special Imenu element. * eglot.el (eglot--managed-mode): Add and remove the eglot-which-func hook in which-func-functions. * eglot-tests.el (basic-which-func): Test which-function-mode.
Ah, but why isn't that hook installed by default in The special elements in |
But which-func-functions is provided by the which-func package specifically to support imenu--index-alist special elements? Are you asking why this patch doesn’t install the hook? It does here, inside eglot--managed-mode. Or are you asking why which-func doesn’t rely on imenu’s interface to do the reverse lookup? I think this would be too slow. Imenu doesn’t expose this kind of API, and because the special function is arbitrary, you’d basically have to walk imenu--index-alist with save-excursion to locate the right entry, which would probably be super slow.
Yeah, it seems like overloading imenu--index-alist to present rich location information was a good attempt but imenu’s API isn’t flexible enough for other clients to deal with? What kind of existing functionality would be lost? As an alternative, we could store the rich information returned by textDocument/documentSymbol in eglot--document-symbol-alist, which gets reduces to the simple elements in imenu--index-alist. But perhaps that would be better done in another PR? If eglot--document-symbol-alist existed, I can also imagine a world where overlay properties are used to directly annotate the buffer. The documentation in which-func-mode actually points this out:
|
Simon Law ***@***.***> writes:
As an alternative, we could store the rich information returned by
textDocument/documentSymbol in eglot--document-symbol-alist, which
gets reduces to the simple elements in imenu--index-alist. But perhaps
that would be better done in another PR?
If eglot--document-symbol-alist existed, I can also imagine a world
where [overlay
properties](https://www.gnu.org/software/emacs/manual/html_node/elisp/Overlay-Properties.html)
are used to directly annotate the buffer. The documentation in
[which-func-mode](https://github.com/emacs-mirror/emacs/blob/3af9e84ff59811734dcbb5d55e04e1fdb7051e77/lisp/progmodes/which-func.el#L41-L47)
actually points this out:
> ``` elisp
> ;; TODO LIST
> ;; ---------
> ;; 1. Dependence on imenu package should be removed. Separate
> ;; function determination mechanism should be used to determine the end
> ;; of a function as well as the beginning of a function.
> ;; 2. This package should be realized with the help of overlay
> ;; properties instead of imenu--index-alist variable.
> ```
For what it's worth, ada-mode does not use imenu to provide
which-function. Instead, it adds ada-which-function to
which-func-functions. ada-which-function queries the syntax tree to
find the declaration that contains point.
eglot could do something similar; the textDocument/documentSymbol query
essentially returns the syntax tree. You can descend the tree to find
the symbol containing point, then ascend the tree to find a symbol that
is a "function" in the which-function-mode sense (ada-mode includes type
declarations here). That's assuming the server supports
textDocument/documentSymbol.
It would be more efficient if LSP defined a "containingDeclaration"
query; then you would not have to process the entire syntax tree in lisp
- I'm guessing that will be too slow in large files. Since ada-mode has
complete control over the parser interface, the ada-mode parser provides
that query.
--
-- Stephe
|
No sorry, I wasn't making myself clear. I'm going to try to say more or less the same thing in three different ways :-)
|
You are asking the right questions, I think. But unfortunately, I have lost the answer to this (maybe the Commit log remembers?)
That seems interesting. Especially so if it could somehow magically solve all the other imenu-related issues in addition to this |
@joaotavora I started drafting this implementation in #760. I would appreciate your thoughts about my approach. |
Hi @sfllaw, I briefly tested the latest code with Can double check if anything is missing? |
@joaotavora: It seems to work OK for me as well, so thank you for doing this! Also, I’m glad that you removed the magic closures! |
Fix joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535. Eglot's eglot-imenu returned a structure compliant with the rules outlined in imenu--index-alist. In particular, it returned some elements of the form (INDEX-NAME POSITION GOTO-FN ARGUMENTS...) The original intention (mine) must have been to allow fancy highlighting of the position navigated to with a custom GOTO-FN. Not only was access to that fanciness never implemented, but many other imenu frontends do not support such elements. See for example joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535. And also related issues in other packages: colonelpanic8/flimenu#6 bmag/imenu-list#58 So it's best to remove this problematic feature for now. It can be added back later. * eglot.el (eglot-imenu): Simplify. * NEWS.md: Mention change
Fix joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535. Eglot's eglot-imenu returned a structure compliant with the rules outlined in imenu--index-alist. In particular, it returned some elements of the form (INDEX-NAME POSITION GOTO-FN ARGUMENTS...) The original intention (mine) must have been to allow fancy highlighting of the position navigated to with a custom GOTO-FN. Not only was access to that fanciness never implemented, but many other imenu frontends do not support such elements. See for example joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535. And also related issues in other packages: colonelpanic8/flimenu#6 bmag/imenu-list#58 So it's best to remove this problematic feature for now. It can be added back later. * eglot.el (eglot-imenu): Simplify. * NEWS.md: Mention change
Fix #758, #536, #535. Eglot's eglot-imenu returned a structure compliant with the rules outlined in imenu--index-alist. In particular, it returned some elements of the form (INDEX-NAME POSITION GOTO-FN ARGUMENTS...) The original intention (mine) must have been to allow fancy highlighting of the position navigated to with a custom GOTO-FN. Not only was access to that fanciness never implemented, but many other imenu frontends do not support such elements. See for example #758, #536, #535. And also related issues in other packages: colonelpanic8/flimenu#6 bmag/imenu-list#58 So it's best to remove this problematic feature for now. It can be added back later. * eglot.el (eglot-imenu): Simplify. * NEWS.md: Mention change #758: joaotavora/eglot#758 #536: joaotavora/eglot#536 #535: joaotavora/eglot#535 #758: joaotavora/eglot#758 #536: joaotavora/eglot#536 #535: joaotavora/eglot#535
Fix joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535. Eglot's eglot-imenu returned a structure compliant with the rules outlined in imenu--index-alist. In particular, it returned some elements of the form (INDEX-NAME POSITION GOTO-FN ARGUMENTS...) The original intention (mine) must have been to allow fancy highlighting of the position navigated to with a custom GOTO-FN. Not only was access to that fanciness never implemented, but many other imenu frontends do not support such elements. See for example joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535. And also related issues in other packages: colonelpanic8/flimenu#6 bmag/imenu-list#58 So it's best to remove this problematic feature for now. It can be added back later. * eglot.el (eglot-imenu): Simplify. * NEWS.md: Mention change
Fix joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535. Eglot's eglot-imenu returned a structure compliant with the rules outlined in imenu--index-alist. In particular, it returned some elements of the form (INDEX-NAME POSITION GOTO-FN ARGUMENTS...) The original intention (mine) must have been to allow fancy highlighting of the position navigated to with a custom GOTO-FN. Not only was access to that fanciness never implemented, but many other imenu frontends do not support such elements. See for example joaotavora/eglot#758, joaotavora/eglot#536, joaotavora/eglot#535. And also related issues in other packages: colonelpanic8/flimenu#6 bmag/imenu-list#58 So it's best to remove this problematic feature for now. It can be added back later. * eglot.el (eglot-imenu): Simplify. * NEWS.md: Mention change
which-func assumes that imenu is enabled and determines which function your current point is in using imenu--index-alist.
However, it doesn’t understand special elements in imenu--index-alist so those entries must be handled by a hook installed in
which-func-functions.
eglot.el (eglot-which-func): Hook to determine the function which your current point is in, based on Eglot’s special Imenu element.
eglot.el (eglot--managed-mode): Add and remove the eglot-which-func hook in which-func-functions.
eglot-tests.el (basic-which-func): Test which-function-mode.