Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.22.1 can not logger format liveview projects #1110

Open
NoBrainSkull opened this issue Jul 19, 2024 · 25 comments
Open

v0.22.1 can not logger format liveview projects #1110

NoBrainSkull opened this issue Jul 19, 2024 · 25 comments
Labels
wontfix This will not be worked on

Comments

@NoBrainSkull
Copy link

Environment

  • Elixir & Erlang versions (elixir --version):
    Tested with both :
Erlang/OTP 27 [erts-15.0] [source] [64-bit] [smp:24:24] [ds:24:24:10] [async-threads:1] [jit:ns]

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

Expected behavior

Reverting elixir-ls to v0.22.0 fixes the problem entirely, with no observed impact from Elixir/OTP version.

@lukaszsamson
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Collaborator

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

@NoBrainSkull
Copy link
Author

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
Copy link

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

@kabturek
Copy link

kabturek commented Jul 25, 2024

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
Copy link

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
Copy link

adamu commented Aug 6, 2024

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
Copy link

numso commented Aug 9, 2024

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
Copy link

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

@grahac
Copy link

grahac commented Aug 22, 2024

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
Copy link

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
Copy link
Collaborator

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
Copy link

goulvenclech commented Aug 27, 2024

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!

@lukaszsamson
Copy link
Collaborator

I'm going to close this as there's a confirmed workaround

@lukaszsamson lukaszsamson added wontfix This will not be worked on and removed waiting for information labels Sep 28, 2024
@anildigital
Copy link

@lukaszsamson This needs a proper fix.

@lukaszsamson
Copy link
Collaborator

@lukaszsamson This needs a proper fix.

Agreed @anildigital please send a PR or a reliable repro.

@sabiwara
Copy link
Contributor

sabiwara commented Oct 10, 2024

I think I found a reliable repro, it feels like a race condition:

  1. Cloning the repo shared by @NoBrainSkull v0.22.1 can not logger format liveview projects #1110 (comment)
  2. I just tweaked the .tool-versions to use elixir 1.17.2
  3. Install everything until you get a working state
  4. Close vscode
  5. rm -rf .elixir_ls
  6. Open a file in vscode, e.g. lib/ex17ls/mailer.ex, immediately add some spaces and try to save a couple of times
  7. Get the error
  8. Run Elixir: Restart language server => the formatter works again

@lukaszsamson
Copy link
Collaborator

@sabiwara The formatter cannot work until the first build finishes. Formatter API can under that conditions initiate compilation which would conflict with the ongoing compilation. You wouldn't normally run mix format while mix compile is under way. To prevent that ElixirLS is using a vendored compiler API that never compiles anything.

@sabiwara
Copy link
Contributor

sabiwara commented Oct 10, 2024

Maybe the issue is for big projects for which the compilation is slow, and every new save will trigger a new compilation, delaying the formatter being available?
Naive question, but isn't a mix deps.compile enough for the formatter? If the deps didn't change it shouldn't care about compiling the project itself, no? (at least for projects not defining custom plugins)

@lukaszsamson lukaszsamson reopened this Oct 10, 2024
@lukaszsamson
Copy link
Collaborator

It's not trivial to separate deps.compile. Deps change (e.g. when you switch branches or edit config). Elixir is pretty bad in deciding what to recompile. There were dozens of nontrivial errors and crashes so it's safest to rebuild on start. There's no easy escape from the initial compile time. I guess the real issue would be if the plugins get unloaded on each subsequent compile. I will need to check that.
The last change that could have affected purging and reloading was d17ee89 introduced in v0.21.0. OP reported that v0.22.0 didn't have the problem while v0.22.1 did. There were no changes affecting build between those versions

@lukaszsamson
Copy link
Collaborator

lukaszsamson commented Oct 10, 2024

Reports on forum thread started on August 22 a few weeks after v0.23 release, but this post states that v0.20 worked OK

@anildigital
Copy link

Anyone already fixing this somewhere? Any woraround to avoid this error? thanks

@mawkler
Copy link

mawkler commented Nov 12, 2024

Just commenting here to say that I have the same issue

@mrluc
Copy link

mrluc commented Nov 12, 2024

I started seeing this today, after a machine crash. 1.17.2 elixir, latest ElixirLS in VSCode.

  • rm -rf .elixir-ls/ and Elixir: Restart language server didn't work for me
  • rm -rf .elixir-ls/ and then > Restart Extension Host did!

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests