vscode-elixir-ls icon indicating copy to clipboard operation
vscode-elixir-ls copied to clipboard

Annoying red highlighting of the whole mix.exs

Open crabvk opened this issue 4 years ago • 15 comments

If a project has problems with deps (or some other errors), the whole mix.exs is highlighted red. This is annoying and interferes with editing the file. Is there an option to disable highlighting of mix.exs, or maybe highlight only the first line of it?

crabvk avatar Aug 13 '20 07:08 crabvk

Can you please copy the output from Output tab in vscode to this issue?

wingyplus avatar Aug 15 '20 13:08 wingyplus

Started ElixirLS v0.5.0
Elixir version: "1.10.4 (compiled with Erlang/OTP 23)"
Erlang version: "23"
ElixirLS compiled with Elixir 1.7.4 and erlang 20
MIX_ENV: test
MIX_TARGET: 
[Warn  - 6:38:06 PM] Unchecked dependencies for environment test:
[Warn  - 6:38:06 PM] * telemetry_metrics (Hex package)
[Warn  - 6:38:06 PM]   the dependency is not available, run "mix deps.get"
[Warn  - 6:38:06 PM] * phoenix_live_dashboard (Hex package)
[Warn  - 6:38:06 PM]   the dependency is not available, run "mix deps.get"
[Warn  - 6:38:06 PM] * ecto_sql (Hex package)
[Warn  - 6:38:06 PM]   the dependency is not available, run "mix deps.get"
[Warn  - 6:38:06 PM] * telemetry_poller (Hex package)
[Warn  - 6:38:06 PM]   the dependency is not available, run "mix deps.get"
[Warn  - 6:38:06 PM] * gettext (Hex package)
[Warn  - 6:38:06 PM]   the dependency is not available, run "mix deps.get"
[Warn  - 6:38:06 PM] * jason (Hex package)
[Warn  - 6:38:06 PM]   the dependency is not available, run "mix deps.get"
[Warn  - 6:38:06 PM] * phoenix_html (Hex package)
[Warn  - 6:38:06 PM]   the dependency is not available, run "mix deps.get"
[Warn  - 6:38:06 PM] * phoenix (Hex package)
[Warn  - 6:38:06 PM]   the dependency is not available, run "mix deps.get"
[Warn  - 6:38:06 PM] * postgrex (Hex package)
[Warn  - 6:38:06 PM]   the dependency is not available, run "mix deps.get"
[Warn  - 6:38:06 PM] * plug_cowboy (Hex package)
[Warn  - 6:38:06 PM]   the dependency is not available, run "mix deps.get"
[Warn  - 6:38:06 PM] * phoenix_ecto (Hex package)
[Warn  - 6:38:06 PM]   the dependency is not available, run "mix deps.get"

18:38:06.987 [error] Process #PID<0.126.0> raised an exception
** (Mix.Error) Can't continue due to errors on dependencies
    (mix 1.10.4) lib/mix.ex:392: Mix.raise/1
    (mix 1.10.4) lib/mix/tasks/deps.loadpaths.ex:28: Mix.Tasks.Deps.Loadpaths.run/1
    (mix 1.10.4) lib/mix/task.ex:330: Mix.Task.run_task/3
    (mix 1.10.4) lib/mix/tasks/loadpaths.ex:35: Mix.Tasks.Loadpaths.run/1
    (mix 1.10.4) lib/mix/task.ex:330: Mix.Task.run_task/3
    (mix 1.10.4) lib/mix/tasks/compile.ex:90: Mix.Tasks.Compile.run/1
    (mix 1.10.4) lib/mix/task.ex:330: Mix.Task.run_task/3
    (language_server 0.5.0) lib/language_server/build.ex:204: ElixirLS.LanguageServer.Build.compile/0

crabvk avatar Aug 15 '20 13:08 crabvk

@vyachkonovalov

I had the same problem when I updated few dependencies in original project from github. Red highlighting of the whole mix.exs is a result of problems with dependencies in your project.

jameskentTX avatar Aug 20 '20 11:08 jameskentTX

Is there an option to disable highlighting of mix.exs, or maybe highlight only the first line of it?

This happens when the language server returns an error without a line number. Perhaps the language server client you're using can be configured to show such errors by highlighting only the first line? I know that emac's lsp-mode made a change a month or two ago that made such errors not highlight every single line.

axelson avatar Aug 21 '20 17:08 axelson

@axelson I'm using vscode 1.48.2 with JakeBecker.elixir-ls, what language server client am I using?

