go icon indicating copy to clipboard operation
go copied to clipboard

x/tools/gopls: allow enabling gofumpt extra rules

Open maxbrunet opened this issue 2 years ago • 4 comments

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

maxbrunet avatar Oct 24 '22 20:10 maxbrunet

Change https://go.dev/cl/444656 mentions this issue: gopls, internal/lsp: allow enabling gofumpt extra rules

gopherbot avatar Oct 24 '22 20:10 gopherbot

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.

findleyr avatar Oct 27 '22 16:10 findleyr

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 avatar Oct 27 '22 21:10 mvdan

@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?

findleyr avatar Oct 28 '22 13:10 findleyr

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

maxbrunet avatar Oct 31 '22 23:10 maxbrunet