-
Notifications
You must be signed in to change notification settings - Fork 795
Support custom formatters with args #3729
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
Comments
Reading the source code, the language server isn't used when you set "go.formatTool" to "custom". The arguments for custom formatter work for me properly.
Could you check if this command prints out the full code to |
@logica0419 Are you sure this configuration work? When I copy paste your settings it does not work for me. There is a formatter running, and it might be golangci-lint, but it's not using the args. For example providing an illegal argument still works:
Also when comparing the output when running the tool directly I get two different results. I see that |
@palsivertsen The format error may be displayed in the dev tools console (you can see it by clicking Help > Toggle Developer Tools), so could you check if some errors are displayed there? |
There are no errors in the debug console. I cleared all settings (user and workspace json files) and uninstalled all extensions except go. This is the only thing I have in my settings file: {
"go.formatTool": "custom",
"go.alternateTools": {
"customFormatter": "golangci-lint"
},
"go.formatFlags": [
"fmt",
"--stdin",
"--no-config",
"--enable",
"gci"
]
} Note I added package example
import (
"github.com/aws/aws-sdk-go-v2/aws"
"fmt"
"io"
"log"
)
func Example() {
var (
_ = aws.SDKVersion
_ = io.EOF
_ = log.Print
_ = fmt.Print
)
} When I run this through the formatter I get the expected results: golangci-lint fmt --stdin --no-config --enable gci < example.go package example
import (
"fmt"
"io"
"log"
"github.com/aws/aws-sdk-go-v2/aws"
)
func Example() {
var (
_ = aws.SDKVersion
_ = io.EOF
_ = log.Print
_ = fmt.Print
)
} When I run the formatter in vscode I get a different result: package example
import (
"github.com/aws/aws-sdk-go-v2/aws"
"fmt"
"io"
"log"
)
func Example() {
var (
_ = aws.SDKVersion
_ = io.EOF
_ = log.Print
_ = fmt.Print
)
} This do match the results of running |
Thank you for raising this issue. I will focus on why the configuration you mentioned in description does not work:
The flag is propagated to the
looks like the log is being sent to terminal in webview developer tool, a correct way to do is to create a terminal first and attach the log to that terminal. See the screenshot in developer tool: This is a bug, there is TODO here, I will fix it. For now, you need to go to ![]() |
With the configuration here
One thing to note here is, golangci-lint v1 does not support fmt. So at the beginning, I saw error from terminal saying the fmt command not recoganized. So I think the reason you do not see any change after using @logica0419 is currently making some change to support golangci-lint v2. Until that is released, you have to manage golangci-lint-v2 yourself. Try
Before Save: ![]() After Save: ![]() Let me know if this fixes your problem. |
@h9jiang Thank you so much! This solved my issue. For anyone who encounters this issue My goal for formatting is to format the code, add missing imports and divide imports. I'm using version: "2"
formatters:
enable:
- goimports
- gci
settings:
gci:
sections:
- standard
- default
- blank
- dot
- alias
- localmodule
custom-order: true To get this working I had to make golangci-lint version 2 available to vscode. Since vscode with the go extension manages it's own version of golangci-lint and it's currently using v1 I sat a custom name for the binary (
I then updated my vscode settings and everything worked: {
"go.alternateTools": {
"customFormatter": "golangci-lint-v2"
},
"go.formatFlags": [
"fmt",
"--stdin"
],
"go.formatTool": "custom"
} |
For anyone who used an hack like the ones that were suggested, I would like to share that vscode now supports golangci-lint v1 and v2 The documentation of golangci-lint has been updated lately. https://golangci-lint.run/welcome/integrations/#visual-studio-code I was also using the hack, and I don't need it anymore. Here is the PR that brought the change in the documentation You might find more information and some GitHub links to bounce on. |
I'm trying to set up gci as my formatter for more control over import arrangement. I think I've found the relevant extensions, but I can not get the arguments to work. Here's a configuration example:
Looking at the docs it seems like the args are just ignored:
I would have more control if I could configure formatting like so:
The text was updated successfully, but these errors were encountered: