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

definition not able to locate elixir sources on some ocasions #44

Closed
justindotpub opened this issue Aug 25, 2019 · 16 comments
Closed

definition not able to locate elixir sources on some ocasions #44

justindotpub opened this issue Aug 25, 2019 · 16 comments

Comments

@justindotpub
Copy link

Should ElixirSense.definition/3 be able to handle modules that are provided with Elixir, like GenServer? See https://github.com/balduncle/playground/blob/master/test/playground_test.exs for 3 tests that are currently failing due to the paths to the source files for built in modules not existing on my computer and instead being associated with the machine Elixir was built on. Note that the Enum test comes straight from the docs on hex.

Thanks.

@justindotpub
Copy link
Author

justindotpub commented Aug 25, 2019

In case it is helpful, that repo has Rexbug printing out a trace to help quickly see each function's arguments and return value.

@justindotpub
Copy link
Author

I see now that if I install elixir from source (e.g. with asdf install elixir ref:HEAD) the tests pass. Would it make sense to 1) call this out in the docs, and 2) consider returning something else that more clearly states why the definition wasn't found?

@msaraiva
Copy link
Collaborator

msaraiva commented Sep 5, 2019

@balduncle yes, we can only "find definition" or "go to definition" if Elixir was installed from source. Not sure if there's another way to do this. Maybe we could accept an option like src_path and then users could just download the source and set the option. Ideally, I think the editor could even ask the user if he wants the source to be downloaded and automatically set the option whenever the editor needs to find definitions. Since this will demand work on the editor plugins side, we would need confirmation from those projects maintainers if they are willing to do those changes.

  1. call this out in the docs

We should definitely have that explicit in the docs, however, remember that the end-user doesn't even know that he should read ElixirSense's docs when something doesn't work as expected, he just uses the editor that uses a plugin that uses ElixirSense under the hood.

  1. consider returning something else that more clearly states why the definition wasn't found?

I'm open to suggestions here ;)

@justindotpub
Copy link
Author

Yeah, I like the idea of having the editors download the source. It would alleviate tickets like JakeBecker/vscode-elixir-ls#123. I'm willing to try to tackle this for vscode-elixir-ls, for what it's worth.

Fair point on the docs being more valuable for end users if present in a library that calls into ElixirSense.

@khanakia
Copy link

khanakia commented Nov 7, 2021

@msaraiva any update on this?
I tried to install from source asdf install elixir ref:HEAD but Go To Definition is still not working

@lukaszsamson
Copy link
Collaborator

@khanakia can yo debug it with?

iex(3)> Enum.module_info[:compile][:source]
'/Users/me/elixir/lib/elixir/lib/enum.ex'

on my machine the sources are in the directory that is returned (I don't use asdf, I build elixir myself)

head -n 1 /Users/me/elixir/lib/elixir/lib/enum.ex 
defprotocol Enumerable do

@khanakia
Copy link

khanakia commented Nov 7, 2021

@lukaszsamson

iex(2)> Enum.module_info[:compile][:source]
'/home/build/elixir/lib/elixir/lib/enum.ex'
iex(3)> 

The above path does not exists. But i verified this path exists /Users/khanakia/.asdf/installs/elixir/1.12.3-otp-24/lib/elixir/lib/enum.ex

My binaries are located in this folder

/Users/khanakia/.asdf/shims/iex
/Users/khanakia/.asdf/shims/elixir

How can I change the path to point the elixir to a new path?

@lukaszsamson lukaszsamson changed the title Possible bug in ElixirSense.definition/3 definition not able to locate elixir sources on some ocasions Nov 7, 2021
@khanakia
Copy link

khanakia commented Nov 7, 2021

@lukaszsamson So paths are correct now after I compiled with source. This is the new path it's showing now

iex(1)> Enum.module_info[:compile][:source]
'/Users/khanakia/D1/elixir/lib/elixir/lib/enum.ex'
iex(2)> 

But Go to definition still not works as you can see in the attached screenshot
Screenshot 2021-11-07 at 2 08 09 PM

@khanakia
Copy link

khanakia commented Nov 7, 2021

@lukaszsamson Also i just reinstalled the elixir-ls vscode extension and I can see now the extension is not loaded at all and the reason extension looks for a binary under asdf path but as I compiled the binaries manually so they exist in the different path now.

As https://github.com/elixir-lsp/vscode-elixir-ls required the elixir to be installed using the asdf path.

Refer to this issue. elixir-lsp/vscode-elixir-ls#208

Show how did you make it work with the custom build then as vscode extension requires asdf LOL ?

@khanakia
Copy link

khanakia commented Nov 7, 2021

I have fixed the issue. Here are the steps

  1. Download the source code zip from here https://github.com/elixir-lang/elixir/releases/tag/v1.12.3
  2. Unzip the file and rename it to elixir
  3. cd elixir
  4. make clean test
  5. Edit .bashrc or .zshrc file and it should be like this
. $HOME/.asdf/asdf.sh
export PATH=$PATH:/Users/khanakia/.asdf/shims
export PATH="$PATH:/Users/khanakia/D1/elixir/bin"
  1. Make sure you do not have elixir installed using asdf
  2. Run these commands
asdf global elixir path:/Users/khanakia/D1/elixir
asdf plugin add elixir
  1. Verify the asdf plugins by running asdf current and this will output
elixir          path:/Users/khanakia/D1/elixir /Users/khanakia/.tool-versions
erlang          24.1.4          /Users/khanakia/.tool-versions
  1. Confirm elixir -v
Erlang/OTP 24 [erts-12.1.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Elixir 1.12.3 (compiled with Erlang/OTP 24)
  1. Now you can open the vscode with elixir-ls plugin installed and it will fetch the core function definition e.g. IO.puts("demo") I can simply click the puts and it will open the IO code file

@Sky0307
Copy link

Sky0307 commented Jan 6, 2022

Must I install elixir via asdf to use this? Im an Intel Mac user, I installed elixir via brew. And i have the same problems that i cant use the Go to Definition function with the VS Code extension

@Sky0307
Copy link

Sky0307 commented Jan 6, 2022

I have fixed the issue. Here are the steps

  1. Download the source code zip from here https://github.com/elixir-lang/elixir/releases/tag/v1.12.3
  2. Unzip the file and rename it to elixir
  3. cd elixir
  4. make clean test
  5. Edit .bashrc or .zshrc file and it should be like this
. $HOME/.asdf/asdf.sh
export PATH=$PATH:/Users/khanakia/.asdf/shims
export PATH="$PATH:/Users/khanakia/D1/elixir/bin"
  1. Make sure you do not have elixir installed using asdf
  2. Run these commands
asdf global elixir path:/Users/khanakia/D1/elixir
asdf plugin add elixir
  1. Verify the asdf plugins by running asdf current and this will output
elixir          path:/Users/khanakia/D1/elixir /Users/khanakia/.tool-versions
erlang          24.1.4          /Users/khanakia/.tool-versions
  1. Confirm elixir -v
Erlang/OTP 24 [erts-12.1.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Elixir 1.12.3 (compiled with Erlang/OTP 24)
  1. Now you can open the vscode with elixir-ls plugin installed and it will fetch the core function definition e.g. IO.puts("demo") I can simply click the puts and it will open the IO code file

i tried these steps, however im stucked at step 4, i got the following error after running the command make clean test

rm -rf ebin
rm -rf lib//ebin
rm -rf lib/elixir/src/elixir_parser.erl
rm -rf lib/
/_build/
rm -rf lib/*/tmp/
rm -rf lib/elixir/test/ebin/
rm -rf lib/mix/test/fixtures/deps_on_git_repo/
rm -rf lib/mix/test/fixtures/git_rebar/
rm -rf lib/mix/test/fixtures/git_repo/
rm -rf lib/mix/test/fixtures/git_sparse_repo/
rm -f erl_crash.dump
rm -f man/elixir.1
rm -f man/elixir.1.bak
rm -f man/iex.1
rm -f man/iex.1.bak
make: erlc: No such file or directory
make: *** [lib/elixir/src/elixir_parser.erl] Error 1

@Sky0307
Copy link

Sky0307 commented Jan 6, 2022

Can i ask the if go to definition function will only on default function such IO.inspect etc?

Currently i can see the definition of IO.inspect, IO.puts etc.

But, I have a helper.ex file and when i import it into another file(example, users.ex), i can't see the definition of the functions that is in the helper.ex from the users.ex file, is this normal?

@khanakia
Copy link

khanakia commented Jan 6, 2022

@Sky0307 the steps i gave once you perform VS Code Go To Definition will work for everything.

Regarding helper.ex you cannot inspect because you did not compile the file using elixirc. So there are 2 ways:

  1. Compile the helper.ex file within the same directory and then you will see the VS Code Definition
  2. Use mix to create a project. That the most common approach everybody uses.

@Sky0307
Copy link

Sky0307 commented Jan 7, 2022

@khanakia Thanks for your help! I actually created my project with mix.
Anyway, I managed to get the extension working!
Here's a few things I did, hope it will help others who facing the same issue.

I am an Intel Mac user, I installed both elixir and asdf with brew.

Then, I did the following:

  1. edit .zshrc file

. /usr/local/opt/asdf/libexec/asdf.sh
export PATH=$PATH:/Users/skylee/.asdf/shims
export PATH="$PATH:/usr/local/Cellar/elixir/1.13.1"

  1. run the command

asdf global elixir path:/usr/local/Cellar/elixir/1.13.1/
asdf plugin add elixir

  1. asdf current gives me the following output

elixir path:/usr/local/Cellar/elixir/1.13.1/ /Users/skylee/.tool-versions
erlang path:/usr/local/Cellar/erlang/24.2/ /Users/skylee/.tool-versions

On top of this, I compiled my project with elixir -S mix phx.server

@samaaron
Copy link

samaaron commented Dec 18, 2022

Hi there,

has anyone figured out how to get the language server to find sources on Windows? I see:

Elixir sources not found (checking in d:/home/runner/work/elixir/elixir

I installed Elixir using the standard installer which puts it in the program files directory (I assume with no source). I'd be happy to manually download the source and configure a pointer to it if that's a possibility.

(Note that d:/home/ is not a valid directory on my machine. I'm not sure where it's getting that path from).

(Additionally, asdf isn't available for Windows and building Elixir from source on Windows appears to be non-trivial - although I'd love to be proved wrong).

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

6 participants