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

ElixirLS can't find Elixir installation #408

Closed
TBK145 opened this issue Nov 18, 2020 · 17 comments
Closed

ElixirLS can't find Elixir installation #408

TBK145 opened this issue Nov 18, 2020 · 17 comments

Comments

@TBK145
Copy link

TBK145 commented Nov 18, 2020

Environment

  • Elixir & Erlang versions (elixir --version):
$ elixir --version
Erlang/OTP 23 [erts-11.1.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]

Elixir 1.11.2 (compiled with Erlang/OTP 23)
  • Operating system:
$ uname -srvmo
Linux 5.9.8-arch1-1 #1 SMP PREEMPT Tue, 10 Nov 2020 22:44:11 +0000 x86_64 GNU/Linux
  • Editor or IDE name (e.g. Emacs/VSCode): VS code OSS
  • Editor Plugin/LSP Client name: ElixirLS

Logs

/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en-US)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en-US)
/home/thijs/.vscode-oss/extensions/elixir-lsp.elixir-ls-0.6.2/elixir-ls-release/launch.sh: line 66: exec: elixir: not found
[Info  - 6:43:31 PM] Connection to server got closed. Server will restart.
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en-US)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en-US)
/home/thijs/.vscode-oss/extensions/elixir-lsp.elixir-ls-0.6.2/elixir-ls-release/launch.sh: line 66: exec: elixir: not found
[Info  - 6:43:31 PM] Connection to server got closed. Server will restart.
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en-US)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en-US)
/home/thijs/.vscode-oss/extensions/elixir-lsp.elixir-ls-0.6.2/elixir-ls-release/launch.sh: line 66: exec: elixir: not found
[Info  - 6:43:31 PM] Connection to server got closed. Server will restart.
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en-US)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en-US)
/home/thijs/.vscode-oss/extensions/elixir-lsp.elixir-ls-0.6.2/elixir-ls-release/launch.sh: line 66: exec: elixir: not found
[Info  - 6:43:31 PM] Connection to server got closed. Server will restart.
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en-US)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en-US)
/home/thijs/.vscode-oss/extensions/elixir-lsp.elixir-ls-0.6.2/elixir-ls-release/launch.sh: line 66: exec: elixir: not found
[Error - 6:43:31 PM] Connection to server got closed. Server will not be restarted.

I have Elixir installed with kiex (and Erlang with kerl), however ElixirLS apparently can't find my Elixir installation. After a bit of troubleshooting it seems that the 'launch.sh' is executed as the wrong user, root instead of my own user.

@lukaszsamson
Copy link
Collaborator

There is no su nor sudo in launch.sh. If it's started as a wrong user than it's not an elixit-ls problem. Aren't you running vscode as a wrong user?
Can you check if language server starts from terminal after

cd /path/to/your/project
/path/to/elixir-ls/release/language_server.sh

@AndrewDryga
Copy link

Same here. I fixed it by manually pasting PATH=... to lanch.sh because for some reason it did not use PATH set in ZSH profile. But this fix is just temporary.

@TBK145
Copy link
Author

TBK145 commented Nov 19, 2020

I actually was maybe a bit hasty in claiming it was run as the root user, it's maybe just not picking up the changes I'm making in my bashrc, where I'm sourcing kiex.

I tried creating a ~/.config/elixir_ls/setup.sh where I would source my bashrc or kiex manually, but both approaches also didn't work.

Manually overriding PATH in the launch.sh is a possibility, but that becomes a hassle when switching Elixir versions...

Running the launch.sh script on the root of my (umbrella, in case that matters) project appears to be fine, exit code 0.

@axelson
Copy link
Member

axelson commented Nov 19, 2020

I actually was maybe a bit hasty in claiming it was run as the root user, it's maybe just not picking up the changes I'm making in my bashrc, where I'm sourcing kiex.

Can you try making the changes in your .bash_profile instead?

Running the launch.sh script on the root of my (umbrella, in case that matters) project appears to be fine, exit code 0.

Can you try running the language_server.sh instead? launch.sh is not mean to be run directly.

Working output should look roughly like:

jason@jdesktop /t/e/some_app> ~/.vscode-oss/extensions/jakebecker.elixir-ls-0.6.2/elixir-ls-release/language_server.sh
Content-Length: 106

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Started ElixirLS v0.6.2","type":4}}

Content-Length: 142

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Elixir version: \"1.10.3 (compiled with Erlang/OTP 22)\"","type":4}}

Content-Length: 105

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Erlang version: \"23\"","type":4}}

Content-Length: 132

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"ElixirLS compiled with Elixir 1.8.2 and erlang 21","type":4}}

At which point it should just hang/wait for input. I usually then press "enter" and I get an expected error:

Content-Length: 518

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"\u001B[33mwarning: \u001B[0mUnable to read from device: :invalid_content_length\n  (elixir 1.10.3) lib/stream.ex:1415: Stream.do_resource/5\n  (elixir 1.10.3) lib/stream.ex:1609: Enumerable.Stream.do_each/4\n  (elixir 1.10.3) lib/stream.ex:649: Stream.run/1\n  (stdlib 3.13) erl_eval.erl:680: :erl_eval.do_apply/6\n  (elixir 1.10.3) src/elixir.erl:278: :elixir.recur_eval/3\n  (elixir 1.10.3) src/elixir.erl:263: :elixir.eval_forms/3\n","type":2}}

@TBK145
Copy link
Author

TBK145 commented Nov 20, 2020

Can you try making the changes in your .bash_profile instead?

My .bash_profile sources my .bashrc, so that should work right?

$ ~/.vscode-oss/extensions/elixir-lsp.elixir-ls-0.6.2/elixir-ls-release/language_server.sh
Content-Length: 106

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Started ElixirLS v0.6.2","type":4}}

Content-Length: 139

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Elixir version: \"1.11.2 (compiled with Erlang/OTP 23)\"","type":4}}

Content-Length: 105

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Erlang version: \"23\"","type":4}}

Content-Length: 132

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"ElixirLS compiled with Elixir 1.8.2 and erlang 21","type":4}}


Content-Length: 520

{"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"\u001B[33mwarning: \u001B[0mUnable to read from device: :invalid_content_length\n  (elixir 1.11.2) lib/stream.ex:1415: Stream.do_resource/5\n  (elixir 1.11.2) lib/stream.ex:1609: Enumerable.Stream.do_each/4\n  (elixir 1.11.2) lib/stream.ex:649: Stream.run/1\n  (stdlib 3.13.2) erl_eval.erl:680: :erl_eval.do_apply/6\n  (elixir 1.11.2) src/elixir.erl:280: :elixir.recur_eval/3\n  (elixir 1.11.2) src/elixir.erl:265: :elixir.eval_forms/3\n","type":2}}

@axelson
Copy link
Member

axelson commented Nov 20, 2020

Maybe #!/bin/sh isn't bash on your machine.

@lukaszsamson
Copy link
Collaborator

@TBK145 so it is working fine when run from terminal. VSCode extension just runs language_server.sh so it should inherit PATH env from VSCode process. Can you debug it via adding echo $PATH 1>&2 to language_server.sh?

@lukaszsamson lukaszsamson changed the title ElixirLS can't find Elixir installation, executes launch.sh as wrong user ElixirLS can't find Elixir installation Nov 22, 2020
@TBK145
Copy link
Author

TBK145 commented Nov 23, 2020

I echo'd the path and it returned /usr/local/bin:/usr/local/sbin:/usr/bin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl in the output console.

But my .bash_profile is just doing this: [[ -f ~/.bashrc ]] && . ~/.bashrc, so the PATH should be set correctly by my .bashrc.

@lukaszsamson
Copy link
Collaborator

But my .bash_profile is just doing this: [[ -f ~/.bashrc ]] && . ~/.bashrc, so the PATH should be set correctly by my .bashrc.

Well, I guess it isn't. Here's what it outputs in VSCode on my machine (macOS) when I add this snippet to language_server.sh

#!/bin/sh
# Launches the language server. This script must be in the same directory as the compiled .ez archives.
echo PATH=$PATH 1>&2
echo USER=$USER 1>&2
echo HOME=$HOME 1>&2
echo SHELL=$SHELL 1>&2
...
PATH=/Users/my_user/.asdf/shims:/usr/local/opt/asdf/bin:/Users/my_user/.mix:/Users/my_user/.cargo/bin:/Users/my_user/elixir/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Applications/Wireshark.app/Contents/MacOS:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/my_user/Library/Android/sdk/tools:/Users/my_user/.kiex/bin
USER=my_user
HOME=/Users/my_user
SHELL=/bin/zsh

@TBK145
Copy link
Author

TBK145 commented Nov 23, 2020

I guess my .bash_profile isn't even loaded. I changed it to this:

PATH="$PATH:~/.kiex/elixirs/elixir-1.11.2/bin"

[[ -f ~/.bashrc ]] && . ~/.bashrc

And the language_server.sh still echoed the same PATH as before: /usr/local/bin:/usr/local/sbin:/usr/bin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl

@NobbZ
Copy link
Member

NobbZ commented Nov 24, 2020

Do you start vscode from a shell or from the graphical launcher?

@delameko
Copy link

NobbZ solution should work for loading .bashrc, or setting the "Integrated Shell" option in VSCode to /bin/bash should work for opening it from the icon.

There's few other possible solutions in this post of stack.

@TBK145
Copy link
Author

TBK145 commented Nov 24, 2020

I'm starting vscode from the Gnome 'Activities' button. When I start it from my terminal it works indeed.
Setting "terminal.integrated.shell.linux": "/bin/bash" did load my .bash_profile, but not my .bashrc yet.
InheritEnv was already turned on by default, and adding -l did not change anything.
But when I now make changes to my .bash_profile, they aren't applied to vscode.

@NobbZ
Copy link
Member

NobbZ commented Nov 24, 2020

There is no reason why any program started from your GUI should read your shells configuration.

To mitigate that, the ElixirLS startup script indeed searches at a well known location for a hint whether or not asdf-vm is installed for the user and if it is found, the LS will reload the startup script with asdf enabled.

If you use something else to manage your elixir version than asdf, you either need to make sure to have the correct version selected on the terminal before starting VScode from the terminal.

And if elixir-lsp/vscode-elixir-ls#3 was fixed, you could easily maintain a local fork with a patched launcher which would find any other managed elixir version you like.

If you do not use VScode, but another editor with a more generic LSP client that uses a configured location for the LSP server anyway, you can already today patch accordingly.

@TBK145
Copy link
Author

TBK145 commented Nov 25, 2020

Right, maybe this should be a part of the readme/ installation guide?

Also, I would think that kiex would be part of this startup script as well, as the Readme suggests to install Erlang and Elixir using kerl and kiex: https://github.com/elixir-lsp/elixir-ls#supported-versions

The only thing that's not clear for me yet is why my .bash_profile is now loaded, but my .bashrc isn't apparently.
Nvm, I just found out that my bashrc bails out when not run interactively. That didn't seem to fix it.
I got my it working, after passing "-i" as extra argument, apparently some things in my .bashrc were not supposed to be in quotes when loading from .bash_profile.

Also, when starting from the GUI or the terminal, this $XDG_CONFIG_HOME/elixir_ls/setup.sh isn't run it seems? Is that expected as well?

@axelson
Copy link
Member

axelson commented Nov 29, 2020

@TBK145 $XDG_CONFIG_HOME/elixir_ls/setup.sh is expected to run, are you sure that it is not running? If so please put together some reproduction steps and then file a separate issue.

@lukaszsamson
Copy link
Collaborator

Closing due to lack of OPs response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants