Skip to content
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

Go to definition should jump to the start of the identifier(e.g. myFunc) instead of the keyword (e.g. def) #1088

Closed
shinohara-rin opened this issue May 7, 2024 · 2 comments

Comments

@shinohara-rin
Copy link

Current behaviour

Use Go to Definition on a function will jump to the start of def keyword of the function, instead of the function identifier.
For example when jumping to the definition to foo, it will land the cursor at the start of def like this:

    def foo() do
    ^

current behavior

This is same for modules, macros and etc.

The problem

While the current behaviour is okay to use, it seems to me that it would be more appropriate to jump to the actual identifier of the definition instead of the leading keyword, like most language server implementations did.

For example this is how JavaScript language server handles Go to Definition:
javascript

And Python too:
python

Expected behaviour

Instead of landing on def, it should land on the start of foo like this:

    def foo() do
        ^
@lukaszsamson
Copy link
Collaborator

Locating symbols is actually pretty complex. This code is doing the job https://github.com/elixir-lsp/elixir-ls/blob/master/apps/language_server/lib/language_server/location.ex for functions and types. There are 2 mechanisms - 1 relying on doc chunks for compiled modules and other on metadata extracted from AST for current buffer code. While AST is easier to modify as we have control over what we extract, docs are quite limited. Docs actually store the position of @(type|module)?doc attribute, not the def/module/type. A possible approach would be to either extract the correct positions via regex or use the AST in both cases and only fall back to docs if AST extraction fails to find the position.
Also keep in mind that the standard asks to return ranges https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_definition https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#location. We need that to fully address
#1042

@lukaszsamson
Copy link
Collaborator

Closing as this is already tracked in #1042

@lukaszsamson lukaszsamson closed this as not planned Won't fix, can't repro, duplicate, stale Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants