golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.89k stars 753 forks source link

display error notice #2253

Closed imilli closed 2 years ago

imilli commented 2 years ago

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.16 linux/amd64 * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_. Build info ---------- golang.org/x/tools/gopls v0.8.4 golang.org/x/tools/gopls@v0.8.4 h1:zGZsAXAb0LLws/Z+2BCWR17dkPHhIO2GYwYSSkeXX5c= github.com/google/go-cmp@v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= golang.org/x/mod@v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sys@v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c= golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/tools@v0.1.11-0.20220513164230-dfee1649af67 h1:CJwk4qG1fov4WP7/DWhhb7OQVZlQKAl1rEMnDF+ceGU= golang.org/x/vuln@v0.0.0-20220503210553-a5481fb0c8be h1:jokAF1mfylAi1iTQx7C44B7vyXUcSEMw8eDv0PzNu8s= mvdan.cc/gofumpt@v0.3.0 h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4= mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc= go: go1.16 * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. 1.67.2 c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5 x64 * Check your installed extensions to get the version of the VS Code Go extension v0.33.0 * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command. Checking configured tools.... GOBIN: undefined toolsGopath: gopath: /root/go GOROOT: /usr/local/go PATH: /usr/local/go/bin:/root/.vscode-server/bin/c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/go/bin:/root/go/bin:/usr/lib/jvm/ant/bin:/usr/lib/jvm/maven/bin:/root/.edge-ci/:/root/.ccc/bin:/root/go/bin:/root/go/bin:/usr/lib/jvm/ant/bin:/usr/lib/jvm/maven/bin:/usr/local/mysql/bin:/usr/local/mysql/lib/:/root/.edge-ci/:/root/.ccc/bin:/root/bin PATH (vscode launched with): /root/.vscode-server/bin/c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/go/bin:/root/go/bin:/root/go/bin:/usr/lib/jvm/ant/bin:/usr/lib/jvm/maven/bin:/root/.edge-ci/:/root/.ccc/bin:/usr/local/go/bin:/root/go/bin:/root/go/bin:/usr/lib/jvm/ant/bin:/usr/lib/jvm/maven/bin:/usr/local/mysql/bin:/usr/local/mysql/lib/:/root/.edge-ci/:/root/.ccc/bin:/root/bin go: /usr/local/go/bin/go: go version go1.16 linux/amd64 gotests: not installed gomodifytags: not installed impl: not installed goplay: not installed dlv: /root/go/bin/dlv (version: v1.8.3 built with go: go1.16) staticcheck: /root/go/bin/staticcheck (version: v0.2.2 built with go: go1.16) gopls: /root/go/bin/gopls (version: v0.8.4 built with go: go1.16) go env Workspace Folder (code): /data/code GO111MODULE="auto" GOARCH="amd64" GOBIN="" GOCACHE="/root/.cache/go-build" GOENV="/root/.config/go/env" GOEXE="" GOFLAGS="-mod=mod" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/root/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/root/go" GOPRIVATE="" GOPROXY="https://goproxy.cn,direct" GOROOT="/usr/local/go" GOSUMDB="off" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.16" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" 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-build450663513=/tmp/go-build -gno-record-gcc-switches"

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. the config is empty: "{}"

Describe the bug

A clear and concise description of what the bug. vscode display the import error: error while importing github.com/gin-gonic/gin: missing go.sum entry for module providing package github.com/mattn/go-isatty (imported by github.com/gin-gonic/gin); to add: go get github.com/gin-gonic/gin@v1.7.7compiler but the go.sum exists in path : /root/go/pkg/mod/github.com/mattn/go-isatty@v0.0.12 A clear and concise description of what you expected to happen. vscode should not report this error

Steps to reproduce the behavior:

  1. Go to '...' open the project folder
  2. Click on '....' open the main.go of the project
  3. See error

Screenshots or recordings

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

hyangah commented 2 years ago

The error indicates the go.sum file in your workspace (not in /root/go/pkg/mod/...) is missing the entry. Can you try to run go get github.com/gin-gonic/gin@v1.7.7 as the error message indicates? (Or vscode should show go mod tidy codelens in your main project's go.mod file.

imilli commented 2 years ago

I have executed "go get GitHub com/gin-gonic/ @.*** " and "go mod tidy", Still display the error. Later, I checked the problem and found that a folder of the project contained go.mod, Delete the go.mod file and the error disappears. the file releationship: project |-go.mod |-folder |-go.mod but the project code no the error in another vscode of the same version which is on another machine

------------------ 原始邮件 ------------------ 发件人: "Hyang-Ah Hana @.>; 发送时间: 2022年5月24日(星期二) 晚上9:52 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [golang/vscode-go] display error notice (Issue #2253)

The error indicates the go.sum file in your workspace (not in /root/go/pkg/mod/...) is missing the entry. Can you try to run go get @.*** as the error message indicates? (Or vscode should show go mod tidy codelens in your main project's go.mod file.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

hyangah commented 2 years ago

@imilli Thanks for the update. The extension assumes the directory you open is the root of the workspace, and starts processing go files from the directory. This can cause problems when the directories with go.mod (module roots) are nested. In that case, users are expected to use go.work and tell gopls and go commands which modules should be included in the workspace explicitly.

However we noticed many users work with multi-language projects where a go module directory is in a subdirectory. For example

  project (<-- user opens vscode from this directory)
     +- javascript
     +- go
           + go.mod            

To handle this rather common case with zero configuration, gopls treats this layout specially.

In your case, when you had two go.mod files

project (<-- you open vscode from here)
  +- go.mod
  +- folder
         +- go.mod

This is considered a workspace with multiple modules. The code in the project/folder belongs to a separate module and go and gopls running from the project directory won't see them unless you use go.work or gopls.experimentalWorkspaceModule setting. go mod tidy will update the project/go.mod.

When you deleted the go.mod file, gopls's special logic to handle the single, nested module can kick in and makes it to work.

For more discussions about workspace settings, please see https://github.com/golang/tools/blob/master/gopls/doc/workspace.md

I'd say this is confusing and unfortunate, but working as intended.

We hope to work on improving the workspace handling taking advantage of the new go.work support near future.

Closing.