-
Notifications
You must be signed in to change notification settings - Fork 769
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
document (unfortunate) relationship between [go,gopls].buildFlags and go.lintFlags (was ["-mod=mod"] doesn't seem to work) #2932
Comments
It looks like this is solved by:
I'm leaving this open because well, it seems like there should be some link between these settings and/or at least some mention of the lintFlags where the relationship between the other buildFlags are described? Also, maybe instead of |
What problem do you want to solve by setting this flag? |
As described, the problem I'm trying to solve is to get correct editor error/lint/etc messages when a project requires the What I've found is that there are at least three places (as described above) where the same flags have to be provided, and I may just have found a fourth: Namely, here when I'm using the vscode debugger, I think it's using the vendor'ed module again instead of the Shouldn't there be a single setting for these flags, with these individual breakout settings used only if they're specified, so that users don't have to set 3-4 things to the same value? The current situation makes it a pain to switch back and forth between |
EDIT: I'm leaving this open in case others run into this problem, but i looks like the supported launch.json flags for the dlv-dap adapter are in fact documented (here) and Please also see: go-delve/delve#3462 I'm not sure how/if the go vscode extension is involved in what is allowed or how to specify launch.json entries relevant to the debuggering, but it seems that I cannot successfully pas |
Different lint tools have different flags. So, we cannot plumb all However, the Have you tried to remove the vendor directory instead of trying to set |
I understand. Please consider the following points:
|
For anyone arriving here searching for how to make https://github.com/golang/vscode-go/wiki/debugging#launchjson-attributes If you use the go debugger in vscode, you'll want to set |
Let's use this issue to track improving our documentation. |
The current documentation already mention the relationship between go.buildFlags and gopls.build.buildFalgs Flags to go build/go test used during build-on-save or running tests. (e.g. ["-ldflags='-s'"]) This is propagated to the language server if gopls.build.buildFlags is not specified. buildFlags is the set of flags passed on to the build system when invoked. It is applied to queries like go list, which is used when discovering files. The most common use is to set -tags. I verified the flags set with "go.buildFlags" are copied to gopls. However, gopls selectively applies flags and "-mod" flag is one of those dropped (in my case, I see the "inconsistent vendoring" errors coming from go command during package loading). @findleyr shouldn't gopls respect the user-specified mod flag? @aathan what linter are you using? Neither staticcheck nor golangci-lint accepts -mod=mod flag (so, basically setting such value in "go.lintFlags" basically makes lint functionality stop). p.s. BTW, the use case (hacking dependencies locally) is served better with |
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
Share the Go related settings you have added/edited
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.
The text was updated successfully, but these errors were encountered: