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

x/tools/gopls: How to support opposite compilation flags at the same time #71600

Closed
Luna-CY opened this issue Feb 7, 2025 · 1 comment
Closed
Labels
gopls Issues related to the Go language server, gopls. Question Issues that are questions about using Go. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@Luna-CY
Copy link

Luna-CY commented Feb 7, 2025

gopls version

gopls version
golang.org/x/tools/gopls v0.17.1

go env

go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/path/to/go-build'
GOENV='/path/to/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/path/to/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/path/to/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn,direct'
GOROOT='/opt/homebrew/Cellar/go/1.23.6/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.23.6/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.6'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/path/to/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
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/n9/63yb4dm55_nb7hlgft8dz1dm0000gn/T/go-build2875263274=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Add a file wire.go

Add the following custom build tag

//go:build wireinject
// +build wireinject

Then generate wire_gen.go through the wire command, which will contain the following custom tag

//go:build !wireinject
// +build !wireinject

What did you see happen?

gopls cannot analyze the code in wire.go file. The error message is as follows

No packages found for open file /path/to/wire.go.
This file may be excluded due to its build tags; try adding "-tags=<build tag>" to your gopls "buildFlags" configuration
See the documentation for more information on working with build tags:
https://github.com/golang/tools/blob/master/gopls/doc/settings.md#buildflags.go list

What did you expect to see?

I hope gopls can automatically parse the wire.go file correctly

I have tried searching for answers, and there are answers that point out that buildFlags can be added to gopls to support the wireinject compilation tag

But when doing this, I will encounter another problem. Gopls will not be able to parse the wire_gen.go file because it contains the opposite !wireinject tag

Sorry, I have tried searching but have not found an effective way to support the parsing of these two opposite tags at the same time. Can anyone tell me the correct answer?

Editor and settings

No response

Logs

No response

@Luna-CY Luna-CY added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Feb 7, 2025
@gopherbot gopherbot added this to the Unreleased milestone Feb 7, 2025
@gabyhelp gabyhelp added the Question Issues that are questions about using Go. label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Question Issues that are questions about using Go. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants