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.46k stars 192 forks source link

v0.22.1 can not logger format liveview projects #1110

Open NoBrainSkull opened 1 month ago

NoBrainSkull commented 1 month ago

Environment

Elixir 1.17.2 (compiled with Erlang/OTP 27)


and

Erlang/OTP 26 [erts-14.2.1] [source] [64-bit] [smp:24:24] [ds:24:24:10] [async-threads:1] [jit:ns]

Elixir 1.16.3 (compiled with Erlang/OTP 26)


* Elixir Language Server version: v0.22.1
* Operating system: Archlinux
* Editor or IDE name (e.g. Emacs/VSCode):  Neovim
* Editor Plugin/LSP Client name and version: nvim-lsp

### Current behavior

Calling the LSP format function will fail with the following : 

(Mix.Error) Formatter plugin Phoenix.LiveView.HTMLFormatter cannot be found



[For some reason, the `&Code.ensure_loaded?/1` call in the `&load_plugins` function returns false for the `LiveView.HTMLFormatter` in this version
](https://github.com/elixir-lsp/elixir-ls/blob/master/apps/language_server/lib/language_server/mix_tasks/format.ex#L301)

### Expected behavior

Reverting `elixir-ls` to v0.22.0 fixes the problem entirely, with no observed impact from Elixir/OTP version.
lukaszsamson commented 1 month ago

I cannot reproduce that. Formatting a live_view project works on my machine. Note that there were no changes that could affect formatting between v0.22.0 and v0.22.1. Do you have a project that reproduces it reliably?

NoBrainSkull commented 1 month ago

Sure, please find the link below.

I must add that for 1 second I thought that reverting to v0.22.0 and upgrading again to v0.22.1 solved the issue but removing .elixir_ls, deps/ and build made it appear again (after reinstalling, deps and compiling).

Here is the full output I'm having :

LSP[elixirls] Unable to find formatter for /home/no_brain_skull/src/ex17ls/.formatter.exs: "** 
        (Mix.Error) Formatter plugin Phoenix.LiveView.HTMLFormatter cannot be found
        (mix 1.15.0) lib/mix.ex:577: Mix.raise/2
    (language_server 0.22.1) lib/language_server/mix_tasks/format.ex:302: anonymous fn/2 in Mix.Tasks.ElixirLSFormat.load_plugins/1
    (elixir 1.15.0) lib/enum.ex:2510: Enum.\"-reduce/3-lists^foldl/2-0-\"/3
    (language_server 0.22.1) lib/language_server/mix_tasks/format.ex:299: Mix.Tasks.ElixirLSFormat.load_plugins/1
    (language_server 0.22.1) lib/language_server/mix_tasks/format.ex:362: Mix.Tasks.ElixirLSFormat.formatter_for_file/2
    (language_server 0.22.1) lib/language_server/source_file.ex:277: ElixirLS.LanguageServer.SourceFile.formatter_for/3
    (language_server 0.22.1) lib/language_server/providers/formatting.ex:13: ElixirLS.LanguageServer.Providers.Formatting.format/4
    (language_server 0.22.1) lib/language_server/server.ex:1280: anonymous fn/3 in ElixirLS.LanguageServer.Server.handle_request_async/2"

And here is the reproduction repo. It's a freshly generated liveview app with nothing special.

lukaszsamson commented 1 month ago

@NoBrainSkull Formatting works for me with your repo. Tested on macOS VSCode v0.22.1, elixir 1.17.2, OTP 26

NoBrainSkull commented 1 month ago

Well I guess the problem is on my end then... For the records, I'm using neovim and installed elixir-ls through Mason.

I do have the problem but I'm fine staying on the v0.22.0 for now. I suggest closing this issue and maybe reopening if someone else has a similar problem ?

Thank you for your time !

jamilabreu commented 1 month ago

I'm also getting the same error at times, and it randomly goes away

kabturek commented 1 month ago

I'm also getting an error on neovim (Lazy). Removing the plugin fixes the issue.

   Error  12:00:55 lsp.message LSP Message (elixirls) Unable to find formatter for /Users/kabturek/projects/insight/.formatter.exs: "
** (Mix.Error) Formatter plugin Phoenix.LiveView.HTMLFormatter cannot be found\n    
(mix 1.17.2) lib/mix.ex:588: Mix.raise/2\n    
(language_server 0.22.1) lib/language_server/mix_tasks/format.ex:302: anonymous fn/2 in Mix.Tasks.ElixirLSFormat.load_plugins/1\n    
(elixir 1.17.2) lib/enum.ex:2531: Enum.\"-reduce/3-lists^foldl/2-0-\"/3\n    
(language_server 0.22.1) lib/language_server/mix_tasks/format.ex:299: Mix.Tasks.ElixirLSFormat.load_plugins/1\n    
(language_server 0.22.1) lib/language_server/mix_tasks/format.ex:362: Mix.Tasks.ElixirLSFormat.formatter_for_file/2\n    
(language_server 0.22.1) lib/language_server/source_file.ex:277: ElixirLS.LanguageServer.SourceFile.formatter_for/3\n    
(language_server 0.22.1) lib/language_server/providers/formatting.ex:13: ElixirLS.LanguageServer.Providers.Formatting.format/4\n    
(language_server 0.22.1) lib/language_server/server.ex:1280: anonymous fn/3 in ElixirLS.LanguageServer.Server.handle_request_async/2\n"
Erlang/OTP 27 [erts-15.0.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
Elixir 1.17.2 (compiled with Erlang/OTP 27)

Elixir Language Server version: v0.22.1 Operating system: Mac Editor or IDE name (e.g. Emacs/VSCode): Neovim Editor Plugin/LSP Client name and version: nvim-lspconfig/mason (default LazyVim config)

aar2dee2 commented 1 month ago

getting the same error elixir v1.17.2 live_view v1.0.0-rc.6 macOS

Also getting it for projects with older versions of LiveView. Error disappears if I uninstall the extension.

adamu commented 4 weeks ago

I was also experiencing this with coc.nvim after upgrading to Elixir 1.17.2.

Funnily enough, just leaving the editor open for a few minutes resolved the issue. I guess it was compiling, but each interaction was interrupting the process. I confirmed that Elixir.Phoenix.LiveView.HTMLFormatter.beam was missing from .elixir_ls/build/dev_test/lib/phoenix_live_view/ebin (actually the phoenix_live_view directory didn't exist), but it appeared after waiting a bit.

edit: Confirmed that deleting .elixir-ls/build then opening a .ex file and waiting for .elixir_ls/build/dev_test/lib/phoenix_live_view to show up again resolves the issue for me.

numso commented 3 weeks ago

I've also been experiencing this issue off and on (in vscode). Sometimes the formatter fixes itself; other times it'll stay broken for days. The best way I've found to fix it when it does remain broken is:

  1. Remove plugins: [TailwindFormatter, Phoenix.LiveView.HTMLFormatter], from my .formatter.exs
  2. Go save a random .heex file in my project
  3. Revert the change made in step 1

Seems like maybe elixir_ls sometimes has an issue compiling those plugins and following those steps forces a re-compile.

ravensiris commented 2 weeks ago

Had the same issue with styler. I fixed it by copying _build/test/lib/styler/ to .elixir_ls/build/test/lib/.

grahac commented 1 week ago

Just adding in I had this for weeks. Elixir 1.17.2, OTP 27. Tried installing older versions, uninstalling, reinstalling. Nothing worked. Eventually I uninstalled, trashed the .elixir_ls folder, reinstalled an older version and then upgraded and it worked!

RobertoSchneiders commented 1 week ago

I have the same issue with VSCode, ElixirLS 0.23.0, Elixir 1.17.2, and OTP 27.

I tried some of the solutions presented here but none worked for me. However, sometimes just leaving VSCode open resolves the issue as some already pointed out. One weird thing is that I have the VSCode plugin v0.23.1 but the language server is 0.23.0, I'm not sure what is going on there.

Unable to find formatter for some_path/app.html.heex: ** (Mix.Error) Formatter plugin Phoenix.LiveView.HTMLFormatter cannot be found
(mix 1.17.2) lib/mix.ex:588: Mix.raise/2
(language_server 0.23.0) lib/language_server/mix_tasks/format.ex:302: anonymous fn/2 in Mix.Tasks.ElixirLSFormat.load_plugins/1
(elixir 1.17.2) lib/enum.ex:2531: Enum.\"-reduce/3-lists^foldl/2-0-\"/3
(language_server 0.23.0) lib/language_server/mix_tasks/format.ex:299: Mix.Tasks.ElixirLSFormat.load_plugins/1
(language_server 0.23.0) lib/language_server/mix_tasks/format.ex:362: Mix.Tasks.ElixirLSFormat.formatter_for_file/2
(language_server 0.23.0) lib/language_server/source_file.ex:277: ElixirLS.LanguageServer.SourceFile.formatter_for/3
(language_server 0.23.0) lib/language_server/providers/formatting.ex:13: ElixirLS.LanguageServer.Providers.Formatting.format/4
(language_server 0.23.0) lib/language_server/server.ex:1280: anonymous fn/3 in ElixirLS.LanguageServer.Server.handle_request_async/2

Elixir Language Server version: v0.23.0 Operating system: Ubuntu (VSCode Server) Editor or IDE name: VSCode Editor Plugin/LSP Client name and version: vscode-elixir-ls (0.23.1)

lukaszsamson commented 1 week ago

One weird thing is that I have the VSCode plugin v0.23.1 but the language server is 0.23.0

This is correct. Plugin versioning is independent from language server versioning.

goulvenclech commented 1 week ago

Same error :

Unable to find formatter for /Users/goulvenclech/Documents/encheres_immo/lib/encheres_immo_web/components/form/combobox.ex: "** (Mix.Error) Formatter plugin Surface.Formatter.Plugin cannot be found    
(mix 1.17.2) lib/mix.ex:588: Mix.raise/2    
(language_server 0.23.0) lib/language_server/mix_tasks/format.ex:302: anonymous fn/2 in Mix.Tasks.ElixirLSFormat.load_plugins/1    
(elixir 1.17.2) lib/enum.ex:2531: Enum.\"-reduce/3-lists^foldl/2-0-\"/3    
(language_server 0.23.0) lib/language_server/mix_tasks/format.ex:299: Mix.Tasks.ElixirLSFormat.load_plugins/1    
(language_server 0.23.0) lib/language_server/mix_tasks/format.ex:362: Mix.Tasks.ElixirLSFormat.formatter_for_file/2    
(language_server 0.23.0) lib/language_server/source_file.ex:277: ElixirLS.LanguageServer.SourceFile.formatter_for/3    
(language_server 0.23.0) lib/language_server/providers/formatting.ex:13: ElixirLS.LanguageServer.Providers.Formatting.format/4\n    (language_server 0.23.0) lib/language_server/server.ex:1280: anonymous fn/3 in ElixirLS.LanguageServer.Server.handle_request_async/2"

Erlang/OTP 26 Elixir 1.17.2 ElixirLS plugin v0.23.1 ElixirLS v0.23.0 VScode 1.92.2 (Universal) MacOS 14.5 (23F79)

Fixed after following this post on Elixir Forum :

Just adding in I had this for weeks on latest version of ElixirLS (0.23.1). Elixir 1.17.2, OTP 27. Tried installing older versions, uninstalling, reinstalling. Nothing worked. Eventually I uninstalled, trashed the .elixir_ls folder, reinstalled an older version and then upgraded Elixir LS and it worked!