crabvk avatar Aug 26 '20 08:08 crabvk

My mixfile (umbrella) is always covered in red. The problems tab seems to indicate it's a problem with elixir-ls.

an exception was raised:
    ** (FunctionClauseError) no function clause matching in String.split/3
        (elixir 1.11.2) lib/string.ex:473: String.split(nil, ":", [])
        (stdlib 3.13.2) erl_eval.erl:680: :erl_eval.do_apply/6
        (stdlib 3.13.2) erl_eval.erl:888: :erl_eval.expr_list/6
        (stdlib 3.13.2) erl_eval.erl:411: :erl_eval.expr/5
        (stdlib 3.13.2) erl_eval.erl:449: :erl_eval.expr/5
        (elixir 1.11.2) src/elixir.erl:280: :elixir.recur_eval/3
        (elixir 1.11.2) src/elixir.erl:265: :elixir.eval_forms/3
        (elixir 1.11.2) lib/code.ex:341: Code.eval_string_with_error_handling/3

cjbottaro avatar Dec 11 '20 14:12 cjbottaro

FWIW, I find that this happens anytime I change a dependency in the mix.exs file (or add something that breaks it). It seems to get the build in a stuck state (as if cached and can't detect new changes past the error?).

Anyway, I can typically resolve by doing rm -rf .elixir_ls/build then reload the window (or manually save the file to trigger ElixirLS to run again)

jjcarstens avatar Dec 11 '20 17:12 jjcarstens

@cjbottaro if that's the full stacktrace then it looks like ElixirLS isn't failing in ElixirLS's code. So my guess is that you have something either in your mix.exs or config.exs that is failing to parse correctly, and might be related to an environment variable. But as @jjcarstens mentions you should try running rm -rf .elixir_ls and restarting your editor first.

axelson avatar Dec 12 '20 18:12 axelson

I have the same issue with the umbrella application. It happens every time when dependencies are changed, which can be quite often. @axelson Could you explain, please, a bit more how it could be related to an environment variable?

dsnipe avatar Apr 13 '21 12:04 dsnipe

Same problem for me with an umbrella project. Just a hunch:

ElixirLS only checks the top-level mix.exs for dependeny changes in order to trigger updates to its internal book keeping concerning dependencies. So when you add a new dependency to one of your apps' mix.exs and install it, it fails to re-evaluate the umbrella project's deps directory.

@jjcarstens solution also works for me.

dersmon avatar Apr 29 '21 07:04 dersmon

bump

ConnorRigby avatar May 20 '21 20:05 ConnorRigby

Question. Is there a way to introduce some environment variable during the mix deps.get that is being run whlie building out .elixir_ls? In my config/config.exs I have this:

config :goth, json: System.get_env("GOOGLE_APPLICATION_CREDENTIALS") |> File.read!()

.. and elixir-ls can't find the environment variable, because that is set via direnv.

If only I can run direnv allow in the terminal/shell session where elixirls is doing its thing, then it might work.

Else I might have to just conditionally |> File.read!() in the config.

lovebes avatar Aug 16 '21 15:08 lovebes

From here https://github.com/JakeBecker/elixir-ls/issues/71#issuecomment-455335633 :

I was able to make this stop happening by changing 2 configuration settings in ElixirLS:

  • uncheck Fetch Deps automatically option
  • changed Project Dir to . (it was empty and had a red error alert around it)

When I restarted VScode the issue was resolved. This does mean that you have to run mix deps.get and deps.compile manually when you make changes, but I kind of prefer that--I know the state of things in my conceptual understanding of my deps :)

This solved the issue for me

That-David-Guy avatar Dec 21 '21 01:12 That-David-Guy

I tried the solution from @That-David-Guy which didn't seem to resolve. Manually removing the entire .elixir_ls/build directory occassionally does fix it for me, but with a large project and a number of dependencies it takes too long to recompile everything. At this point I just always expect the mix.exs file to be red constantly. Even going into that file to bump a version number results in the entire thing going red.

rossvz avatar Jan 03 '22 20:01 rossvz

I wonder how to, in general, debug stuff like this.

I had ElixirLS completely broken for half an hour today, and then I did some random stuff and I fixed it.

It seemed to have failed to parse mix credo output, which, I presume, was complaining about a crash, but I couldn't even see the whole log...

And of course, this UX peculiarity plagues my workflow as well.

cognivore avatar May 23 '22 01:05 cognivore

Duplicate of https://github.com/elixir-lsp/elixir-ls/issues/120

lukaszsamson avatar Oct 07 '22 22:10 lukaszsamson