Skip to content

Instantly share code, notes, and snippets.

@randycoulman
Last active August 22, 2023 20:50
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randycoulman/e554a46e31c2c064820d4137c21b3b14 to your computer and use it in GitHub Desktop.
Save randycoulman/e554a46e31c2c064820d4137c21b3b14 to your computer and use it in GitHub Desktop.
Recompiling ElixirLS

When ElixirLS is compiled with a different version of Elixir/Erlang than we use in our projects, it is unable to show pop-up documentation and auto-completion for certain constructs (like imports or requires done by a using block).

To check if you have a version mismatch, you can scroll to the top of the output pane for ElixirLS (VSCode View -> Output, then select ElixirLS from the dropdown list).

ElixirLS v0.13.0 and Later

In v0.13.0, vscode-elixir-ls added the ability to override the default elixirLS release path in config. This allows us to recompile elixirLS with whichever versions of Elixir and Erlang we like and then tell the extension to use that version. It should even be possible to compile with multiple different Elixir/Erlang combinations and use different versions in different projects, though I haven't tried that yet.

Here's how to do this:

# First time only
git clone git@github.com:elixir-lsp/elixir-ls.git
cd elixir-ls

# Second and subsequent times
cd elixir-ls
git pull

# Always
asdf local erlang {desired version}
asdf local elixir {desired version}
asdf install # should do nothing, but just to be safe
mix deps.get
# --force seems to be needed to get the reported version to update
MIX_ENV=prod mix compile --force
# Specify a release dir if you plan to compile for multiple versions
MIX_ENV=prod mix elixir_ls.release # -o {release_dir}

Once built, provide the absolute path to the release directory (default release) as the value of the Elixir LS: Language Server Override Path setting in VSCode.

For more information, see the ElixirLS README.

Elixir LS v0.12.0 and Earlier

It is possible to recompile the extension with the same versions of Elixir and Erlang that we use in our projects as follows. You'll have to do this every time the extension updates itself from the marketplace unless you turn off auto-updating of all extensions.

# First time only
git clone --recursive git@github.com:elixir-lsp/vscode-elixir-ls.git
cd vscode-elixir-lsp

# Second and subsequent times
cd vscode-elixir-lsp
git pull && git submodule update --recursive

# Always
npm install
cd elixir-ls
asdf local erlang {desired version}
asdf local elixir {desired version}
asdf install # should do nothing, but just to be safe
cd ..
rm *.vsix
npx vsce package
code --install-extension *.vsix --force

References

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