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

Feature: Navigate from defdelegate to the function delegated to #126

Closed
axelson opened this issue Feb 15, 2020 · 9 comments · Fixed by #134
Closed

Feature: Navigate from defdelegate to the function delegated to #126

axelson opened this issue Feb 15, 2020 · 9 comments · Fixed by #134
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@axelson
Copy link
Member

axelson commented Feb 15, 2020

May require changes to elixir_sense

@axelson axelson added enhancement New feature or request help wanted Extra attention is needed labels Feb 15, 2020
@lukaszsamson
Copy link
Collaborator

It will require changes in elixir sense. I was planning to do this anyway though.

@axelson
Copy link
Member Author

axelson commented Feb 17, 2020

That sounds good, I created an issue in the elixir_sense repo as well: elixir-lsp/elixir_sense#89

@IvanShpotenko
Copy link

IvanShpotenko commented Oct 12, 2021

So is it possible now to navigate to the delegated function?
If so, how can this be done? Or is there some additional work required to do so?

Currently, it seems like I can only see peek definition (which is displayed correctly).
But as for navigation, I am able to navigate from the function call to the defdelegate definition and then from the defdelegate definition to the module that is delegated to, but from there you’ll have to manually search for the function in question.

Sorry if am missing smth obvious :)

@lukaszsamson
Copy link
Collaborator

@IvanShpotenko use go to implementation instead of go to definition

@IvanShpotenko
Copy link

Thanks, it works! Sorry for the confusion!

@giddie
Copy link

giddie commented Jan 7, 2022

It seems if I'm at the defdelegate site, I need to jump back to the call site and do go-to-implementation to jump through the delegation. Is there a way to jump directly from the delegation to the implementation without jumping back to the call site?

Also, it seems that listing references doesn't work from the function implementation (i.e. the target of the delegation). I'd expect that it would list the defdelegate call(s) as references. Should I be doing something differently, or is this not available yet?

@lukaszsamson
Copy link
Collaborator

It seems if I'm at the defdelegate site, I need to jump back to the call site and do go-to-implementation to jump through the delegation. Is there a way to jump directly from the delegation to the implementation without jumping back to the call site?

You can use go to implementations on the defdelegate site, no need to jump back to call site (I've just verified it and it works for me)

Also, it seems that listing references doesn't work from the function implementation (i.e. the target of the delegation). I'd expect that it would list the defdelegate call(s) as references. Should I be doing something differently, or is this not available yet?

That's a separate issue. Please fill it in elixir_sense repo

@giddie
Copy link

giddie commented Jan 10, 2022

You can use go to implementations on the defdelegate site, no need to jump back to call site (I've just verified it and it works for me)

Ah! OK, I've traced my issue here to an issue with alias resolution:

# lib/test.ex
defmodule Test do
  alias __MODULE__, as: Self
  alias Self.Private

  defdelegate my_function(), to: Private
end

# lib/test/private.ex
defmodule Test.Private do
  def my_function() do
    IO.puts("Hello")
  end
end

It seems that the double-alias involving __MODULE__ breaks resolution, which breaks jump-to-implementation as a side-effect. Where should I report this? Does it go to elixir_sense?

@lukaszsamson
Copy link
Collaborator

Where should I report this? Does it go to elixir_sense?

Yes. If you would like to try adding support for it, the relevant code is in https://github.com/elixir-lsp/elixir_sense/blob/219b4d0fcb27c46dd4dad915ece01ec2b92d0249/lib/elixir_sense/core/metadata_builder.ex#L705

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants