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

Using go language server with go vet #3499

Closed
SamMcEachern opened this issue Aug 21, 2024 · 4 comments
Closed

Using go language server with go vet #3499

SamMcEachern opened this issue Aug 21, 2024 · 4 comments
Milestone

Comments

@SamMcEachern
Copy link

SamMcEachern commented Aug 21, 2024

Is your feature request related to a problem? Please describe.
Hello! We want to add custom go vet tools to our vscode settings, allowing us to visualize warnings regarding the framework we are using.

The issue is that While the go language server is active, vscode-go disables the usage of go vet

if (vetDiagnosticCollection && !disableBuildAndVet && !!goConfig['vetOnSave'] && goConfig['vetOnSave'] !== 'off') {

Describe the solution you'd like
Can we enable go vet while the language server is active?

Describe alternatives you've considered
We have also tried using the any-lint package. But this is pretty limited and doesnt give a nice visualisation of the warnings like using vscode-go does

@gopherbot gopherbot added this to the Untriaged milestone Aug 21, 2024
@hyangah
Copy link
Contributor

hyangah commented Aug 26, 2024

Thanks for sharing your use case @SamMcEachern

Our current plan is to remove the vet support and related code path completely in favor of gopls.
Gopls currently does not support a custom analyzer but there is an ongoing discussion about supporting extensible gopls in golang/go#59869.

In the mean time, is it possible to hook your analyzer into a meta linter instead?
For example, a simple custom linter can be like

$ cat mylinter.sh
#!/bin/bash

go vet -vettool=$(which shadow) $@ 2>&1

from the settings.json

    "go.lintTool": "golint",
    "go.alternateTools": {
        "golint": "${workspaceRoot}/mylinter.sh"
    },

This will cause mylinter.sh to run instead of golint.
I think meta-linters like golangci-lint also supports a custom linter (https://golangci-lint.run/contributing/new-linters/#how-to-add-a-private-linter-to-golangci-lint), that is also a possibility.

@SamMcEachern
Copy link
Author

thanks for the reply @hyangah
Thats a really cool idea! I gave it a go and it seems to run my lint tool. But it seems vscode doesnt visualize the diagnostics because it think an error occurred:
[error] Error while running tool: /<my-directory>/vet.sh

It still prints the diagnostics in the output tab of vscode though. The linting tool im using outputs to stderr, and im guessing vscode-go expects the diagnostics to come to stdout?

Ill try using golangci-lint and see if I get any progress there

@hyangah
Copy link
Contributor

hyangah commented Aug 28, 2024

@SamMcEachern Thanks for staying flexible.
Yes, the extension expects the linter to output to stdout (so I had to redirect stderr to stdout in my example script in #3499 (comment)).

@SamMcEachern
Copy link
Author

@hyangah oh gotcha! It all works if I do the same in my shell script! this works really well, thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants