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

x/tools/gopls: inaccurate diagnostics after switching branches #52499

Closed
rohan-rayaraddi opened this issue Apr 20, 2022 · 3 comments
Closed

x/tools/gopls: inaccurate diagnostics after switching branches #52499

rohan-rayaraddi opened this issue Apr 20, 2022 · 3 comments
Labels
FrozenDueToAge gopls/metadata Issues related to metadata loading in gopls gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@rohan-rayaraddi
Copy link

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.

    • 1.17.6
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.

    • gopls v0.8.2
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.

    • 1.66.0
  • Check your installed extensions to get the version of the VS Code Go extension

    • v0.32.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

    • Checking configured tools....
      GOBIN: undefined
      toolsGopath:
      gopath: /Users/rohan.rayaraddi/go
      GOROOT: /usr/local/go
      PATH: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Users/rohan.rayaraddi/bin:/Users/rohan.rayaraddi/go/bin

    go: /usr/local/go/bin/go: go version go1.17.6 darwin/amd64

    go-outline: /Users/rohan.rayaraddi/go/bin/go-outline (version: unknown - )
    gotests: /Users/rohan.rayaraddi/go/bin/gotests (version: unknown - )
    gomodifytags: /Users/rohan.rayaraddi/go/bin/gomodifytags (version: unknown - )
    impl: /Users/rohan.rayaraddi/go/bin/impl (version: unknown - )
    goplay: /Users/rohan.rayaraddi/go/bin/goplay (version: unknown - )
    dlv: /Users/rohan.rayaraddi/go/bin/dlv (version: unknown - )
    staticcheck: /Users/rohan.rayaraddi/go/bin/staticcheck (version: unknown - )
    gopls: /Users/rohan.rayaraddi/go/bin/gopls (version: unknown - )

go env
Workspace Folder (nutanix-era-cloud-service): /Users/rohan.rayaraddi/nutanix-era-cloud-service
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/rohan.rayaraddi/Library/Caches/go-build"
GOENV="/Users/rohan.rayaraddi/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/rohan.rayaraddi/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/rohan.rayaraddi/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/9d/z94gzxxn5nl209kz5ylyp0s40000gp/T/go-build977718275=/tmp/go-build -gno-record-gcc-switches -fno-common"

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.

Describe the bug

Say file f1 has a struct MyStruct on branch main. f1 was renamed to f2 in branch feature and then you checkout main branch, main shows an error than Mystruct is declared twice in f1 and f2, when infact f2 does not exist in the main branch

Steps to reproduce the behavior:

described above
microsoft/vscode#147326

Screenshots or recordings

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

@findleyr findleyr changed the title go language parse error gopls: inaccurate diagnostics after switching branches Apr 21, 2022
@findleyr findleyr added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 21, 2022
@findleyr findleyr changed the title gopls: inaccurate diagnostics after switching branches x/tools/gopls: inaccurate diagnostics after switching branches Apr 22, 2022
@findleyr findleyr transferred this issue from golang/vscode-go Apr 22, 2022
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Apr 22, 2022
@gopherbot gopherbot added this to the Unreleased milestone Apr 22, 2022
@findleyr findleyr added the gopls/metadata Issues related to metadata loading in gopls label Apr 22, 2022
@findleyr findleyr self-assigned this Apr 22, 2022
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.8.4 Apr 22, 2022
@findleyr
Copy link
Contributor

Hi, I'm not sure this is a bug. I only reproduce this issue when the file is open in the editor. For example, see the gif below:

movefile

The reason this causes a type-checking error is that gopls sees f1.go on disk, but also sees f2.go in the open buffer. VS Code indicates that f2.go has been deleted on disk by striking out the tab name, and the diagnostic goes away if I close the tab.

@rohan-rayaraddi is that consistent with what you observe? If so, what did you expect to happen?

@findleyr findleyr added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 22, 2022
@rohan-rayaraddi
Copy link
Author

Hi, I believe this is true. But the type checker marks the error in both f1 and f2. I have not tried closing f2 explicitly before changing the branch. I notice the issue in file f1 but don't explicitly navigate to f2 to close it. Ideally, since f2 is not in the branch, the type checker should not be able to find it in its current scope.
I see in other editors like intellij, that it maintains a list of files open per branch, and when you switch the branch it opens or closes relevant files.

@findleyr
Copy link
Contributor

Ideally, since f2 is not in the branch, the type checker should not be able to find it in its current scope.

gopls does not know about branches (nor should it), and so does not differentiate between a file created by switching branches and a file created by running a script. Fundamentally the editor is telling gopls that f2 is open, and so gopls must compute diagnostics assuming f2 still exists.

So this sounds like an editor feature to me (not gopls or vscode-go related). I thought that perhaps vs code supports this feature, and it looks like it might?
https://stackoverflow.com/questions/61298899/how-to-configure-vs-code-to-automatically-close-deleted-files-when-switching-bra

Closing this issue as there's nothing we can do on our end.

@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls/metadata Issues related to metadata loading in gopls gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository. 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