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

Warning of missing fields when using build constraints #3270

Open
nikpivkin opened this issue Mar 21, 2024 · 2 comments
Open

Warning of missing fields when using build constraints #3270

nikpivkin opened this issue Mar 21, 2024 · 2 comments
Labels
FeatureRequest WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@nikpivkin
Copy link

nikpivkin commented Mar 21, 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.21.2 darwin/arm64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.15.2
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.87.2
      863d2581ecda6849923a2118d93a088b0745d9d6
      arm64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.41.2
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
    • toolsGopath:
      gopath: /Users/foo/go
      GOROOT: /usr/local/go

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

Workspace settings:

{
    "go.buildTags": "integration,tinygo.wasm,k8s_integration,module_integration,mage_cloudactions,wireinject,cgo"
}

Describe the bug

There are several variants of the structure for different builds: common with the constraint //go:build !tinygo.wasm and Wasm //go:build tinygo.wasm. Some methods are defined only for common builds (they will never be called in a Wasm build) and this is handled normally in IDEs like Goland or Zed but in VSCode I get a warning:

uuid.New().URN undefined (type uuid.UUID has no field or method URN)

Additional: I get the following warning for a package with a constraint for a common build:

No packages found for open file /Users/nikita/projects/trivy/pkg/uuid/uuid.go.
This file may be excluded due to its build tags; try adding "-tags=" 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-string.

Steps to reproduce the behavior:

  1. git clone git@github.com:aquasecurity/trivy.git
  2. cd trivy && code .
  3. open pkg/sbom/cyclonedx/marshal.go

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

image image
@gopherbot gopherbot added this to the Untriaged milestone Mar 21, 2024
@adonovan
Copy link
Member

Gopls automatically selects builds based on GOOS and GOARCH tags in source files, but it does not do the same for arbitrary build tags (and it seems like a difficult problem for gopls to solve). We usually advise that you set any project-specific build tags in your LSP client configuration (e.g. settings.json).

I'm curious that Zed supports the desired feature, because it uses gopls as its Go backend. Can you tell us a little about your Zed LSP configuration?

@adonovan adonovan added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 21, 2024
@nikpivkin
Copy link
Author

nikpivkin commented Mar 22, 2024

Hi @adonovan

I have specified all tags that are used in the project in the go.buildTags field (see description).

Zed has default settings, I haven't changed anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants