Skip to content

document (unfortunate) relationship between [go,gopls].buildFlags and go.lintFlags (was ["-mod=mod"] doesn't seem to work) #2932

@aathan

Description

@aathan

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.19.3 linux/amd64 * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_. - golang.org/x/tools/[email protected] h1:Q0cfPbEG1WVfgxcRZ9uKTA6/ckIRNXx6Ym7KgT/VFE4= * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. - 1.80.2 2ccd690cbff1569e4a83d7c43d45101f817401dc x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.39.1

Share the Go related settings you have added/edited

"gopls.buildFlags": [
    "-mod=mod"
],
"go.buildFlags": [
    "-mod=mod"
]

Describe the bug

"undefined: xyz (compile)" shows up for symbols that are defined but only if you need to compile with -mod=mod, despite having properly set the flag in buildFlags

Steps to reproduce the behavior:

in go.mod, use a module from github (e.g. gopkg.in/yaml.v3).
go mod vendor (not sure if vendoring is the problem)
Also, set a replace => for that module, to a local git clone.
Add a public function in your local git clone
Use/reference that function in the project that has the replace for that module...
Observe that if you leave out the gopls.buildFlags, you get red warnings about unknown functions etc.
Set the gopls.buildFlags and reload the window
Observe that after reloading the window, no red warnings exist about the unknown function (i.e., the -mod=mod took effect)
Now, Command-S (save) the file.
Observe that "undefined: yaml.Xyz() (compile)" warning in yellow appears, despite having the go.buildFlags="-mod=mod"

EDIT: I should mention, compiling on the command line with -mod=mod works. I.e., the code and go.mod etc is in fact correct, and correctly compiles vs the local git repo clone. The vscode warning seems to be based on a compile that does not reference the right version of the foreign mod.

Screenshots or recordings

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions