go
go copied to clipboard
x/tools/gopls: allow enabling gofumpt extra rules
gopls version
master (8166dca1c) (latest release: v0.9.5)
go env
N/A
What did you do?
Currently gofumpt
can be enabled: https://go.googlesource.com/tools/+/refs/heads/master/gopls/doc/settings.md#gofumpt-bool
But extra rules cannot be used: mvdan/gofumpt#extra-rules-behind--extra
What did you expect to see?
An option to enable extra rules (e.g. formatting.gofumptExtraRules
bool
). Suggested implementation: golang/tools#410
What did you see instead?
No option to enable extra rules.
Editor and settings
"gopls": { "formatting.gofumpt": true }
Logs
N/A
Change https://go.dev/cl/444656 mentions this issue: gopls, internal/lsp: allow enabling gofumpt extra rules
We generally try to avoid new configuration when possible, but this may be important as we already integrate with gofumpt.
Curious what @mvdan thinks of this request.
That flag only turns on one additional rule, and it's a somewhat controversial one. Looking ahead, that kind of optional cleanup should rather be a "quickfix" step that the user opts into, rather than formatting that happens automatically. So I don't oppose adding the feature in the future (e.g. as a quickfix), but I do lean against adding "extra rules" as a formatting option. At least for now, given the only rule that it turns on.
@mvdan that sounds like a great idea: if gofumpt were to provide an API for these types of additional formatting rules, we could definitely offer them as a quick-fix, via an analyzer that could be enabled/disabled independently of gofumpt formatting.
@maxbrunet what do you think about this idea?
Thank you for the replies, it sounds reasonable. I am not familiar enough with LSP and the requirements for a code action, but I have opened mvdan/gofumpt#251 to start the discussion about what it would look like there