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

gopls diagnostics clear linter/Problems output #3511

Open
kb-sp opened this issue Aug 28, 2024 · 5 comments
Open

gopls diagnostics clear linter/Problems output #3511

kb-sp opened this issue Aug 28, 2024 · 5 comments
Assignees
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@kb-sp
Copy link

kb-sp commented Aug 28, 2024

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.23.0 darwin/arm64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
Build info
----------
golang.org/x/tools/gopls v0.16.1
    golang.org/x/tools/[email protected] h1:1hO/dCeUvjEYx3V0rVvCtOkwnpEpqS29paE+Jw4dcAc=
    github.com/BurntSushi/[email protected] h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
    golang.org/x/exp/[email protected] h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/[email protected] h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
    golang.org/x/[email protected] h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
    golang.org/x/[email protected] h1:3Wt8mZlbFwG8llny+t18kh7AXxyWePFycXMuVdHxnyM=
    golang.org/x/[email protected] h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
    golang.org/x/[email protected] h1:Kd+Z5Pm6uwYx3T2KEkeHMHUMZxDPb/q6b1m+zEcy62c=
    golang.org/x/[email protected] h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
    honnef.co/go/[email protected] h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
    mvdan.cc/[email protected] h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
    mvdan.cc/xurls/[email protected] h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.23.0
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
1.92.2
fee1edb8d6d72a0ddff41e5f71a671c23ed924b9
arm64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.42.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
# Tools Configuration


## Environment

GOBIN: undefined
toolsGopath: 
gopath: /Users/me/go
GOROOT: /Users/me/local/Cellar/go/1.23.0/libexec
PATH: /Users/me/google-cloud-sdk/bin:/opt/X11/bin:/opt/local/sbin:/opt/local/bin:/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin

## Tools

	go:	/Users/me/local/bin/go: go version go1.23.0 darwin/arm64

	gopls:	/Users/me/go/bin/gopls	(version: v0.16.1 built with go: go1.23.0)
	gotests:	/Users/me/go/bin/gotests	(version: v1.6.0 built with go: go1.23.0)
	gomodifytags:	/Users/me/go/bin/gomodifytags	(version: v1.16.0 built with go: go1.23.0)
	impl:	/Users/me/go/bin/impl	(version: v1.1.0 built with go: go1.23.0)
	goplay:	/Users/me/go/bin/goplay	(version: v1.0.0 built with go: go1.23.0)
	dlv:	/Users/me/go/bin/dlv	(version: v1.23.0 built with go: go1.23.0)
	golangci-lint:	/Users/me/go/bin/golangci-lint	(version: v1.60.3 built with go: go1.23.0)

## Go env

Workspace Folder (madhatter): /Users/me/go/src/github.com/MyCo/madhatter

	GO111MODULE=''
	GOARCH='arm64'
	GOBIN=''
	GOCACHE='/Users/me/Library/Caches/go-build'
	GOENV='/Users/me/Library/Application Support/go/env'
	GOEXE=''
	GOEXPERIMENT=''
	GOFLAGS=''
	GOHOSTARCH='arm64'
	GOHOSTOS='darwin'
	GOINSECURE=''
	GOMODCACHE='/Users/me/go/pkg/mod'
	GONOPROXY='github.com/MyCo,buf.build/gen/go,github.com/github-handle'
	GONOSUMDB='github.com/MyCo,buf.build/gen/go,github.com/github-handle'
	GOOS='darwin'
	GOPATH='/Users/me/go'
	GOPRIVATE='github.com/MyCo,buf.build/gen/go,github.com/github-handle'
	GOPROXY='https://proxy.golang.org,direct'
	GOROOT='/Users/me/local/Cellar/go/1.23.0/libexec'
	GOSUMDB='sum.golang.org'
	GOTMPDIR=''
	GOTOOLCHAIN='auto'
	GOTOOLDIR='/Users/me/local/Cellar/go/1.23.0/libexec/pkg/tool/darwin_arm64'
	GOVCS=''
	GOVERSION='go1.23.0'
	GODEBUG=''
	GOTELEMETRY='local'
	GOTELEMETRYDIR='/Users/me/Library/Application Support/go/telemetry'
	GCCGO='gccgo'
	GOARM64='v8.0'
	AR='ar'
	CC='cc'
	CXX='c++'
	CGO_ENABLED='0'
	GOMOD='/Users/me/go/src/github.com/MyCo/madhatter/go.mod'
	GOWORK='/Users/me/go/src/github.com/MyCo/madhatter/go.work'
	CGO_CFLAGS='-O2 -g'
	CGO_CPPFLAGS=''
	CGO_CXXFLAGS='-O2 -g'
	CGO_FFLAGS='-O2 -g'
	CGO_LDFLAGS='-O2 -g'
	PKG_CONFIG='pkg-config'
	GOGCCFLAGS='-fPIC -arch arm64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/9z/mn1s9hm917b11k64wnvjm7nh0000gn/T/go-build2463239726=/tmp/go-build -gno-record-gcc-switches -fno-common'

Share the Go related settings you have added/edited

  "go.lintTool": "golangci-lint",
  "go.lintOnSave": "workspace",

Describe the bug

When saving a Go file, golangci-lint runs and shows warnings in the Problems pane. But when gopls diagnostics are applied, the Problems list is completely cleared of all Go issues. Other linter issues (e.g., for JSON) remain in the Problems pane.

The OUTPUT pane shows the successful run of the linter and its output, and PROBLEMS shows the errors. But when gopls.diagnosticsDelay is hit, the PROBLEMS pane is erased, and no additional output appears in the OUTPUT pane.

REALIZATION: Only golangci-lint output from the staticcheck linter seems to be affected. Other linter issues for Go or other languages remain.

Even if the staticcheck linter has become deprecated, this behavior is super confusing. ;) Additionally, our CI/CD is gated by a standalone golangci-lint run, so it's more than cosmetic.

Steps to reproduce the behavior:

Create a file that fails the staticcheck linter (in golangci-lint), save it, and gopls diagnostics will quickly clear these entries.

.golangci.yaml:

linters:
  enable:
    staticcheck
@gopherbot gopherbot added this to the Untriaged milestone Aug 28, 2024
@findleyr
Copy link
Contributor

@hyangah this sounds like a bug: linters from multiple sources should be merged, no?

REALIZATION: Only golangci-lint output from the staticcheck linter seems to be affected. Other linter issues for Go or other languages remain.

This might because all of those other linters (for Go files) are actually being run by gopls. Gopls runs the standard vet suite, as well as staticcheck if configured with "staticcheck": true.

@kb-sp
Copy link
Author

kb-sp commented Aug 30, 2024

I'm not aware of having that on (it's not in our config, and I can't find a Settings entry that has it enabled (or configurable). If it's gopls.staticcheck in settings.json, making it false doesn't change the behavior. However, marking it manually to true does retain the messages, but they're in the broader, less-configurable context of gopls/vet, and doesn't match our golangci-lint config gating our CI/CD. Perhaps gopls.staticcheck=false shouldn't remove existing staticcheck linters?

@hyangah
Copy link
Contributor

hyangah commented Sep 5, 2024

The extension is supposed to merge and dedup the diagnostics. When deduping, it favors the reports from gopls. Can you share an example code with problems that exhibit the issue?

@hyangah hyangah added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Sep 5, 2024
@hyangah hyangah self-assigned this Sep 5, 2024
@kb-sp
Copy link
Author

kb-sp commented Sep 5, 2024

I originally made an initial pass at a test case, but a simple one-/two-package case in the same module wasn't sufficient. If I could get a pointer to the location of the code that handles the deduping, I could take a look and either run a local build and debug or figure out a potential test case.

@hyangah
Copy link
Contributor

hyangah commented Sep 5, 2024

Thanks.
The relevant code locations:

  • Where gopls diagnostics triggers dedupping:

removeDuplicateDiagnostics(lintDiagnosticCollection, uri, diagnostics);

  • Where linter diagnostics are saved:

handleDiagnosticErrors(

  • Looks like deduping is primarily based on the diagnostic report's start line but I could be wrong:

function deDupeDiagnostics(

Let us know what you find!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants