-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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 Document working, editor.formatOnSave=true broken #41194
Comments
This is happening for my TypeScript code as well. While saving, formatting is not working. Formatting is working if I do it separately. But my HTML files are getting formatted at the time of saving. Here is my User Settings.
|
This appears to happen when formatting takes longer than expected. I can repro this in Python as well. Python extension runs formatters in Python process and in a large file formatting may take 2-3-4 seconds. Format Document appears to be executing synchronously and succeeds which formatting on save appears to abandon formatting after a second or so. I.e. same file - when file is small, formatting on save works, but when content grows format on save stops working. Format Document always works. |
perhaps?
|
Rather than setting hard budget, perhaps some sort of progress reporting would help |
@MikhailArkhipov Yeah, I've come to the same conclusion independently of this issue during debugging formatting in Elm extension (associated issue). I think both time constants should be at least configurable from settings. Some progress reporting / throwing errors on timeouts to dev console will be nice.
I've confirmed this problem with 750ms limit when I've built VSC from source with that constant set to some bigger values (master branch from yesterday, Windows 10). @rebornix I can try to create a PR if you or somebody else could suggest some correct way how to solve it or I'll try to investigate it deeper and come with some solution (I saw VSC's source for the first time yesterday ). Thanks! |
Seeing the same thing with the |
Sent a patch to make this configurable: #43702 |
Also related #40030 |
I think this is exacerbated by the opaqueness of the "format on save" feature. As a new user of vscode it's challenging to figure out what's happening:
For formatters like prettier many of these questions don't apply, but I think it's an issue for other extensions. It would be worth adding some UX here to help the user understand what's happening. |
The problem for making this configurable is that it might not be clear that saving is blocked. You'd be surprised how often someone forgets that he/she made a settings change that affects your workflow. There should already be a progress UI that shows a message like "Running Save Participants..." |
@jrieken Format on save is aborted in 750ms. There is no UI/message for either progress or for when formatting gets aborted for exceeding 750ms |
Well, the message is delayed by 150ms (and showing for at least 150ms). The message is shown before calling any participant which run sequentially - that still makes 750ms for format on save and 1750 for onWillSave. That should make 2500ms in total (given a slow formatter and a slow will-save-handler) |
Now that you've pointed it out, I see a brief flash of
|
IMO any hard time limit is a problem. On large Python files formatting can take 3-4 seconds. Python extension worked around this (for now) by detecting if document actually changed on save and if it was not, forcibly reformatting and then saving. This may not work if user decides to close dirty file and then clicks 'Yes' to the save prompt. |
Can't imagine a situation where one would sit and monitor the In Also, a simple but great cue for understanding the progress of the formatting is the fact that your code is not yet correctly formatted, and you are quite OK with just waiting a bit longer or retrying by continuing working and hitting save again. |
Looks like it is hard to discover and users are still confused. microsoft/vscode-python#1325. What's wrong with adding progress indicator with cancellation? |
I am having some trouble with
editor.formatOnSave=true
when using the Ruby extension. It isn't formatting on save. This is strange, because a manualFormat Document
works fine. How is that possible?I assumed this was user error or an extension bug. So I modified the extension locally and added some debug output to this file:
https://github.com/rubyide/vscode-ruby/blob/master/src/format/rubyFormat.ts
I verified that the correct edits were being returned from
provideDocumentFormattingEdits
. This makes sense since a manualFormat Document
works fine. What am I missing? Could this be a vscode bug? Not sure how to debug further.The text was updated successfully, but these errors were encountered: