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 use //go:build sometag #54317

Closed
gaoyusongcn opened this issue Aug 6, 2022 · 3 comments
Closed

x/tools/gopls: How to use //go:build sometag #54317

gaoyusongcn opened this issue Aug 6, 2022 · 3 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@gaoyusongcn
Copy link

I read a lot of issues. There seems to be no solution?

gopls version

go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build470319813=/tmp/go-build -gno-record-gcc-switches"

What did you do?

This case from conditional-compilation-with-build-tags

image

What did you expect to see?

I hope to fix this error message when I used //go:build !alt

What did you see instead?

vscode error:

No packages found for open file /go/src/my-practice/my/foo_alt.go: <nil>. If this file contains build tags, try adding "-tags=<build tag>" to your gopls "buildFlags" configuration (see (https://github.com/golang/tools/blob/master/gopls/doc/settings.md#buildflags-string). Otherwise, see the troubleshooting guidelines for help investigating (https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md).

Editor and settings

in project:

{
    "go.inferGopath": false,
    "gopls": {
        "build.buildFlags": [
            "-tags=alt"
        ],
    },
}

default settings:

{
  "explorer.confirmDelete": false,
  "[nginx]": {
    "editor.defaultFormatter": "ahmadalli.vscode-nginx-conf"
  },
  "workbench.iconTheme": "material-icon-theme",
  "editor.formatOnSave": true,
  "go.testFlags": ["-count=1"],
  "editor.bracketPairColorization.enabled": true,
  "editor.guides.bracketPairs": "active",
  "go.inferGopath": true,
  "workbench.colorTheme": "Default Dark+",
  "workbench.editorAssociations": {
    "*.db": "default"
  },
  "diffEditor.ignoreTrimWhitespace": false,
  "gopls": {
    
  },
}
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Aug 6, 2022
@gopherbot gopherbot added this to the Unreleased milestone Aug 6, 2022
@seankhliao
Copy link
Member

That looks like tags working correctly

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 6, 2022
@gaoyusongcn
Copy link
Author

That looks like tags working correctly

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

Thant you for your reply.

I asked here because I can't find the answer

@findleyr
Copy link
Contributor

findleyr commented Aug 8, 2022

@wonderfate I'm not sure I understand your question: you set "-tags=alt" in your configuration, and are getting an error about not having any packages for a file tagged !alt. That looks like it is working as intended: your file is being excluded by your configuration.

@golang golang locked and limited conversation to collaborators Aug 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. 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