No errors and warnings in VSCode

Hello everyone,

I’ve installed Elixir with asdf and everything works fine so far except the linting. I’m not able to get a warning or problem linting with the VSCode ElixirLS plugin. I have a large Phoenix project which had warnings in the past but the warnings disappeared since I’m using asdf.

Here is a small example code from a dummy project:

defmodule BlaTest do
  use ExUnit.Case
  doctest Bla

  test "greets the world" do
    some_variable = 5

    assert Bla.hello() == :world
  end
end

When I run mix test I get a warning in the terminal: warning: variable “some_variable” is unused (if the variable is not meant to be used, prefix it with an underscore)

I expect this also with ElixirLS in my editor.

What I have tried so far

  • Reinstalling the ElixirLS plugin
  • Tested Erlang 24.3.4.5, 25.0.3, 25.0.4
  • Tested Elixir 1.13.4-otp-25, 1.14.0, 1.14.0-otp-24, 1.14.0-otp-25
  • The Output terminal in VSCode doesn’t show any errors. Dialyzer is working there.
  • I’ve used Dialyxir with mix dialyzer but I haven’t gotten any warnings.
  • I have an existing .elixir_ls folder in my project with a dialyzer_tmp folder and a dialyzer_manifest file.
  • I’ve replicated the code in Elixir LS not showing warnings . Similar to the post creator, I get no warnings.

There’s a few considerations here. Elixir has to-be-compiled files (.ex) and script files (.exs). Warnings are only shown when one of those files are compiled by the compiler.

.ex files are only compiled if their individual contents had changed since the last time they were compiled. This means if you run mix compile twice in a row without changes to any file in between warnings will only show up on the first run and not on the second.

For .exs files compilation happens whenever script files are compiled by code using them. When you run mix test you’ll see warning for issues in test files, because the script files are compiled and executed by the test runner. Given tests files are .exs files and also not in a load elixirrc_path they’re not compiled when doing mix compile, so warning also won’t show up for the latter command.

Now to elixir-ls. Its integration can show you the warnings it sees when running (probably mix compile) and also only the ones reported the last time the command was run, as there’s no manifest keeping track of warnings and if they have been resolved. Compiling your whole project on each change would help somewhat, but is unlikely to be fast enough to be a viable option. It also still won’t catch all warnings as some script files in your project might not be compiled and also elixir-ls runs in a configured MIX_ENV, so all code not available to that MIX_ENV also won’t be compiled and therefore not be reported for.

2 Likes

What I have done to always have the right version of elixir-ls:

  1. Clone GitHub - elixir-lsp/elixir-ls: A frontend-independent IDE "smartness" server for Elixir. Implements the "Language Server Protocol" standard and provides debugger support via the "Debug Adapter Protocol" on your computer. For instance in $HOME/opt/elixir-ls

  2. add a bash script with the following:

    mix elixir_ls.release -o ~/.vscode/extensions/jakebecker.elixir-ls-0.11.0/elixir-ls-release
    
  3. call your bash script.

Beware, sometimes elixirLS is updated, and the path changes ( current is jakebecker.elixir-ls-0.11.0 ) because the version changes.

After the script, you will have ElixirLS compiled with your versions of Elixir/Erlang.

That will solve problems caused by version mistmatch, but it will not address other cases listed by @LostKobrakai