ca1989

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

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

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:

https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/elixirls.lua#L7

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

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

dimitarvp

One of my steps was removing that file as well.

Welcome to the forum. :058:

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49084 226
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement