elixir-ls
elixir-ls copied to clipboard
ElixirLS not consistently recompiling dependencies
Environment
- Elixir & Erlang versions (elixir --version): 1.13.0/23.3.1
- Elixir Language Server version: 0.8.2
- Operating system: MacOS Monterey
- Editor or IDE name (e.g. Emacs/VSCode): VSCode
- Editor Plugin/LSP Client name and version: ElixirLS 0.9.0
Current behavior
ElixirLS is, in some cases, not recompiling dependencies after they are updated, forcing manual deletion of dependency in .elixir_ls/build directory. The dependencies have been downloaded correctly to the deps folder, and regular mix compile runs fine at the command prompt, as it has correctly determined the deps need to be recompiled. The issue seems to be that ElixirLS is only trying to recompile the project app and not consistently checking if the deps also need recompiling.
ElixirLS will report that dependencies are not up to date:
Resolving Hex dependencies...
Dependency resolution completed:
Unchanged:
...
All dependencies are up to date
[Warn - 12:01:33 PM] Unchecked dependencies for environment test:
[Warn - 12:01:33 PM] * erlex (Hex package)
[Warn - 12:01:33 PM] the dependency does not match the requirement ">= 0.2.6", got "0.2.5"
[Warn - 12:01:33 PM] * dialyxir (Hex package)
[Warn - 12:01:33 PM] the dependency does not match the requirement "~> 1.1", got "1.0.0-rc.7"
[Warn - 12:01:33 PM] * excoveralls (Hex package)
[Warn - 12:01:33 PM] the dependency does not match the requirement "~> 0.14.4", got "0.12.1"
12:01:33.137 [error] Process #PID<0.370.0> raised an exception
** (Mix.Error) Can't continue due to errors on dependencies
When I got this error message, I verified for erlex that the deps folder did have the correct 0.2.6 version, as did the lock file, however .elixir_ls/build/_test/lib/erlex/ebin/erlex.app listed 0.2.5.
When it is in this state, restarting VSCode does not fix the problem. The only fix is to delete the build folder for the erroring dependencies or the entire .elixir_ls/build directory. For example, I resolved the above error by manually deleting the erlex, dialyxir, and excoveralls directories in .elixir_ls/build/_test/lib.
This issue has been pretty common among projects when getting an updated mix file from git, e.g. swapping between branches that have different mix dependency versions. On my machine, was just able to reproduce this by simply checking out an older version of a project which had these dependencies changed, in my case it was ETS, and swapping between master, v0.8.0 and v0.7.0.
@TheFirstAvenger do you have a reliable way of reproducing it? I hit similar errors with mix but they are difficult to reproduce.
@lukaszsamson the last paragraph has steps to reproduce. Check out that repo and swap between the tags
We're also getting this consistently. As @TheFirstAvenger said it usually happens when switching branches or pulling down an updated mix file. We've tried recompiling deps (with and without --force) and it doesn't help -- the only thing that helps is to remove the .elixir_ls folder completely.
I cannot reproduce the original problem on current master. https://github.com/elixir-lsp/elixir-ls/commit/031bd0a7246dc7f6d6e1077a975b55b2110f209c fixed mix state handling. Now the behavior is different.
- I switch tags on your project
(Mix.Error) Can't continue due to errors on dependencieserror shown- I run
mix deps.get - The error disappears and compilation starts
- Credo dependency fails to build with some random error suggesting conflicts between it's modules
Restarting the server fixes build
I think we need to detect changes to deps and force unload all modules from changed deps.