Skip to content

x/tools/gopls: detect tools.go files, and suppress warning #69072

Open
@Jyosua

Description

@Jyosua

I've been looking for a way to fix this for quite a bit of time and nothing I've tried has worked. I'm using oapi-codegen to generate boilerplate for my webserver. The authors of this library recommend the tools.go pattern for managing the dependency, so that go.mod can act as the single source of truth for versioning. For transparency, their readme recommends this here. Doing this actually works -- I can run go generate just fine and my code builds. However, VSCode insists on showing an error and warning in this tools.go file, marking the file and the module folder red:

image

This is driving me crazy. I'd like to at least suppress these, but I can't find any way to do so. I've tried using the lintFlags to exclude it, but it appears to be gopls and not staticcheck, so this doesn't do anything. I can't find a gopls configuration setting that will allow me to ignore this file or any issues with it, either.

For what it's worth, someone else noticed the same thing with a different library in this issue.

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.22.5 darwin/arm64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.16.1
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • Version: 1.92.1
  • 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/[username]/go
GOROOT: /opt/homebrew/Cellar/go/1.22.5/libexec
PATH: /opt/homebrew/bin:/opt/homebrew/sbin:/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:/Users/[username]/Library/Application Support/JetBrains/Toolbox/scripts:/Users/[username]/go/bin

## Tools

	go:	/opt/homebrew/bin/go: go version go1.22.5 darwin/arm64

	gopls:	/Users/[username]/go/bin/gopls	(version: v0.16.1 built with go: go1.22.5)
	gotests:	not installed
	gomodifytags:	not installed
	impl:	not installed
	goplay:	not installed
	dlv:	/Users/[username]/go/bin/dlv	(version: v1.23.0 built with go: go1.22.5)
	staticcheck:	/Users/[username]/go/bin/staticcheck	(version: v0.4.7 built with go: go1.22.5)

## Go env

Workspace Folder (point-system): /Users/[username]/Documents/Repositories/point-system

	GO111MODULE=''
	GOARCH='arm64'
	GOBIN=''
	GOCACHE='/Users/[username]/Library/Caches/go-build'
	GOENV='/Users/[username]/Library/Application Support/go/env'
	GOEXE=''
	GOEXPERIMENT=''
	GOFLAGS=''
	GOHOSTARCH='arm64'
	GOHOSTOS='darwin'
	GOINSECURE=''
	GOMODCACHE='/Users/[username]/go/pkg/mod'
	GONOPROXY=''
	GONOSUMDB=''
	GOOS='darwin'
	GOPATH='/Users/[username]/go'
	GOPRIVATE=''
	GOPROXY='https://proxy.golang.org,direct'
	GOROOT='/opt/homebrew/Cellar/go/1.22.5/libexec'
	GOSUMDB='sum.golang.org'
	GOTMPDIR=''
	GOTOOLCHAIN='auto'
	GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.5/libexec/pkg/tool/darwin_arm64'
	GOVCS=''
	GOVERSION='go1.22.5'
	GCCGO='gccgo'
	AR='ar'
	CC='cc'
	CXX='c++'
	CGO_ENABLED='1'
	GOMOD='/dev/null'
	GOWORK=''
	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 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/by/cxzl4qc57c3c8dd9p9snhn680000gn/T/go-build3419525479=/tmp/go-build -gno-record-gcc-switches -fno-common'

Share the Go related settings you have added/edited

{
    "go.lintTool": "staticcheck",
    "go.lintFlags": [
        "-exclude=gateway/tools/tools.go"
    ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/analysisIssues related to running analysis in goplshelp wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions