ca1989
Elixir formatter in neovim (using coc.nvim) sometimes adds parenthesis around macros
Hi all,
my editor (neovim + elixir-ls via coc.nvim) does format on save.
Randomly, it adds parenthesis around macros, so I have a diff looking like:
- get "/", PageController, :home
+ get("/", PageController, :home)
Is anyone experiencing something similar?
Thank you
Most Liked
linusdm
I’d guess this is related to this elixir-ls issue: Formatter doesn't respect formatter.exs while your code is still compiling · Issue #526 · elixir-lsp/elixir-ls · GitHub
If you wait for the underlying compilation to finish, the formatter options are respected again, which makes it seem random.
georgeguimaraes
You defintely can and should use nested .formatter.exs. I also have an umbrella app with several apps within.
Here’s my root .formatter.exs:
[
inputs: ["mix.exs", "config/*.exs"],
subdirectories: ["apps/*"]
]
And in the app that uses Ecto ./apps/analytics/.formatter.exs:
import_deps: [:ecto, :ecto_sql],
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
subdirectories: ["priv/*/migrations"]
]
And in the phoenix app ./apps/analytics_web/.formatter.exs:
[
import_deps: [:phoenix],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}"]
]
You can always generate a new umbrella Phoenix app that will give a boilerplate on how those files are generated.
This issue is related to LazyVim changing Neovim’s cwd which would cause some weird interactions with neotree, for instance. It would change the file tree from neotree to only display ./apps/analytics_web in certain scenarios.
Since you’re using LazyVim, which uses nvim-lspconfig, the actual “directory” for ElixirLs is defined here:
I changed that recently to give priority to a .git folder in the root dir, so that you only have one ElixirLS in the entire umbrella app.
elurker
Alright, sorry for the noise - as a newcomer I wasn’t aware there’s a dedicated mix new --umbrella (yay!) to set everything up properly. Coming from JS world where I had to set up monorepos manually, but here it’s turn-key. Now formatting seems to work fine, without any custom NeoVim or LS configuration.
(I should note that I still get the error from above if I try to save an Elixir file without giving ElixirLS a few seconds to start up, if I close and reopen Neovim. But that’s probably expected)
Thanks again for all your help!
Last Post!
dimitarvp
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









