Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: convert 'gofumpt' from formatter to code action provider #39805

Open
stamblerre opened this issue Jun 24, 2020 · 5 comments
Open

x/tools/gopls: convert 'gofumpt' from formatter to code action provider #39805

stamblerre opened this issue Jun 24, 2020 · 5 comments

Comments

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Jun 24, 2020

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.

/cc @joshbaum @mvdan

@gopherbot gopherbot added this to the Unreleased milestone Jun 24, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.5.0 Jun 24, 2020
@muirdm
Copy link

@muirdm muirdm commented Jun 24, 2020

If people want to use gofumpt, wouldn't an option to use gofumpt for formatting be more useful than suggested fixes?

@stamblerre
Copy link
Contributor Author

@stamblerre stamblerre commented Jun 24, 2020

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.

@muirdm
Copy link

@muirdm muirdm commented Jun 24, 2020

I see, I knew I was missing something!

@gopherbot
Copy link

@gopherbot gopherbot commented Jul 12, 2020

Change https://golang.org/cl/241985 mentions this issue: gopls, internal/lsp: support an extra formatting hook for gofumpt

@stamblerre
Copy link
Contributor Author

@stamblerre stamblerre commented Jul 13, 2020

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.

@stamblerre stamblerre changed the title x/tools/gopls: support suggested fixes from 'gofumpt' x/tools/gopls: convert 'gofumpt' from formatter to suggested fixes Aug 28, 2020
@stamblerre stamblerre changed the title x/tools/gopls: convert 'gofumpt' from formatter to suggested fixes x/tools/gopls: convert 'gofumpt' from formatter to code action provider Aug 28, 2020
@stamblerre stamblerre added the Thinking label Aug 28, 2020
@stamblerre stamblerre added this to the gopls/unplanned milestone Oct 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants