ElixirLS server initialization failed

I just started trying Elixir today and configuring the dev environment in vscode and got this error.

Here is some basic information below :

Erlang/OTP 24 [erts-12.2.1] [source] [64-bit] [smp:20:20] [ds:20:20:10] [async-threads:1] [jit]
Elixir 1.12.2 (compiled with Erlang/OTP 24)

I created a project following this tutorial https://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html

After installing this vscode plugin " ElixirLS: Elixir support and debuggerv0.14.5"

I got this error message.

could not compile dependency :sourceror, “mix compile” failed. You can recompile this dependency with “mix deps.compile sourceror”, update it with “mix deps.update sourceror” or clean it with “mix deps.clean sourceror”
[Error - 21:37:22] Server initialization failed.
Message: Pending response rejected since connection got disposed
Code: -32097
[Info - 21:37:22] Connection to server got closed. Server will restart.
true
[Error - 21:37:22] ElixirLS - kv client: couldn’t create connection to server.
Message: Pending response rejected since connection got disposed
Code: -32097

I googled similar issues and no solution fixed my problem interestingly, there is no “.elixir_ls/” in the project root.
I think this must be a really trivial mistake and it took me 3 hours

Try creating a dummy project and adding {:sourceror, "~> 0.12.2"} to dependencies, then get and compile it with mix deps.get && mix deps.compile and tell us if it’s successful or not.

Thank you so much for your help.
After adding the dependencies and compiling as instructed

mix deps.get
Resolving Hex dependencies…
Resolution completed in 0.006s
Unchanged:
sourceror 0.12.2

  • Getting sourceror (Hex package)

mix deps.compile
==> sourceror
Compiling 10 files (.ex)
warning: Sourceror.Code.Formatter.to_algebra/2 is undefined (module Sourceror.Code.Formatter is not available or is yet to be defined)
lib/sourceror/code.ex:78: Sourceror.Code.quoted_to_algebra/2

warning: Sourceror.Code.Normalizer.normalize/2 is undefined (module Sourceror.Code.Normalizer is not available or is yet to be defined)
lib/sourceror/code.ex:77: Sourceror.Code.quoted_to_algebra/2

warning: :sourceror_elixir.string_to_tokens/5 is undefined (module :sourceror_elixir is not available or is yet to be defined)
lib/sourceror/code.ex:21: Sourceror.Code.string_to_quoted_with_comments/2

warning: :sourceror_elixir.tokens_to_quoted/3 is undefined (module :sourceror_elixir is not available or is yet to be defined)
lib/sourceror/code.ex:22: Sourceror.Code.string_to_quoted_with_comments/2

warning: :sourceror_errors.parse_error/4 is undefined (module :sourceror_errors is not available or is yet to be defined)
lib/sourceror/code.ex:37: Sourceror.Code.string_to_quoted_with_comments!/2

warning: Mix.Tasks.Format.formatter_for_file/1 is undefined or private. Did you mean one of:

  * formatter_opts_for_file/1
  * formatter_opts_for_file/2

lib/sourceror.ex:921: Sourceror.locals_without_parens/0

Generated sourceror app

I think I’ve added the sourceror successfully, however, I still got the error message :

could not compile dependency :sourceror, “mix compile” failed. You can recompile this dependency with “mix deps.compile sourceror”, update it with “mix deps.update sourceror” or clean it with “mix deps.clean sourceror”
[Error - 00:42:42] Server initialization failed.
Message: Pending response rejected since connection got disposed
Code: -32097
[Error - 00:42:42] The ElixirLS - kv server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
[Error - 00:42:42] ElixirLS - kv client: couldn’t create connection to server.
Message: Pending response rejected since connection got disposed
Code: -32097
[Error - 00:42:42] Restarting server failed
Message: Pending response rejected since connection got disposed
Code: -32097

The dummy project is created using

mix new kv

I think I’ve added the sourceror successfully, however, I still got the error message

Yes you did, however there’s quite a number of warnings as well as you can see. From the sourceror README it reads that they DO support your version of Elixir and OTP, but as a first poke you could try installing fresher versions of each via ASDF package manager (very convenient and supports a lot of tools other than Elixir/OTP). After removing your old installations of Elixir and Erlang and installing ASDF following the instructions on their website:

asdf plugin-add elixir
asdf plugin-add erlang
asdf install erlang 25.3
asdf install elixir 1.14.4-otp-25
asdf global erlang 25.3
asdf global elixir 1.14.4-otp-25 
1 Like

It looks like elixir-ls don’t even started. I don’t use vs code but maybe you could try to clone and build elixir-ls locally. It is in this repo GitHub - elixir-lsp/elixir-ls: A frontend-independent IDE "smartness" server for Elixir. Implements the "Language Server Protocol" standard and provides debugger support via the "Debug Adapter Protocol", for starter maybe just try deps.get, compile and iex -S mix. Maybe even details about your laptop like os and architecture can be useful, If I remember right, vs code elixir-ls plugin is boundling already build version of elixir-ls.

It works now and thanks so much for your help!
There is some other issue I’d like to mention …
After installing asdf

OS:
Linux h 5.19.0-40-generic #41~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 31 16:00:14 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

SHELL:
fish, version 3.3.1

ASDF VERSION:
v0.11.3-0adc6c1

ASDF ENVIRONMENT VARIABLES:
ASDF_DIR=/home/me/.asdf

For some reason, most of the files in the folder .asdf/shims folder look like this

exec ./bin/asdf exec “erlc” “$@” # asdf_allow: ’ asdf ’

which actually should be

exec /home/me/.asdf/bin/asdf exec “elixir” “$@” # asdf_allow: ’ asdf ’
apparently, there is no bin folder inside this shims folder…

just cannot believe why this kind of matured toolkit makes this mistake.
probably there is something fundamentally wrong with my OS configuration…

Mine point at the correct locations, but I can’t comment on this, I don’t know much about ASDF and bash scripting. Glad to hear it worked out for you!

Why would you include sourceror in your project deps? Btw you are using a not supportd elixir and otp combination. Eithe update elixir o downgrade otp.

I have a similar problem (but with a supported version: Elixir 1.13.4 (compiled with Erlang/OTP 24).

It always says the same when starting VS Code.

could not compile dependency :sourceror, “mix compile” failed. You can recompile this dependency with “mix deps.compile sourceror”, update it with “mix deps.update sourceror” or clean it with “mix deps.clean sourceror”

The thing is - I don’t have this dependency in my workspace, never had and I don’t need it. But I cannot clean it. Any restarts, deleting of deps etc. didn’t work. Do you have any other ideas how to solve this?

Do you have hex installed? See ElixirLS - linked_list client: couldn't create connection to server. · Issue #339 · elixir-lsp/vscode-elixir-ls · GitHub
Can you try cleaning up your mix install cache directory (you can get it with Mix.Utils.mix_cache())

I have the same sourceror warnings in my lsp logs (running in neovim). No matter what folder I remove (including the mix cache directory as you suggested), the warning keeps coming back. But the LSP works, so it’s not breaking anything for me. In addition to the final warning as shown before, I also have several of these warnings preceding:

warning: redefining module Sourceror (current version loaded from ~/.local/share/lvim/mason/packages/elixir-ls/sourceror-0.11.2.ez/sourceror-0.11.2/ebin/Elixir.Sourceror.beam)\n  lib/sourceror.ex:1\n

(this warning is repeated for a few Sourceror modules).

It’s not clear to me, @la_219, what the observed malfunctioning is, except from the warnings.

Thank you for your quick reply! I tried it but it didn’t help. In the end, I downgraded the VS Code extension and that fixed it for me. So the chances that it is a problem in the extension and not in the LS itself are pretty high.