Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Find all references/implementations won't show where the method is called #3140

Closed
kerhbal opened this issue Mar 31, 2020 · 7 comments
Closed
Labels
upstream-gopls Issue for gopls

Comments

@kerhbal
Copy link

kerhbal commented Mar 31, 2020

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go
    • go1.14.1 darwin/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • 1.43.2
      0ba0ca52957102ca3527cf479571617f0de6ed50
      x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.13.1
  • Run go env GOOS GOARCH to get the operating system and processor architecture details
    • darwin
      amd64

Share the Go related settings you have added/edited

"go.useLanguageServer": true

Describe the bug

Find all references/implementations won't show where the method is called when this method is defined in an interface and implemented somewhere.
A clear and concise description of what you expected to happen:
Find all references/implementations should show p.print() in line 16 in screenshot below.

Steps to reproduce the behavior:

In the screen shot below, when right click on print() in line 19 and choose "Find all references/implementations", Vscode cannot see what's in line 16.
This is the case that they are in the same file, it takes a lot more effort to figure out who called this method when they are in different files.
Thank you!
Code for test:

package main

import "fmt"

type printer interface {
	print()
}

type my struct {
	a int
}

func main() {
	var p printer
	p = my{1}
	p.print()
}

func (m my) print() {
	fmt.Println(m.a)
}

Screenshots or recordings

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

Xnip2020-03-30_19-46-49

@kerhbal kerhbal changed the title Find all references/implementations won't show where the method is called Find all references/implementations won't show where the method is called when this method is defined in an interface Mar 31, 2020
@kerhbal kerhbal changed the title Find all references/implementations won't show where the method is called when this method is defined in an interface Find all references/implementations won't show where the method is called Mar 31, 2020
@stamblerre
Copy link
Contributor

What is the output of gopls -rpc.trace -v references path/to/file.go:<line>:<col>? Alternatively, you can also capture your gopls logs and share them here (details).

@stamblerre stamblerre added the upstream-gopls Issue for gopls label Mar 31, 2020
@kerhbal
Copy link
Author

kerhbal commented Mar 31, 2020

@stamblerre Thank you for the reply.
Here is the result of gopls -rpc.trace -v references <this_file>.go:19:13:

2020/03/31 09:22:48 Info:2020/03/31 09:22:48 Build info
----------
golang.org/x/tools/gopls v0.3.4
    golang.org/x/tools/[email protected] h1:4GC7q/pXQ/tsxHBGVdsMdlB4gCxVC06m/7rIXg1Px4E=
    github.com/BurntSushi/[email protected] h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/[email protected] h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
    golang.org/x/[email protected] h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=
    golang.org/x/[email protected] h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/[email protected] h1:hKrQy/q8/Xivoqgw6nGiz1jqpn1WGBLDcWLZwW0983E=
    golang.org/x/[email protected] h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
    honnef.co/go/[email protected] h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=
    mvdan.cc/xurls/[email protected] h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=

Go info
-------
go version go1.14.1 darwin/amd64

GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOENV="/Users/xxx/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/xxx/Documents/mystuff/code/golang/mygocode"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.1/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3p/rjwnk8m15038z9q2p51c31vw0000gq/T/go-build445267129=/tmp/go-build -gno-record-gcc-switches -fno-common"
2020/03/31 09:22:49 Info:2020/03/31 09:22:49 go/packages.Load
        snapshot = 0
        query = [./... builtin]
        packages = 11

@kerhbal
Copy link
Author

kerhbal commented Mar 31, 2020

And gopls logs:

[Info  - 9:20:43 AM] 2020/03/31 09:20:43 Build info
----------
golang.org/x/tools/gopls v0.3.4
    golang.org/x/tools/[email protected] h1:4GC7q/pXQ/tsxHBGVdsMdlB4gCxVC06m/7rIXg1Px4E=
    github.com/BurntSushi/[email protected] h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/[email protected] h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
    golang.org/x/[email protected] h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=
    golang.org/x/[email protected] h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/[email protected] h1:hKrQy/q8/Xivoqgw6nGiz1jqpn1WGBLDcWLZwW0983E=
    golang.org/x/[email protected] h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
    honnef.co/go/[email protected] h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=
    mvdan.cc/xurls/[email protected] h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=

Go info
-------
go version go1.14.1 darwin/amd64

GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOENV="/Users/xxx/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/xxx/Documents/mystuff/code/golang/mygocode"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.1/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3p/rjwnk8m15038z9q2p51c31vw0000gq/T/go-build900677006=/tmp/go-build -gno-record-gcc-switches -fno-common"

[Info  - 9:20:43 AM] 2020/03/31 09:20:43 go/packages.Load
	snapshot = 0
	query = [./... builtin]
	packages = 11
[Info  - 9:21:49 AM] 2020/03/31 09:21:49 91.50208ms for GOROOT=/usr/local/Cellar/go/1.14.1/libexec GOPATH=/Users/xxx/Documents/mystuff/code/golang/mygocode GO111MODULE=auto GOPROXY=https://proxy.golang.org,direct PWD=/Users/xxx/Documents/mystuff/code/golang/mygocode/src/github.com/kerhbal go [go env GOMOD]
[Info  - 9:21:49 AM] 2020/03/31 09:21:49 background imports cache refresh starting
[Info  - 9:21:49 AM] 2020/03/31 09:21:49 background refresh finished after 146.684156ms
	Error = <nil>
[Info  - 9:23:06 AM] 2020/03/31 09:23:06 background imports cache refresh starting
[Info  - 9:23:06 AM] 2020/03/31 09:23:06 background refresh finished after 38.72588ms
	Error = <nil>
[Info  - 9:25:04 AM] 2020/03/31 09:25:04 background imports cache refresh starting
[Info  - 9:25:04 AM] 2020/03/31 09:25:04 background refresh finished after 44.083261ms
	Error = <nil>
[Info  - 9:36:43 AM] 2020/03/31 09:36:43 background imports cache refresh starting
[Info  - 9:36:43 AM] 2020/03/31 09:36:43 background refresh finished after 78.268167ms
	Error = <nil>
[Info  - 9:37:25 AM] 2020/03/31 09:37:25 background imports cache refresh starting
[Info  - 9:37:25 AM] 2020/03/31 09:37:25 background refresh finished after 37.170513ms
	Error = <nil>
[Info  - 9:37:55 AM] 2020/03/31 09:37:55 background imports cache refresh starting
[Info  - 9:37:55 AM] 2020/03/31 09:37:55 background refresh finished after 36.141032ms
	Error = <nil>

@hyangah
Copy link
Contributor

hyangah commented Apr 1, 2020

@stamblerre I think this is the current limitation of gopls' analysis. Dup of golang/go#35999 which was closed as a dup of the related bug golang/go#35550 (not a perfect dupe IMO)

@stamblerre
Copy link
Contributor

Ah, thanks @hyangah, I should've read the repro before asking for extra data 😄

On golang/go#35999, @muirdm said:

I've realized that making find-references work this way has the disadvantage of needing to search all packages, not just transitive dependents.

Which was the reason that idea was abandoned. Maybe we could support this if there are no references results, or would that be too hacky?

@stamblerre
Copy link
Contributor

I reopened the upstream issue, so let's shift the conversation there, and I'll close this issue.

@kerhbal
Copy link
Author

kerhbal commented Apr 2, 2020

Thanks guys. @stamblerre @hyangah

@vscodebot vscodebot bot locked and limited conversation to collaborators May 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
upstream-gopls Issue for gopls
Projects
None yet
Development

No branches or pull requests

3 participants