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

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
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
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
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