Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

"// +build wireinject" cause gopls error  #282

Description

@ymchun

Describe the bug

If we have a go file that call wire.Build, we put a build constraint to the start of the file. The gopls will prompt the following message saying that no packages found.

No packages found for open file /some/path/wire.go: <nil>.
If this file contains build tags, try adding "-tags=<build tag>" to your gopls "buildFlag" 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).

If we remove the empty line between the build constraint and the package, it behave like the issue described here #117

To Reproduce

// +build wireinject

package cmd

Expected behavior

No warnings.

Version

go version go1.16 darwin/amd64

Additional context

My vscode settings

{
  "go.lintOnSave": "workspace",
  "go.lintTool": "golangci-lint",
  "go.useLanguageServer": true,
  "go.formatTool": "goimports",
  "[go]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
    },
    "editor.snippetSuggestions": "none"
  },
  "[go.mod]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
    }
  },
  "gopls": {
    "usePlaceholders": true,
    "staticcheck": false
  },
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions