Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Save All doesn't gofmt all files when "go:formatOnSave" flag is true #279

Closed
lirao opened this issue Apr 6, 2016 · 6 comments
Closed

Save All doesn't gofmt all files when "go:formatOnSave" flag is true #279

lirao opened this issue Apr 6, 2016 · 6 comments

Comments

@lirao
Copy link

lirao commented Apr 6, 2016

When I save a bunch of files all at once with Save All, only the active file is formatted, and the rest are saved in their un-fmt'ed state. (Autosave is off)

@lukehoban
Copy link
Contributor

I looked into this, and it appears it isn't possible to fix this with the current VS Code APIs.

This is primarily blocked on microsoft/vscode#239, which would make sure the formatting could be applied before the files are saved to disk.

But it is more directly blocked by seemingly not being able to get a TextEditor to use to apply a set of TextEdits for a TextDocument provided to vscode.workspace.onDidSaveTextDocument. See https://github.com/Microsoft/vscode-go/blob/master/src/goMain.ts#L186.

/cc @egamma and @bpasero in case they have a suggestion for how this could be handled with the current VS Code API.

@bpasero
Copy link
Member

bpasero commented Apr 8, 2016

I think this needs microsoft/vscode#239 and is a good scenario for having that as API.

@FrenchBen
Copy link
Contributor

FrenchBen commented Sep 5, 2016

It'd be nice to also have:
"go.fmtFlags": [],

edit: Looks like it exists, but no docs:
"go.formatFlags": [],
https://github.com/Microsoft/vscode-go/blob/dca9bef794ba1a40f42a1dff63ab5fe9658e4652/package.json#L270

@ramya-rao-a
Copy link
Contributor

onWillSaveTextDocument API is now available: https://code.visualstudio.com/updates/v1_6#_new-apis

The only catch is that there is a limitation on the time taken for the listeners of this event.
There have been cases where the formatter in the GO extension seem to take a long time (multiple seconds) in which case, they will be eventually ignored: https://github.com/Microsoft/vscode/blob/a6435b1cbd1417b0d334ea9018f5371df198898f/src/vs/vscode.d.ts#L3980

@ramya-rao-a
Copy link
Contributor

Closing in favor of #540 which will fix this issue as well

@ramya-rao-a
Copy link
Contributor

With the work in #540 completed, the latest update to the Go extension (0.6.70) has the fix for this issue.

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants