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

set GOTOOLCHAIN=go1.22.x when you are using Go>=1.22 #3669

Closed
j2gg0s opened this issue Jun 6, 2024 · 2 comments
Closed

set GOTOOLCHAIN=go1.22.x when you are using Go>=1.22 #3669

j2gg0s opened this issue Jun 6, 2024 · 2 comments

Comments

@j2gg0s
Copy link

j2gg0s commented Jun 6, 2024

What happened

I’ve noticed that GoDef has significantly slowed down when using Go >= 1.22.

The logs for jumping to json.Marshal, 4th line show than it took 2 seconds.

     1	四  6/ 6 11:10:22 2024:["lsp#register_server","server registered","pylsp"]
     2	四  6/ 6 11:10:22 2024:["s:on_text_document_did_open()",1,"go","/Users/j2gg0s/go/src/github.com/j2gg0s/gist/vimgo","file:///Users/j2gg0s/go/src/github.com/j2gg0s/gist/vimgo/main.go"]
     3	四  6/ 6 11:10:26 2024:["s:on_text_document_did_close()",1]
     4	四  6/ 6 11:10:28 2024:["s:on_text_document_did_open()",2,"go","/Users/j2gg0s/go/src/github.com/j2gg0s/gist/vimgo","file:///Users/j2gg0s/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/encoding/json/encode.go"]
     5	四  6/ 6 11:10:28 2024:["s:on_text_document_did_open()",2,"go","/Users/j2gg0s/go/src/github.com/j2gg0s/gist/vimgo","file:///Users/j2gg0s/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/encoding/json/encode.go"]

Why

vim-go's call chain: DidOpen -> ModuleRoot -> go env GOMOD.
However, we can't invoke go env in go's src directory when go>=1.22.

➜  json pwd
/Users/j2gg0s/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/encoding/json
➜  json go env GOMOD
go: downloading go1.22 (darwin/arm64)
go: download go1.22 for darwin/arm64: toolchain not available

Go inferred an incorrect version, it should be go1.22.x

Quick fix

Set env GOTOOLCHAIN=go1.22.x

GOTOOLCHAIN=go1.22.4 vim main.go

     8  四  6/ 6 11:23:59 2024:["s:on_text_document_did_open()",1,"go","/Users/j2gg0s/go/src/github.com/j2gg0s/gist/vimgo","file:///Users/j2gg0s/go/src/github.com/j2gg0s/gist/vimgo/main.go"]
     9  四  6/ 6 11:24:02 2024:["s:on_text_document_did_close()",1]
    10  四  6/ 6 11:24:02 2024:["s:on_text_document_did_open()",2,"go","/Users/j2gg0s/go/src/github.com/j2gg0s/gist/vimgo","file:///Users/j2gg0s/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/encoding/json/encode.go"]
    11  四  6/ 6 11:24:02 2024:["s:on_text_document_did_open()",2,"go","/Users/j2gg0s/go/src/github.com/j2gg0s/gist/vimgo","file:///Users/j2gg0s/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.4.darwin-arm64/src/encoding/json/encode.go"]
@bhcleek
Copy link
Collaborator

bhcleek commented Jun 6, 2024

Where are these logs coming from? They don't look like they're created by vim-go. The issue template asks for information that wasn't provided here, too.

Closing, as it does not seem to be vim-go related. If you believe this is being closed incorrectly, please create a new issue and provide the information that the issue template asks for.

@bhcleek bhcleek closed this as completed Jun 6, 2024
@j2gg0s
Copy link
Author

j2gg0s commented Jun 7, 2024

Where are these logs coming from? They don't look like they're created by vim-go. The issue template asks for information that wasn't provided here, too.

Closing, as it does not seem to be vim-go related. If you believe this is being closed incorrectly, please create a new issue and provide the information that the issue template asks for.

I'm sorry, the logs are from interactions with gopls.
I forgot that these are not the logs provided by vim-go.

I should provide some reproduction methods.
Such as:

  1. unset GOTOOLCHAIN, if you set this env.
  2. open encoding/json/encode.go with vim, Go's version should >= 1.22
  3. This will be very slow, and we can see warn messages: vim-go: could not determine appropriate working directory for gopls

The direct reason is that we cannot execute go env GOMOD in the directory where theencoding/json/encode.go is located.
I dont think this is due to vim-go, I just want to inform other users.

Of course, it would be even better if we could accommodate this situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants