elixir-ls icon indicating copy to clipboard operation
elixir-ls copied to clipboard

fix: make goto def/refs work when cursor is at end of symbol (#1038)

Open shinohara-rin opened this issue 9 months ago • 3 comments

This PR addresses issue #1038.

This pull request presents a fairly basic approach that relies on retrying with the character to the left of the original one if the first attempt to retrieve definitions/references fails.

Additionally, this PR considers the scenario highlighted in issue #1027, where if the cursor is positioned on the . right to a symbol, it references the function instead of the module. With the changes in this PR, it will reference the module instead.

Below is a video demonstrating the resolution of the issues specified in issue #1027.

https://github.com/elixir-lsp/elixir-ls/assets/25588514/6a2b1226-6881-48f3-982a-a3ad7fddf6a7

shinohara-rin avatar May 07 '24 05:05 shinohara-rin

There are other places where NormalizedCode.Fragment.surround_context is used (hover provider, implementations provider) that would require a similar change. How about wrapping that function and applying the fallback logic once instead of in each provider?

lukaszsamson avatar May 07 '24 06:05 lukaszsamson

Hi @lukaszsamson, we've wrapped NormalizedCode.Fragment.surround_context but not quite sure which module would be the best one to accommodate it...

We temporarily placed it in ElixirLS.LanguageServer.AstUtils.surround_context_with_fallback. Could you advise where would be the most appropriate module for it? Also we're happy to change its name if surround_context_with_fallback doesn't sound good to describe this behaviour.

Other than that, we were also writing some tests for this PR but we had some issue when testing it using mix test. It works as intended in vscode but not in the unit test. We'll be looking into this later today or tomorrow but please let us know if you happen to have any idea why it works in vscode but not in the tests 😃

cocoa-xu avatar May 07 '24 13:05 cocoa-xu

How about CodeFragmentUtils?

lukaszsamson avatar Jun 04 '24 15:06 lukaszsamson