-
Notifications
You must be signed in to change notification settings - Fork 645
Add format-on-save support (instead of requiring use of explicit Format Document command) #14
Comments
I am experiencing this as well. In User preferences: |
Strange: Alt-Shft-F (or right-click menu) works correctly ! |
Actually I just now realize that formatting on save is not in the feature list.... |
Format on save would be a nice feature |
Currently formatting is available through an explicit command ( I'll keep this issue to track adding support for format on save. |
If I wanted to take a bash at this feature where can I modify the existing plugin on my mac? |
@jchannon Great. There's some notes on how to build/debug the extension yourself here: https://github.com/Microsoft/vscode-go#building-and-debugging-the-extension. |
I assume this instruction is wrong: |
Huge +1 to adding format-on-save (and it should be on by default; use By default, it simply shouldn't be possible to save a non- |
Agreed. If Luke can do it quickly go ahead. I'm just poking around ... On Wednesday, 18 November 2015, Dmitri Shuralyov [email protected]
|
+1 to add format on save. I was using Atom and this is definitely what I miss the most :) |
OK I think I have this working, however I'm a bit stuck on writing it back to the file. I have added some code to goCheck.ts. Firstly is that the correct place? Secondly how do I write back to the file in goCheck? |
Actually I think it should go in goMain::startBuildOnSaveWatcher ? |
@jchannon. I think what is probably best is the following:
The bug in #16 is also something that will need to be fixed before we can turn format-on-save on. We'll also need to make sure that format-on-save interacts decently with Auto Save if the user has that turned on. I'm a little worried that these will interact poorly, since code will be changing unexpecedtly without the user taking any action. It may be that we'll need to turn of format-on-save if Auto Save is turned on. |
Yeah I don't think formatting with auto save turned on will work On Thursday, 19 November 2015, Luke Hoban [email protected] wrote:
|
WIP in PR added here - https://github.com/Microsoft/vscode-go/pull/40/files On 19 November 2015 at 18:15, Jonathan Channon [email protected]
|
@lukehoban have pushed all I can do, but for some reason its not working when I save |
I haven't reviewed carefully yet - but it looks like you aren't yet applying the edits. I believe you need to use |
OK I've tried that and the command is executed but the document is not Cheers On 19 November 2015 at 20:25, Luke Hoban [email protected] wrote:
|
I'd like to propose that the format-on-save command can be different than the explicit "format code" command. I like |
@jchannon I've pushed a new PR which builds upon your changes. This is still work in progress, but it does technically do a format-on-save. The lack of a preSave event in Code makes this much more awkward than it should be. |
Sounds like there's some really good progress on this. Is it possible to have allow for an array of tools to run on save? For instance, I enjoy how Atom's extension does both gofmt and goimports. For now, I have hacked my build task to handle this for me, but that's ugly at best. |
Question about that specific example: do you know that |
Oh wow, you're right, I totally missed that. Thanks for pointing that out :) |
Damn, was thinking something was broken until found "format code" from the menus. So used to fmt on save from LiteIDE. How often is the plugin updated, is it repo tags or how can one see when things go "live"? |
For folks interested in this, I've added a new PR with a more-or-less complete implementation of this in #115. Along with some other formatting fixes from @newhook, I believe this is now working reasonably well. If anyone has a chance to pick up and test it out (git cloning per the instructions in the README and checking out the PR branch), that would be great. The feature is behind a flag so I'll likely check this into master and push an update for broader testing in the next day or so. |
Initial impression is that it does what it's supposed to. However a thing to note is that it doesn't play well with Auto Save, as the sudden reformat when you pause typing is a bit jarring |
I've merged the format-on-save support into master and it's in the It's still behind a flag for now - you'll want to set As @calmh mentions, format-on-save doesn't play well with AutoSave, so you'll want to pick which one you want to use. Generally, this means two modes of use for the plugin:
|
Works like a charm for me. Thanks a lot ! |
Thank you so much @lukehoban! I consider format-on-save to be an absolute must minimum requirement to be able to consider using an editor for writing Go, and this was blocking me from trying VSC out further. This is very exciting! Now that it's resolved, I can try playing more with it. I've briefly tried it, and first impressions are really nice, and I see this on the trajectory of becoming the best (non-terminal) Go editor/plugin I've seen (beating Sublime Text + GoSublime, and Atom + its best Go package). I notice some buggy behavior when there are multiple "issues" to resolve on save, like a golint issue, go build issue, and gofmt issue. It seems it resolves one, but not the others at the same time, so I need to make a few dummy edits and re-save to get it all updated. I also couldn't get But overall, this is looking really incredible! |
Thanks @shurcooL!
Curious if you are able to reproduce this issue? Would love to fix that if there is still a problem. |
can confirm this is working |
The gopath seems to be correctly set because typing errors ('Undefined: ...') en vet messages ('exported function should have comment') are reported correctly.
However, the formatting is not corrected ? Not on disk and not in the editor. I tried to override the default goreturns with goimports and then with gofmt, but that does not seems to matter.
Any ideas ?
The text was updated successfully, but these errors were encountered: