-
Notifications
You must be signed in to change notification settings - Fork 645
formatOnSave re-saves several times #1037
Comments
Hello, i think i have the same issue. Get same issue (two file writes) when all extensions disabled except vscode-go. But I noticed that if i disable formatOnSave and just use "Format document" i still get one file write, could that be a lead or is that expected behaviour? |
Oh just noticed https://github.com/Microsoft/vscode-go/blob/bca4dd5f31f32ac49da79580c07b4000f06287a3/src/goFormat.ts#L69 is the save needed because the formatting tools can only read from file? |
When you say 2 file writes do you mean the file state indicator next to file name goes from dirty - save - dirty - save? The line you are pointing at would only cause dirty - save - save |
Ok the go formatting tools support reading from stdin but vscode-go is currently not using it. So could the issue be that when |
You mean the dot left of the filename? when i make a change the dot appears. Then when i save it flickers fast and disappears Im using https://github.com/cortesi/modd to trigger builds and if i run it in debug mode (
|
My thinking is that if vscode-go currently uses the go formatting tools by pointing them to the source file path (not using stdin or a temp file) then it would require two saves to make formatOnSave work. First one to save the maybe not properly formatted file to disk and then run the formatting tool on the file and then second one to save the change to make it properly formatted. |
Sorry maybe i should mention that i don't have any issues with the undo stack. Just the issue with two writes. |
I did try passing the file contents via stdin to the formatting tool once before, it caused a bug. I can't remember more on that. Am on vacation right now and so don't have access to my mac. Will check this once I get back. Until then if you can, feel free to send a PR to use stdin |
Ah ok, and also use But no hurry, enjoy your vacation! |
Fixes double save issues as now we don't have to save the document to do formatting. Also fixes save on "Format Document" (now no save is done). Related to microsoft#1037
@ramya-rao-a do you remember what bug you saw when using stdin? |
@wader I don't remember. Will have to look at the history of the goformat.ts file. About onWillSaveTextDocument.. I still haven't come up with a good solution for that. There us another issue tracking it. (will link it once am back from vacation and have something better than my phone to work on) For now, go ahead and remove the save and pass file contents using stain and send a PR |
Ok, thanks! I've sent a PR to use stdin #1069 |
@ramya-rao-a This commit i guess 068754e |
Yes, thats the revert commit. See #1069 (comment) for my thoughts on the usage of "onWillSaveTextDocument" and "stdin" Also the reason for the double save is not due to https://github.com/Microsoft/vscode-go/blob/bca4dd5f31f32ac49da79580c07b4000f06287a3/src/goFormat.ts#L69. That line is only reached when you explicity run the "Format Document" command. The actual reason for the second save is https://github.com/Microsoft/vscode-go/blob/bca4dd5f31f32ac49da79580c07b4000f06287a3/src/goMain.ts#L308 |
With the work in #540 completed, the latest update to the Go extension (0.6.70) has the fix for this issue. There won't be any re-saving of files on formatting |
So I've started using the Go extension yesterday and noticed a weird issue. When formatOnSave is on, I push Ctrl-S and the file is saved several times and the undo stack gets crowded with characters getting selected and deselected. It always selects the same characters that were before the cursor when I pressed Ctrl-S. I tried it with all three formatters and they all do the same.
I think there could be some bigger issue behind this because turning off formatOnSave stops this behavior but the characters in the file still get selected but only once (same here, the character before the cursor).
I use VSCode with Ruby as well and I haven't noticed anything similar. I use the latest Code (1.13.1 I think) and the latest extension. I'm on Ubuntu 17.04.
The text was updated successfully, but these errors were encountered: