ElixirLS goes into a compile loop
stoft opened this issue ยท 4 comments
Hi! Thank you for Gleam!
Environment:
VSCode: 1.47.3
ElixirLS extension: 0.5.0 ()
mix_gleam: 0.1.0
Elixir: 1.10.4
Erlang/OTP: 23
Steps to reproduce:
Open the basic_project in this repo in VSCode.
ElixirLS goes into a compile loop. If I remove :gleam
from Project compilers in mix.exs then it completes.
The ElixirLS output loop looks like this:
[Info - 6:26:06 PM] Compile took 1667 milliseconds
MIX_ENV: test
MIX_TARGET:
[Info - 6:26:06 PM] [ElixirLS WorkspaceSymbols] 0 modules need reindexing
[Info - 6:26:06 PM] [ElixirLS WorkspaceSymbols] 0 modules added to index
[Info - 6:26:06 PM] [ElixirLS WorkspaceSymbols] 0 functions added to index
[Info - 6:26:06 PM] [ElixirLS WorkspaceSymbols] 0 types added to index
[Info - 6:26:06 PM] [ElixirLS WorkspaceSymbols] 0 callbacks added to index
Compiling basic_project
Done!
Compiling 1 file (.erl)
Compiling 1 file (.ex)
[Info - 6:26:06 PM] [ElixirLS Dialyzer] Done writing manifest in 2374 milliseconds.
[Info - 6:26:06 PM] Compile took 772 milliseconds
[Info - 6:26:06 PM] [ElixirLS WorkspaceSymbols] Updating index...
[Info - 6:26:06 PM] [ElixirLS Dialyzer] Checking for stale beam files
[Info - 6:26:07 PM] [ElixirLS Dialyzer] Found 2 changed files in 37 milliseconds
[Info - 6:26:07 PM] [ElixirLS Dialyzer] Analyzing 0 modules: []
[Info - 6:26:07 PM] [ElixirLS Dialyzer] Analysis finished in 42 milliseconds
MIX_ENV: test
MIX_TARGET:
[Info - 6:26:08 PM] [ElixirLS Dialyzer] Writing manifest...
Compiling basic_project
Done!
Compiling 1 file (.erl)
Compiling 1 file (.ex)
[Info - 6:26:08 PM] [ElixirLS WorkspaceSymbols] 0 modules need reindexing
[Info - 6:26:08 PM] [ElixirLS WorkspaceSymbols] 0 modules added to index
[Info - 6:26:08 PM] [ElixirLS WorkspaceSymbols] 0 functions added to index
[Info - 6:26:08 PM] [ElixirLS WorkspaceSymbols] 0 types added to index
[Info - 6:26:08 PM] [ElixirLS WorkspaceSymbols] 0 callbacks added to index
[Info - 6:26:08 PM] Compile took 1176 milliseconds
Disabling Dialyzer makes no difference.
With verbose ElixirLS logging I'm seeing examples of the below right after compilation:
[Trace - 9:14:12 PM] Sending notification 'workspace/didChangeWatchedFiles'.
Params: {
"changes": [
{
"uri": "file:///Users/rala/Projects/elixir/mix_gleam/test_projects/basic_project/gen/src/basic_project.erl",
"type": 2
}
]
}
This leads me to believe that something is touching the gleam compilation output file afterwards, which triggers a new round of compilation.
I'm unsure whether this is an issue with the gleam compiler, mix_gleam, VSCode-ElixirLS or ElixirLS. With some guidance I may be able to help out more (but my spare time is limited due to my current family situation).
Hiya! It looks like the ElixirLS is detecting the generated Erlang created by the Gleam compiler and is triggering compilation again. ElixirLS will need to ignore the gen
directory to avoid this.
A later version of Gleam will change where Erlang is written to so this shouldn't be a problem after that point, but ElixirLS will need to handle it until then.
Thanks for the quick reply! Makes sense.
I searched a bit but couldn't find an ignore option in ElixirLS so I solved it with this simple workaround, that excludes the gleam compiler when ElixirLS is running. Since ElixirLS will most likely only run in a developer context and the :dev
environment includes the gleam compiler, gleam code should already be up to date when ElixirLS compiles the rest.
Mix.exs (golf version, could be replaced with a proper if-else block):
compilers: ((Mix.env() == :elixirls && []) || [:gleam]) ++ Mix.compilers(),
VSCode settings:
"elixirLS.mixEnv": "elixirls"
In a more complex project (e.g. in my Phoenix project) a config/elixirls.exs
is needed. This could simply import one of the others:
use Mix.Config
import_config "test.exs"
Ran into this issue as well but it turns out I could have emacs ignore whatever. Maybe this issue would be useful for others.
For anybody coming to this now, changing compilers
in mix.exs
no longer works.
Do this instead:
mix.exs:
Change this:
aliases: MixGleam.add_aliases(aliases()),
To this:
aliases: (Mix.env() == :elixirls && []) || MixGleam.add_aliases(aliases()),
VSCode settings:
"elixirLS.mixEnv": "elixirls"