golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.79k stars 729 forks source link

gopls v0.14.2 crashes while handling completion when packages.Load fails due to invalid go.work #3189

Closed SealOfTime closed 4 months ago

SealOfTime commented 4 months ago

gopls version: v0.14.2/go1.21.4 gopls flags: update flags: proxy extension version: 0.41.1 environment: Visual Studio Code linux initialization error: undefined issue timestamp: Fri, 23 Feb 2024 08:54:14 GMT restart history: Thu, 22 Feb 2024 22:55:57 GMT: activation (enabled: true) Thu, 22 Feb 2024 23:04:37 GMT: manual (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

Added use ./scratch/ into a go.work file, got a crash

Please attach the stack trace from the crash. A window with the error message should have popped up in the lower half of your screen. Please copy the stack trace and error messages from that window and paste it in this issue.

Error - 10:54:14 AM] 2024/02/23 10:54:14 go/packages.Load #1: err: exit status 1: stderr: go: cannot load module scratch listed in go.work file: open scratch/go.mod: no such file or directory

    snapshot=0
    directory=file:///home/user-name/Code/directory-name
    query=[/home/user-name/Code/directory-name/... builtin]
    packages=0

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xd21832]

goroutine 150 [running]:
golang.org/x/tools/gopls/internal/lsp/work.Completion.func1({0xc00013d200, 0x22?}, {0x0?, 0x0?}, {0x412385?, 0x10?})
    /home/user-name/go/pkg/mod/golang.org/x/tools/gopls@v0.14.2/internal/lsp/work/completion.go:88 +0x152
path/filepath.Walk({0xc00013d200, 0x22}, 0xc000b653e8)
    /usr/local/go/src/path/filepath/path.go:570 +0x4a
golang.org/x/tools/gopls/internal/lsp/work.Completion({0x1226428?, 0xc0001f7140?}, {0x1234d48, 0xc0002aa140}, {0x1227660, 0xc00022e7e0}, {0xef3e6878?, 0x7fc1?})
    /home/user-name/go/pkg/mod/golang.org/x/tools/gopls@v0.14.2/internal/lsp/work/completion.go:76 +0x565
golang.org/x/tools/gopls/internal/lsp.(*Server).completion(0xdd0980?, {0x1226428, 0xc0001f7140}, 0xc000304460)
    /home/user-name/go/pkg/mod/golang.org/x/tools/gopls@v0.14.2/internal/lsp/completion.go:44 +0x44f
golang.org/x/tools/gopls/internal/lsp.(*Server).Completion(0xc0004b8120?, {0x1226460?, 0xc00040f2c0?}, 0xdd0980?)
    /home/user-name/go/pkg/mod/golang.org/x/tools/gopls@v0.14.2/internal/lsp/server_gen.go:28 +0x1d
golang.org/x/tools/gopls/internal/lsp/protocol.serverDispatch({0x1226460, 0xc00040f2c0}, {0x1238860, 0xc0000034a0}, 0xc0001f6bd0, {0x1226620, 0xc00035a2c0})
    /home/user-name/go/pkg/mod/golang.org/x/tools/gopls@v0.14.2/internal/lsp/protocol/tsserver.go:269 +0x1edd
golang.org/x/tools/gopls/internal/lsp/lsprpc.(*StreamServer).ServeStream.ServerHandler.func3({0x1226460, 0xc00040f2c0}, 0xc0001f6bd0, {0x1226620, 0xc00035a2c0})
    /home/user-name/go/pkg/mod/golang.org/x/tools/gopls@v0.14.2/internal/lsp/protocol/protocol.go:157 +0x7e
golang.org/x/tools/gopls/internal/lsp/lsprpc.(*StreamServer).ServeStream.handshaker.func4({0x1226460, 0xc00040f2c0}, 0xc0001f6bd0, {0x1226620?, 0xc00035a2c0?})
    /home/user-name/go/pkg/mod/golang.org/x/tools/gopls@v0.14.2/internal/lsp/lsprpc/lsprpc.go:521 +0x923
golang.org/x/tools/gopls/internal/lsp/protocol.Handlers.MustReplyHandler.func1({0x1226460, 0xc00040f2c0}, 0xc000362b70, {0x1226620?, 0xc00035a2c0?})
    /home/user-name/go/pkg/mod/golang.org/x/tools@v0.14.1-0.20231114185516-c9d3e7de13fd/internal/jsonrpc2/handler.go:35 +0xe5
golang.org/x/tools/gopls/internal/lsp/protocol.Handlers.AsyncHandler.func2.2()
    /home/user-name/go/pkg/mod/golang.org/x/tools@v0.14.1-0.20231114185516-c9d3e7de13fd/internal/jsonrpc2/handler.go:103 +0x96
created by golang.org/x/tools/gopls/internal/lsp/protocol.Handlers.AsyncHandler.func2 in goroutine 139
    /home/user-name/go/pkg/mod/golang.org/x/tools@v0.14.1-0.20231114185516-c9d3e7de13fd/internal/jsonrpc2/handler.go:100 +0x1ed
[Error - 10:54:14 AM] 

Failed to auto-collect gopls trace: incomplete panic trace.

gopls stats -anon gopls stats -anon failed after running for 943ms

OPTIONAL: If you would like to share more information, you can attach your complete gopls logs.

NOTE: THESE MAY CONTAIN SENSITIVE INFORMATION ABOUT YOUR CODEBASE. DO NOT SHARE LOGS IF YOU ARE WORKING IN A PRIVATE REPOSITORY.

hyangah commented 4 months ago

Thanks for the detailed report. @SealOfTime Did you hand-edit the go.work file to include use ./scratch/?

It looks like gopls v0.15.0-pre.5 (the upcoming release) doesn't crash, but reports this as an error and the package loading failure progress report (so no completion, or intellisense)

Screenshot 2024-02-23 at 1 25 57 PM

We are very close to v0.15.0 release. Can you give it a try?

gopherbot commented 4 months ago

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.)