Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format on save does not respect imported formatter configuration #67

Closed
JakeBecker opened this issue Mar 16, 2018 · 9 comments
Closed

Comments

@JakeBecker
Copy link
Owner

From @Rosetjau on March 16, 2018 13:58

When running the formatter from command line via mix format the formatter respects the configuration that is imported from dependencies. The same does not seem to apply to the "format on save" feature in Visual Studio Code.

I have set up an example repository to reproduce this issue. Steps to reproduce:

  1. Clone the repo
  2. Run mix format from command line. Notice that the formatter exits without changing the schema.ex file, because the .formatter.exs file imports the configuration that is exported by Absinthe
  3. Open the project with Visual Studio Code, edit the workspace settings to enable "editor.formatOnSave", open the schema.ex file and save it
  4. Upon saving the file the formatter will add parentheses to the schema.ex file, even if the Absinthe formatter configuration declares those functions/macros as locals_without_parens

Copied from original issue: JakeBecker/vscode-elixir-ls#58

@JakeBecker
Copy link
Owner Author

Ah, looks like they've added a lot of configuration options to the format task since I added support for it to ElixirLS. Unfortunately, supporting those features right now will likely involve copy-and-pasting a lot of private functions from Elixir. I'm willing to do that, but I think I also will send a PR to try to export some of the configuration functionality from Mix.Tasks.Format in future Elixir versions.

I'll likely get to this sometime next week.

@JakeBecker
Copy link
Owner Author

I added a new function to Mix.Tasks.Format to return formatter options for a given file, which should fix this. I'll likely do a release tomorrow with the fix and I'll comment here once it's out.

You'll need to be running the latest (pre-release) version of Elixir for it to work, though. You can install it with kiex by running kiex install master.

@Rosetjau
Copy link

Thank you 👍

@JakeBecker
Copy link
Owner Author

Just published a release with the fix.

@hickscorp
Copy link

I would suggest to re-open this issue. We are seeing an non-reproducible problem upon saving.
sometimes the formatter rules are ignored. Ctrl + Z cancels those bad changes. Sometimes it is honored...

@a-kinder
Copy link

a-kinder commented Mar 30, 2020

^ seconded, seems to ignore locals_without_parens as mentioned in JakeBecker/vscode-elixir-ls#21

edit: or may possibly be ignoring import_deps in .formatter.exs

@hickscorp
Copy link

It's definetely adding parenthesis randomly upon saving (sometimes yes, sometimes not).

@zachdaniel
Copy link

zachdaniel commented Mar 23, 2021

I'm also seeing this issue (on the latest version)

@axelson
Copy link

axelson commented Mar 23, 2021

@zachdaniel Issues should be filed on the new repo (https://github.com/elixir-lsp/elixir-ls/). Although this one sounds like a duplicate of elixir-lsp/elixir-ls#402

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants