-
Notifications
You must be signed in to change notification settings - Fork 187
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
Formatter doesn't respect formatter.exs while your code is still compiling #526
Comments
Up. I'm facing this issue too. When I run 2 successive commands to format file, formatter.exs is ignored. |
This is caused because when compiling code, mix changes the current working directory, and the code that is used to fetch the |
Ahh gotcha. Feel free to close this in favor of the earlier reported issue if that makes things easier for you. |
Commenting here because this seems like the central place to address it. This problem was bugging me for a while and I stumbled on #394 (the ETS cache fix), which I had checked out and running locally for a while. That PR seemed to fully fix this problem, but looks like it's been dead for a bit. I'm happy to pick that up and try to get it across the finish line, but I also stumbled on a couple other approaches: #687 (blocking until project reload) and @axelson your work on an Elixir core PR. Is there a preferred approach here? It seems like the Elixir core approach is most robust but this ETS cache fix might be faster to implement? Would love to help in any way I can. |
@MrGrinst at ElixirConf this year I've made plans to start some regular pairing sessions with @zachdaniel on the Elixir core PR that I have started but that got stalled out. Hopefully we'll have something to report soon! |
Any progress or an idea of the direction to take? I can take it over the line otherwise, I need this kind of small win in a project that is not mine right now... |
@DianaOlympos I think this would count as a large win! The way I've been thinking about this is there's two parts to this. First is a PR to Elixir that changes The second is temporarily vendoring |
Maybe it would be easier to run formatter as a separate OS process instead. Another option is separating build to a different process |
Hi all, has anyone found a viable short-term workaround to prevent this from happening (even if it means just ignoring formatting during compilation?) - really anything short of entirely disabling the auto-formatting. It's a huge pain point in my day-to-day. |
Thinking out loud here since there is a lot of people looking at this right now. Couldn't the |
I have a branch where I did just that with the It does solve this formatting issue, but I have run into a bug a few times where it can't find the |
@skbolton @robmerrell while |
Ok so proper fixing options seem to be
Intuitively I want to go for 3 first, to fix the damn problem, then upstream with 2. 1 would be a nice fix, but I really do not want to deal with wiring up everything. What do you think @lukaszsamson ? I may have time to do 2 today. |
Go ahead. It would be best if we could solve the problem upstream |
So after a dive, I will just upstream it. This function got far more complex recently, probably due to plugins, which would make vendoring a pain and a lot of code. Once upstreamed, I will come back to implement it here, in particular because there are at least 5 different ways we call it and validate the correct version to call in the LSP codebase, so I will try to consolidate this a bit |
Opened the PR above with elixir, we will see how it goes. |
FWIW, I had this issue while I was working with a very large codebase. I wanted the formatter must be fast and reliabl -- it should work even if code can not compile but has valid syntax (semantic errors) as I added to "on-save" callback. As I am using Emacs, I just created a library to run an inferior shell Interestingly, this approach helped me to speed up running test suite as well. Start |
Ok so this is now merged. I will look at bringing it to lsp. I quickly grepped the codebase, it seems we have multiple places where we call the formatter, with different styles and using different ways to check which call we should do/elixir version. Is there an interest in unifying this while i am at it? If yes do you prefer a version check or a "if function exported" ? I suppose we would path the project path as root? |
Sure
I prefer version check, it's easier to find and remove them when we bump min version required. Here we'd need to check version anyway as the fun is exported but the new opts will be >= 1.15 only
Exactly. By default elixir-ls looks for mix.exs under workspace root but that can be overwritten by setting |
1 similar comment
Sure
I prefer version check, it's easier to find and remove them when we bump min version required. Here we'd need to check version anyway as the fun is exported but the new opts will be >= 1.15 only
Exactly. By default elixir-ls looks for mix.exs under workspace root but that can be overwritten by setting |
Note that this would not be a problem @lukaszsamson because the option is optional. We can set it up pre 1.15 and it will just be ignored and works as it does today. |
Environment
Elixir 1.11.3 (compiled with Erlang/OTP 21)
Troubleshooting
.elixir_ls
directory, then restart your editorhttps://www.dropbox.com/s/llgnf7ham9d0hf8/Screen%20Recording%202021-04-07%20at%208.28.49%20AM.mov?dl=0
You can reproduce this by deleting the
.elixir_ls
directory, and then saving a file to trigger the LS to start recompiling, then run the formatter. You observe that it is not respecting the formatter configuration because it is adding parens to Ecto functions/macros that shouldn't have parens.The screen recording I added above using VSCode, but I have also reproduced it with Neovim builtin language client.
I personally have never run into this race condition, but my coworkers constantly are pushing up code that is clearly formatted incorrectly, and I traced it down to this issue.
Thanks!
The text was updated successfully, but these errors were encountered: