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"
https://elixir-lsp.github.io/elixir-ls/
Apache License 2.0
1.42k stars 189 forks source link

ElixirLS.LanguageServer.MixShell.info/1 and ElixirSense.Core.Source.split_lines/1 undefined when the project uses Elixir 1.16 #1100

Open fschuindt opened 3 weeks ago

fschuindt commented 3 weeks ago

Precheck

Do a quick search and make sure the issue has not yet been reported

Done. Nothing relevant.

Do not use the issues tracker for guidance, questions or support (try Elixir Forum, Stack Overflow, Slack, etc. instead)

I have started a small thread on the Elixir's Slack, but I'm starting to think this might be indeed a bug.

If using a client other than VS Code, please try VSCode's "ElixirLS: Elixir support and debugger" extension. Does it reproduce your failure?

I have tried it, but I wasn't able to make VSCode to identify my Elixir installation. However, I think my description will clarify that this might be related to the version of Elixir, as it works when using other versions.

Environment

Current behavior

If I create a Mix project using Elixir 1.16, the LSP stops working as expected and whenever there's an issue on the code, it starts acting like crashing. It works normally if I use Elixir 1.14. Since on the README.md the 1.16 is listed as fully supported, I figured I would open this.

Using Elixir 1.16

  1. asdf global elixir 1.16.3-otp-25
  2. mix new test_1_16_3 --module Test
  3. Open mix.exs, LSP complains about exception being raised.
  4. Opens the hello.ex file, and introduce a syntax problem, LSP crashes.

Relevant LSP logs:

[...]

[Trace - 11:25:42 PM] Received notification 'window/logMessage'.
Params: {
  "message": "\n23:25:42.266 [error] Process #PID<0.124.0> raised an exception\n** (UndefinedFunctionError) function ElixirLS.LanguageServer.MixShell.info/1 is undefined (module ElixirLS.LanguageServer.MixShell is not available)\n    (language_server 0.8.2) ElixirLS.LanguageServer.MixShell.info(\"Compiling 1 file (.ex)\")\n    (mix 1.16.3) lib/mix/compilers/elixir.ex:163: Mix.Compilers.Elixir.compile/7\n    (mix 1.16.3) lib/mix/state.ex:15: Mix.State.lock/2\n    (mix 1.16.3) lib/mix/task.ex:478: anonymous fn/3 in Mix.Task.run_task/5\n    (mix 1.16.3) lib/mix/tasks/compile.all.ex:122: Mix.Tasks.Compile.All.run_compiler/2\n    (mix 1.16.3) lib/mix/tasks/compile.all.ex:102: Mix.Tasks.Compile.All.compile/4\n    (mix 1.16.3) lib/mix/tasks/compile.all.ex:91: Mix.Tasks.Compile.All.with_logger_app/2\n    (mix 1.16.3) lib/mix/tasks/compile.all.ex:60: Mix.Tasks.Compile.All.run/1",
  "type": 4
}

[...]

[Trace - 11:25:48 PM] Received response 'textDocument/documentSymbol - (9)' in 11ms.
Result: {
  "code": -32000,
  "message": "an exception was raised:\n    ** (UndefinedFunctionError) function ElixirSense.Core.Source.split_lines/1 is undefined (module ElixirSense.Core.Source is not available)\n        (elixir_sense 2.0.0) ElixirSense.Core.Source.split_lines(\"defmodule XSocialAPI.Test do\\n  @moduledoc \\\"\\\"\\\"\\n  Documentation for `XSocialAPI.Test`.\\n  \\\"\\\"\\\"\\n\\n  @doc \\\"\\\"\\\"\\n  Hello world.\\n\\n  ## Examples\\n\\n      iex> XSocialAPI.Test.hello()\\n      :world\\n\\n  \\\"\\\"\\\"\\n  def hello do\\n    :world +\\n  end\\nend\\n\")\n        (elixir_sense 2.0.0) lib/elixir_sense/core/parser.ex:211: ElixirSense.Core.Parser.fix_parse_error/3\n        (elixir_sense 2.0.0) lib/elixir_sense/core/parser.ex:118: ElixirSense.Core.Parser.string_to_ast/5\n        (elixir_sense 2.0.0) lib/elixir_sense.ex:446: ElixirSense.string_to_quoted/4\n        (language_server 0.8.2) lib/language_server/providers/document_symbols.ex:48: ElixirLS.LanguageServer.Providers.DocumentSymbols.list_symbols/1\n        (language_server 0.8.2) lib/language_server/providers/document_symbols.ex:26: ElixirLS.LanguageServer.Providers.DocumentSymbols.symbols/3\n        (language_server 0.8.2) lib/language_server/server.ex:796: anonymous fn/3 in ElixirLS.LanguageServer.Server.handle_request_async/2"
}

[...]

Complete log here.

Picture: image (19)

Expected behavior

Using Elixir 1.14 yields the expected behavior.

Using Elixir 1.14

  1. asdf global elixir 1.14.3-otp-25
  2. mix new test_1_14_3 --module Test
  3. Open mix.exs, LSP says it was successfully initiated.
  4. Opens the hello.ex file, and introduce a syntax problem, LSP highlights the problem as expected.
lukaszsamson commented 3 weeks ago

There is some problem with your env. The functions are definitely defined, see build on elixir 1.16 and OTP 25 https://github.com/elixir-lsp/elixir-ls/actions/runs/9461131788/job/26067861648. The fact that it's crashing like that means that there is a problem earlier with either your shims, elixir, OTP, ElixirLS install or mix cache. This is a giveway:

I have tried it, but I wasn't able to make VSCode to identify my Elixir installation

Some troubleshooting you should try

  1. You haven't posted the most important logs from ElixirLS start and install
  2. How did you install ElixirLS
  3. Please make sure that your shims are correct and VSCode is able to pick them up. It's a common problem on linux
  4. Delete mix cache directories (whatever Mix.Utils.mix_cache() returns on your machine)
  5. You should be able to start ElixirLS from shell when you cd to your project dir with /path/to/elixir-ls/language_server.sh
fschuindt commented 3 weeks ago

You haven't posted the most important logs from ElixirLS start and install

Are you talking about the logs during the starting of the LS? Like so?

How did you install ElixirLS

Please make sure that your shims are correct and VSCode is able to pick them up. It's a common problem on linux

This is the most tricky part for me, I have very little experience with VSCode. The elixir command is available all through my machine, never faced problems with it. I've checked: .bashrc, .bash_profile, .zshrc, .zprofile and .profile, they all seem correct.

If I open VSCode from my program launcher, it will complain about not finding the elixir command:

image I just discovered that, if I cd into the repository and run code ., Elixir and the LSP works fine, this is for the 1.14.3 project:

image And this is for the 1.16.3 project:

image I think that confirms that this is not a bug within the ElixirLS project, so feel free to close my issue. However I'm still clueless on what to do next. Any tips?

Delete mix cache directories (whatever Mix.Utils.mix_cache() returns on your machine)

Done. No noticeable effect.

You should be able to start ElixirLS from shell when you cd to your project dir with /path/to/elixir-ls/language_server.sh

This is cool. I did that to get the starting logs on the different versions I just posted here. Any way to make the editor to use this process instead? Just so I can monitor logs more closely. (Not important)