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 not consistently recompiling dependencies #688

Closed
TheFirstAvenger opened this issue Apr 15, 2022 · 4 comments · Fixed by #777
Closed

ElixirLS not consistently recompiling dependencies #688

TheFirstAvenger opened this issue Apr 15, 2022 · 4 comments · Fixed by #777
Labels
bug Something isn't working

Comments

@TheFirstAvenger
Copy link

TheFirstAvenger commented Apr 15, 2022

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.

@lukaszsamson
Copy link
Collaborator

@TheFirstAvenger do you have a reliable way of reproducing it? I hit similar errors with mix but they are difficult to reproduce.

@TheFirstAvenger
Copy link
Author

@lukaszsamson the last paragraph has steps to reproduce. Check out that repo and swap between the tags

@hfjallemark
Copy link

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.

@lukaszsamson lukaszsamson added bug Something isn't working and removed waiting for information labels Nov 6, 2022
@lukaszsamson
Copy link
Collaborator

lukaszsamson commented Nov 6, 2022

I cannot reproduce the original problem on current master. 031bd0a fixed mix state handling. Now the behavior is different.

  1. I switch tags on your project
  2. (Mix.Error) Can't continue due to errors on dependencies error shown
  3. I run mix deps.get
  4. The error disappears and compilation starts
  5. 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.

lukaszsamson added a commit that referenced this issue Nov 26, 2022
Purge all modules from changed and removed deps, remove from code paths
Fixes #120
Fixes #688
lukaszsamson added a commit that referenced this issue Nov 26, 2022
* update readme

* run formatter

* Unload changed deps

Purge all modules from changed and removed deps, remove from code paths
Fixes #120
Fixes #688

* run ci on ubuntu 20.04

22.04 is OTP  >= 24

* fix warnings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants