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

Can not connect gopls when start vscode #2914

Closed
tayalone opened this issue Aug 4, 2023 · 14 comments
Closed

Can not connect gopls when start vscode #2914

tayalone opened this issue Aug 4, 2023 · 14 comments
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@tayalone
Copy link

tayalone commented Aug 4, 2023

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.20.7 darwin/arm64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.13.1
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.80.2
      2ccd690cbff1569e4a83d7c43d45101f817401dc
      arm64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.39.1
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /Users/phanupongrong-o/go
GOROOT: /Users/phanupongrong-o/goroot
PATH: /Users/phanupongrong-o/goroot/bin:/usr/local/opt/poppler-qt5/bin:/usr/local/opt/poppler-qt5/bin:/Users/phanupongrong-o/google-cloud-sdk/bin:/usr/local/opt/poppler-qt5/bin:/usr/local/opt/openjdk/bin:/Users/phanupongrong-o/.nvm/versions/node/v16.15.1/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/phanupongrong-o/go/bin://flutter/bin
PATH (vscode launched with): /usr/local/opt/poppler-qt5/bin:/usr/local/opt/poppler-qt5/bin:/Users/phanupongrong-o/google-cloud-sdk/bin:/usr/local/opt/poppler-qt5/bin:/usr/local/opt/openjdk/bin:/Users/phanupongrong-o/.nvm/versions/node/v16.15.1/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/phanupongrong-o/goroot/bin:/Users/phanupongrong-o/go/bin://flutter/bin

	go:	/Users/phanupongrong-o/goroot/bin/go: go version go1.20.7 darwin/arm64

	gotests:	not installed
	gomodifytags:	not installed
	impl:	not installed
	goplay:	not installed
	dlv:	/Users/phanupongrong-o/go/bin/dlv	(version: v1.21.0 built with go: go1.20.7)
	golint:	not installed
	gopls:	/Users/phanupongrong-o/go/bin/gopls	(version: v0.13.1 built with go: go1.20.7)

go env
Workspace Folder (2docrm): /Users/phanupongrong-o/Work/Freelance/2docrm
	GO111MODULE=""
	GOARCH="arm64"
	GOBIN=""
	GOCACHE="/Users/phanupongrong-o/Library/Caches/go-build"
	GOENV="/Users/phanupongrong-o/Library/Application Support/go/env"
	GOEXE=""
	GOEXPERIMENT=""
	GOFLAGS=""
	GOHOSTARCH="arm64"
	GOHOSTOS="darwin"
	GOINSECURE=""
	GOMODCACHE="/Users/phanupongrong-o/go/pkg/mod"
	GONOPROXY=""
	GONOSUMDB=""
	GOOS="darwin"
	GOPATH="/Users/phanupongrong-o/go"
	GOPRIVATE=""
	GOPROXY="https://proxy.golang.org,direct"
	GOROOT="/Users/phanupongrong-o/goroot"
	GOSUMDB="sum.golang.org"
	GOTMPDIR=""
	GOTOOLDIR="/Users/phanupongrong-o/goroot/pkg/tool/darwin_arm64"
	GOVCS=""
	GOVERSION="go1.20.7"
	GCCGO="gccgo"
	AR="ar"
	CC="clang"
	CXX="clang++"
	CGO_ENABLED="1"
	GOMOD="/dev/null"
	GOWORK=""
	CGO_CFLAGS="-O2 -g"
	CGO_CPPFLAGS=""
	CGO_CXXFLAGS="-O2 -g"
	CGO_FFLAGS="-O2 -g"
	CGO_LDFLAGS="-O2 -g"
	PKG_CONFIG="pkg-config"
	GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xn/h2rxdpwn51l_v1c4228wy3cm0000gn/T/go-build1531774915=/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.

    "go.toolsManagement.autoUpdate": true,
    "go.buildTags": "uint",
    "go.lintTool": "golint",
    "editor.inlineSuggest.enabled": true,
    "window.zoomLevel": -1,
    "gopls": {},

Describe the bug

Cann't Connect gopls when start vscode and I got error

fatal: morestack on g0
[Info  - 11:59:22 AM] 
true
[Error - 11:59:22 AM] gopls client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
fatal: morestack on g0
[Error - 11:59:22 AM] The gopls server failed to initialize.
[Error - 11:59:22 AM] gopls client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
Error starting language server: Error: Pending response rejected since connection got disposed

Screenshots or recordings

Screenshot 2566-08-04 at 11 59 31
@gopherbot gopherbot added this to the Untriaged milestone Aug 4, 2023
@bdarcet
Copy link

bdarcet commented Aug 4, 2023

👋 @tayalone Having a similar issue on my VSCode since yesterday. Did you find a workaround? I've tried to change the version but doesn't look like it worked

[Error - 14:00:21] gopls client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
runtime: pcHeader: magic= 0xfffffff0 pad1= 0 pad2= 0 minLC= 1 ptrSize= 8 pcHeader.textStart= 0x0 text= 0x10f0446e0 pluginpath= 
fatal error: invalid function symbol table
runtime: panic before malloc heap initialized

@bdarcet
Copy link

bdarcet commented Aug 4, 2023

@tayalone this fixed my issue golang/go#61190 (comment)

@findleyr
Copy link
Member

findleyr commented Aug 7, 2023

Yes, this looks like a broken binary due to golang/go#61190. @tayalone could you confirm that gopls version is broken?

@findleyr findleyr added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Aug 7, 2023
@gopherbot
Copy link
Collaborator

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@gopherbot gopherbot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 7, 2023
@AasmundN
Copy link

AasmundN commented Jan 8, 2024

I am experiencing a similar issue.

@findleyr
Copy link
Member

findleyr commented Jan 8, 2024

@AasmundN are you on darwin? What happens when you run gopls version?
See also https://go.dev/issue/63997

@AasmundN
Copy link

AasmundN commented Jan 8, 2024

@findleyr thanks for quick reply. I am on Sonoma 14.2.1. I have tried the solution suggested in golang/go#61190. I am currently using xcode devtools for xcode 15.1, considering trying to downgrade. I have not checked out the issue you link to, I will do that before downgrading.

Screenshot 2024-01-08 at 15 03 28
Screenshot 2024-01-08 at 15 05 07

Edit: I read through the issue, and I don't really understand what it concludes with. I am just getting started with Go.

@findleyr
Copy link
Member

findleyr commented Jan 8, 2024

@AasmundN if gopls version succeeds, then it's not the linked issue. Thanks.

I note that your gopls is version devel. How did you install it? Can you try installing gopls@latest?

go install golang.org/x/tools/gopls@latest

@AasmundN
Copy link

AasmundN commented Jan 8, 2024

@findleyr I installed it via homebrew, and also copied it over to /usr/local/go/bin/gopls like suggested in golang/go#61190 (comment). Running the command you sent doesn't seem to change anything.

Here is the error in vscode:

[Info  - 15:33:29] 
true
[Error - 15:33:29] gopls client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 15:33:29] 
[Error - 15:33:29] gopls client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
Error starting language server: Error: Pending response rejected since connection got disposed

@findleyr
Copy link
Member

findleyr commented Jan 8, 2024

Hmm, can you please try running gopls as a daemon in a terminal, to see if it gets a connection?

In a terminal, can you start gopls with gopls -listen=localhost:8091
In VS Code, can you set go.languageServerFlags to have -remote=localhost:8091.

When you restart the language server in VS Code (via the command palette: Go: Restart Language Server), you should see a connection logged in your terminal. Can you confirm?

@AasmundN
Copy link

AasmundN commented Jan 8, 2024

I ran the daemon using the command you provided, it seem to start like it should. However I still get the same error when restarting the language server in vscode. This are my vscode settings.

"gopls": { "ui.semanticTokens": true },
"go.useLanguageServer": true,
"go.languageServerFlags": [-remote=localhost:8091],
"[go]": {
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "golang.go"
},

Screenshot 2024-01-08 at 23 53 47
Screenshot 2024-01-08 at 23 53 56

If I press the update once button from the error message I get this in the ouput:
Screenshot 2024-01-08 at 23 59 04
I notice that the path given here is neither the homebrew path or /usr/local/go/bin

@findleyr
Copy link
Member

findleyr commented Jan 8, 2024

Hi, I believe -remote=localhost:8091 needs to be a string, in quotes. Then you should see a log message in your terminal about the gopls instance connecting to the daemon.

@AasmundN
Copy link

AasmundN commented Jan 8, 2024

Changed it to a string, still no luck.

@AasmundN
Copy link

AasmundN commented Jan 9, 2024

@findleyr I was able to make it connect to the language server by setting alternateTools.gopls to the gopls binary path in my homebrew directory. My current settings are

"go.alternateTools": {
  "gopls": "/opt/homebrew/bin/gopls"
},
"[go]": {
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "golang.go"
},

Intellisense and formatting seems to be working now. However I am getting some error regarding the modules in my workspace that I am not quite sure how to resolve.
Screenshot 2024-01-09 at 22 38 52

Should I change my GOPATH to the homebrew path?

EDIT: Looks like I was just missing a go.mod file. Things seem to be working like they should now. Thanks for the help 💯 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants