Proposal Details
Currently, in the gopls
settings, we only have the option to enable gofumpt
. It would be nice if gopls
allows the user to set a path to a specific formatter program like how nil implements it, where it supports setting a custom formatter in the config by assigning the path of the formatter to "nil"."formatter"."command"
as a String
. This would enable the ability to use third party formatters such as golines
and golangci-lint fmt
with gopls
.
Comment From: gabyhelp
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: adonovan
Though I don't love the idea of further complicating what should be a simple story ("there is one format and its command is gofmt"), I would support this feature if it meant that gopls could avoid linking in gofumpt, instead being loosely coupled to nonstandard formatters through a common command-line interface. Then gofumpt=true
could become a shorthand for formatter=github.com/mvdan/gofumpt
.
Comment From: yzhou216
Though I don't love the idea of further complicating what should be a simple story ("there is one format and its command is gofmt")
golines
for example, internally calls gofmt
anyway, and since gofmt
doesn't have any formatting preferences for line wrapping, that means feeding a go source file formatted by golines
back to gofmt
would not change the format again in any way. Thus, I would like to call that formatters such as golines
and gofumpt
gofmt
compatible formatters, meaning feeding the result of them back to gofmt
doesn't change the file again.
I'm guessing when gopls
decided to add the option to enable gofumpt
, this was part of the consideration, which makes it reasonable to at least add the option for golines
. I completely understand and agree with the opinion of only having one formatter, however, I think such compatible formatters should be allowed.