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