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

Add "goformat" to the allowed values for go.formatTool #1656

Closed
mbenkmann opened this issue May 4, 2018 · 8 comments
Closed

Add "goformat" to the allowed values for go.formatTool #1656

mbenkmann opened this issue May 4, 2018 · 8 comments

Comments

@mbenkmann
Copy link
Contributor

Please add "goformat" to the allowed values for go.formatTool.
goformat is an extended version of gofmt with more options:

https://github.com/mbenkmann/goformat

This tool would also allow you to revisit issue #1011 but all I care about is having VSCode accept "goformat" as a value for go.formatTool. Usage is exactly as gofmt, so the backend can call it exactly the same way.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented May 8, 2018

I believe you should be able to use goformat without any support from the Go extension if it works similar to the other tools we support.

  • Add "go.formatTool": "goformat" to your settings. (There will be a warning that it is not valid, but ignore that)
  • Install the goformat tool so that it is available in the $PATH

The extension should just pick it up and run it.
Let me know if that doesnt work

@mbenkmann
Copy link
Contributor Author

It runs it, but I get a perpetual entry in my Problems tab, so that it always has the blue bubble, which makes harder to notice when I have an actual problem.

@ramya-rao-a
Copy link
Contributor

That makes sense. PRs are welcome to this option to go.formatTool

Just add an entry at https://github.com/Microsoft/vscode-go/blob/0.6.79/package.json#L507. That should fix the warning in the settings.
Also add an entry in https://github.com/Microsoft/vscode-go/blob/0.6.79/src/goInstallTools.ts#L20 which will ensure you get the right prompt when you have chosen goformat, but its not installed

@mbenkmann
Copy link
Contributor Author

Thanks for the code pointers. I managed to implement it.
Since goformat allows style options I think it would make sense to implement the following behavior:

If go.formatFlags == [] and go.formatTool == "goformat", then use a default set of flags that corresponds to

  • editor.insertSpaces
  • editor.tabSize.

I would assume that this automatically fixes issue #1011 if the user is willing/able to set go.formatTool="goformat".

What do you think? Should I add this at
https://github.com/Microsoft/vscode-go/blob/0.6.79/src/goFormat.ts#L31

@ramya-rao-a
Copy link
Contributor

Let's not have hidden defaults that way. Sometimes, a user might indeed want to pass no flags. Also, it wouldn't be right for the Go extension to have formatting opinions :). That's purely a personal decision.

@mbenkmann
Copy link
Contributor Author

But that's exactly the point. We should honor the user's setting of editor.insertSpaces. VSCode contains this default:

"[go]": {
"editor.insertSpaces": false,
"editor.formatOnSave": true
},

If the user deliberately changes insertSpaces to true, he clearly does not want tabs. If he also deliberately changes go.formatTool to goformat, he clearly does not want standard gofmt formatting.
I'm not suggesting any hidden defaults. I'm suggesting to use the user's settings.

@ramya-rao-a
Copy link
Contributor

I am sorry, I misunderstood.

Yes, translating the user's settings for editor.insertSpaces and editor.tabSize to corresponding flags for goformat makes sense.

mbenkmann added a commit to mbenkmann/vscode-go that referenced this issue May 9, 2018
If this formatTool is set and the user has not provided custom go.formatFlags,
indentation settings from editor.insertSpaces/editor.tabSize are used.
ramya-rao-a pushed a commit that referenced this issue May 12, 2018
* Add support for go.formatTool: "goformat" #1656
If this formatTool is set and the user has not provided custom go.formatFlags,
indentation settings from editor.insertSpaces/editor.tabSize are used.

* changed goformat URL to canonical source

* Fix linting error
@ramya-rao-a
Copy link
Contributor

This feature is now out in the latest update to the Go extension (0.6.80)

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

No branches or pull requests

2 participants