-
Notifications
You must be signed in to change notification settings - Fork 762
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
Pass file to format to custom formatter #1603
Comments
Change https://golang.org/cl/332529 mentions this issue: |
It's tricky to assume what a "custom" formatter takes as args. Is it not possible to utilize The extension runs the format tool inside the directory of the document (assuming |
My intention is that you would wrap the custom formatter in a script so that you can transform why the extension passes into the form the formatter needs. Also happy to introduce a template variable if that's preferred |
@mrmeku We discussed this in our internal team meeting and we hope to stick with the |
Change https://go.dev/cl/446298 mentions this issue: |
Change https://go.dev/cl/446296 mentions this issue: |
The extension supports custom formatter. When gopls is used, this is done by intercepting the formatting request from the middleware and passing it to the legacy format provider that calls the specified tool. The "Nonexistent formatter" test is meant to take this middleware code path and let the legacy format provider fail by setting `go.formatTool` with a bogus, non-existing tool name. This setting doesn't need to affect other tests though. Limit this setting to only the nonexistent formatter, by starting a new language server instance for each test. Additionally this fixes bugs: - wait to show the document to format - the legacy formatter doesn't run if there is no visible document. (I don't know why we don't format non-visible document but that's how it's written goFormat.ts:24). - close the open editor after each test. For #1603 Change-Id: I3486b299aa2a2660fb971fed54d3f941be13698d Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/446296 TryBot-Result: kokoro <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]> Reviewed-by: Suzy Mueller <[email protected]>
Custom formatter support was added in #1238. But due to the limitation in the VS Code setting UI (which assumes the acceptable values list is static) and the setting validation logic (VS Code thinks it's an error to use a value outside of the supplied enum list is invalid), this is not visible to users. Instead, this change introduces an extra enum 'custom' for the "go.formatTool" setting. If this is chosen, the extension uses the tool specified as `customFormatter` in the "go.alternateTools" setting section for formatting. The extension expects the custom formatter to accept input as STDIN and output the result as STDOUT. Users can also supply "go.formatFlags". Changed the descriptions to use markdown - which allows to reference other settings ("`#...#`"). The document generation tool does not handle this special syntax nicely but I hope this isn't too confusing. I wish we could add an extra validation on the allowed value for "go.formatTool" in favor of this new 'custom' option. I am not adding the validation in this CL because there could be users who depend on this behavior. For #1238 For #1603 For #2503 Change-Id: I5d9564f331845b6b07f0b54148834118404f3553 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/446298 Reviewed-by: Jamal Carvalho <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]>
Describe the bug
Currently the vscode-go extension has code paths to support running a custom go formatting tool. However, those code paths stop short of actually passing the file that should be formatted as an argument to the formatter. This makes it so that a custom formatting tool cannot actually be run since it has no way of knowing what file it should format
Steps to reproduce the behavior:
"go.formatTool"
to a path to a custom toolThe text was updated successfully, but these errors were encountered: