lexical-lsp / lexical

Lexical is a next-generation elixir language server
779 stars 77 forks source link

Formatter fallback does not resolve imported dependencies #728

Closed soundmonster closed 1 month ago

soundmonster commented 1 month ago

The formatter code mod will use in-project formatting by default. If that doesn't work as expected and raises an error, the code mod will fall back to basically this:

This is problematic, as Code.format_string! does not understand all options allowed in the formatter dotfile. Here's a list of the options that the dot-formatter supports but the function doesn't: https://hexdocs.pm/mix/Mix.Tasks.Format.html#module-formatting-options. Most importantly, plugins and import_deps are not supported. mix format reads from the dotfile and then applies a few transformations to it, e.g. this, thus bringing it into a format that Code.format_string! supports.

I'm not sure what to do about this: the fallback is currently mostly incorrect and is likely very hard to fix. Should we just shell out to mix format path/to/file.ex instead? Or try to evaluate / resolve all options supported in the formatter dotfile?