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: go to definition within imported modules #66827

Open
rustyx opened this issue Apr 14, 2024 · 7 comments
Open

x/tools/gopls: go to definition within imported modules #66827

rustyx opened this issue Apr 14, 2024 · 7 comments
Labels
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.
Milestone

Comments

@rustyx
Copy link

rustyx commented Apr 14, 2024

Consider a Go project with main.go looking like this:

package main

import (
	"fmt"

	"github.com/google/uuid"
)

func main() {
	id := uuid.New()
	fmt.Println(id)
}

When I go to definition (F12) of uuid.New() I end up here:

func New() UUID {
	return Must(NewRandom())
}

So far so good.

But when I try to navigate futher to Must or NewRandom, I get a popup "No definition found...".

Whereas if I navigate to fmt.Println, I can navigate further into Fprintln, doPrintln, writeByte, etc.

Why is this difference in behavior between Go SDK packages and imported modules?

Shouldn't I be able to navigate within modules the same way I do in my own code and the Go SDK?

gopls version: v0.15.2

go version: 1.22

The full test project can be found at https://github.com/rustyx/issue-66827

@rustyx rustyx added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Apr 14, 2024
@gopherbot gopherbot added this to the Unreleased milestone Apr 14, 2024
@rustyx rustyx changed the title x/tools/gopls: issue title x/tools/gopls: go to definition within imported modules Apr 14, 2024
@rustyx
Copy link
Author

rustyx commented Apr 14, 2024

I wonder if this is related to #53004.

@ansaba
Copy link

ansaba commented Apr 15, 2024

cc: @findleyr

@findleyr
Copy link
Contributor

findleyr commented Apr 15, 2024

Sorry, but this didn't reproduce for me, with either VS Code or coc.nvim. (EDIT: to be clear: both of my test clients behaved as expected, and I could navigate to Must, NewRandom, etc)

Which LSP client are you using? Can you please also share the output of gopls -v version?

@findleyr findleyr added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 15, 2024
@rustyx
Copy link
Author

rustyx commented Apr 15, 2024

I have the latest gopls.

gopls -v version
Build info
----------
golang.org/x/tools/gopls v0.15.3
    golang.org/x/tools/gopls@v0.15.3 h1:zbdOidFrPTc8Bx0YrN5QKgJ0zCjyGi0L27sKQ/bDG5o=
    github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
    golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/mod@v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
    golang.org/x/sync@v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
    golang.org/x/telemetry@v0.0.0-20240209200032-7b892fcb8a78 h1:vcVnuftN4J4UKLRcgetjzfU9FjjgXUUYUc3JhFplgV4=
    golang.org/x/text@v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
    golang.org/x/tools@v0.18.1-0.20240412183611-d92ae0781217 h1:uH9jJYgeLCvblH0S+03kFO0qUDxRkbLRLFiKVVDl7ak=
    golang.org/x/vuln@v1.0.1 h1:KUas02EjQK5LTuIx1OylBQdKKZ9jeugs+HiqO5HormU=
    honnef.co/go/tools@v0.4.6 h1:oFEHCKeID7to/3autwsWfnuv69j3NsfcXbvJKuIcep8=
    mvdan.cc/gofumpt@v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
    mvdan.cc/xurls/v2@v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.22.0

Apologies for the confusion, indeed the issue actually arises only after I add the go/pkg/mod folder to the current workspace.

Try these Steps to reproduce:

  • Clone the repo https://github.com/rustyx/issue-66827
  • Go to "Workspaces: Add Folder to Workspace..." and add $HOME/go/pkg/mod/ to the workspace.
  • Open main.go, place the cursor at uuid.New(), press F12, then on NewRandom(), press F12 again.

@rustyx
Copy link
Author

rustyx commented Apr 15, 2024

@findleyr LSP client is VSCode (v1.88.1) running on Ubuntu Linux 22.04 amd64. Again apologies for not mentioning it upfront. I think the issue is specific to VSCode and having go/pkg/mod mapped as a project in the current workspace.

My current LSP session state looks like this:

Session 1

From: Cache 1

Views

ID: 1
Type: GoModView
Root: file:///home/user/src/issue-66827
Folder: issue-66827:file:///home/user/src/issue-66827
ID: 2
Type: AdHocView
Root: file:///home/user/go/pkg/mod
Folder: mod:file:///home/user/go/pkg/mod
ID: 4
Type: GoModView
Root: file:///home/user/go/pkg/mod/github.com/google/uuid@v1.6.0
Folder: mod:file:///home/user/go/pkg/mod

Overlays

file:///home/user/go/pkg/mod/github.com/google/uuid@v1.6.0/version4.go
file:///home/user/src/issue-66827/main.go

@ansaba
Copy link

ansaba commented Apr 17, 2024

This issue is reproducible only when $HOME/go/pkg/mod/ is added to the workspace.
Seems like gopls doesn't processes the module cache and it may not be the recommended way to navigate function definition.

@ansaba ansaba added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Apr 17, 2024
@findleyr
Copy link
Contributor

Indeed, I'll check that we're handling this correctly.

Since this is unlikely to affect a large number of users, I'll move this to a future release milestone.

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.17.0 Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

No branches or pull requests

4 participants