x/tools/gopls: convert 'gofumpt' from formatter to code action provider
Opened this issue · 5 comments
Add an analyzer that produces suggested fixes using https://pkg.go.dev/mvdan.cc/gofumpt/format?tab=doc.
The tricky part is that the dependency will have to live in the gopls
module, since it's not a golang.org/x/...
dependency. That means the analyzer will have to be in that module, and we won't be able to have any internal/lsp tests for this behavior until #35880 is resolved.
If people want to use gofumpt, wouldn't an option to use gofumpt for formatting be more useful than suggested fixes?
The suggested fixes would be categorized as "source.fixAll", which is a code action kind indicating that these are high-confidence fixes that can be applied on save. We already have similar analyzers and fixes for gofmt -s
.
I see, I knew I was missing something!
Change https://golang.org/cl/241985 mentions this issue: gopls, internal/lsp: support an extra formatting hook for gofumpt
Reopened this, as we've only added opt-in support for gofumpt
as a formatter, not in the form of suggested fixes. I would strongly prefer a scenario in which gofumpt
works more like staticcheck - it would make it more configurable for users and easier to adopt (users don't have to run it on save). To that end, I've filed mvdan/gofumpt#78 -- so this issue is blocked until that is resolved.