Feature request: Working directory independent way to get formatter configuration for a file

49 views
Skip to first unread message

Jason Axelson

unread,
Dec 16, 2021, 12:42:15 PM12/16/21
to elixir-l...@googlegroups.com
Hi all,

While working on ElixirLS we cannot use the normal `mix format` for a few reasons:
- We want to provide the results of the formatting as Language Server Protocol edits which allows editors to undo the formatting
- We want to format quickly without paying the cost of the BEAM startup time

Therefore up until now we've been formatting using Code.format_string!/2 and using Mix.Tasks.Format.formatter_opts_for_file/2 to find the formatter options, however that suffers from a major problem for us, the result of Mix.Tasks.Format.formatter_opts_for_file/2 depends on the value of the current working directory (i.e. File.cwd/0), and because of the current architecture of ElixirLS the current working directory is not stable and we cannot control it directly (the current working directory changes as elixir code is compiled).

So I would like to request that there be a function to get the formatter options (and as-of Elixir 1.13 formatter as well) relative to a passed in directory. If we can settle on an approach I'd be willing to create a PR for this.

I'm also open to alternative suggestions (especially ones that take into consideration the fact that we cannot control the current working directory). If it were possible I would love if I could give an individual Elixir process its own file server with its own current working directory. However I'm not sure that that is possible in the BEAM. The only mentions of the file server that I've been able to find in the Erlang docs are in https://www.erlang.org/doc/man/file.html and the file server is only referenced indirectly.

Thanks,
Jason

José Valim

unread,
Dec 16, 2021, 1:20:32 PM12/16/21
to elixir-lang-core
> So I would like to request that there be a function to get the formatter options (and as-of Elixir 1.13 formatter as well) relative to a passed in directory. If we can settle on an approach I'd be willing to create a PR for this.

Maybe I am oversimplifying this but can we:

1. Accept cwd as an option (which defaults to File.cwd)
2. Make sure that all the path lookups what we do have a Path.join(cwd, path)

?

In any case, a PR to address this is very welcome, regardless of the approach, since it is important to Elixir LS.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAHMz6kxfAwzFE8TZzrCSOtmaGLoxZQqUqX55iS9u2S%3DU6EeB3Q%40mail.gmail.com.

José Valim

unread,
Dec 16, 2021, 1:20:59 PM12/16/21
to elixir-lang-core
Oh, the file_server is locally registered and not per process, I don't think we change this. :(

Jason Axelson

unread,
Dec 17, 2021, 12:19:17 PM12/17/21
to elixir-l...@googlegroups.com
I don't think that you're oversimplifying it and that was basically what I had in mind. I'll begin work on a PR. Thanks!

And that's too bad about not being able to change the file_server.

-Jason

Reply all
Reply to author
Forward
0 new messages