gopls version: v0.16.0/go1.22.3 gopls flags: update flags: proxy extension version: 0.41.4 environment: Visual Studio Code linux initialization error: undefined issue timestamp: Tue, 25 Jun 2024 03:14:01 GMT restart history: Mon, 24 Jun 2024 16:34:36 GMT: activation (enabled: true) Mon, 24 Jun 2024 16:44:55 GMT: installation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

Describe what you observed: When I create a package named play, then rename the folder to playdos, and modify the play package declaration to an empty package declaration, gopls crashes upon pressing Ctrl+Space.

Steps to reproduce: 1. Create a package named play: ❯ ls -al total 16 drwxr-xr-x. 1 jorge jorge 52 Jun 24 22:28 ./ drwxr-xr-x. 1 jorge jorge 418 Jun 23 07:47 ../ -rw-r--r--. 1 jorge jorge 459 Jun 19 09:50 go.mod -rw-r--r--. 1 jorge jorge 2115 Jun 19 09:50 go.sum -rw-r--r--. 1 jorge jorge 85 Jun 24 22:24 main.go drwxr-xr-x. 1 jorge jorge 14 Jun 24 22:22 play/ 2. Rename the folder to playdos: ❯ mv play playdos ❯ ls playdos/ play.go 3. Modify the package declaration in play.go: go // Package play -. package play to go // Package play -. package 4. Press Ctrl+Space and gopls crashes.

panic: runtime error: slice bounds out of range [8:7]

goroutine 124 [running]:
golang.org/x/tools/gopls/internal/golang/completion.Selection.Suffix(...)
      completion.go:367
golang.org/x/tools/gopls/internal/server.toProtocolCompletionItems({0xc0008da848, 0x3, 0x0%3F}, 0xc001855280, 0xc0002b2c88)
      completion.go:114  0x9f0
golang.org/x/tools/gopls/internal/server.(*server).Completion(0xc000002000, {0x131a908, 0xc0006225a0}, 0xc00101ac80)
      completion.go:76  0x68e
golang.org/x/tools/gopls/internal/protocol.serverDispatch({0x131a940, 0xc0002ae3c0}, {0x1335fb0, 0xc000002000}, 0xc000622060, {0x131ab00, 0xc0005273c0})
      tsserver.go:361  0x2587
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3({0x131a940, 0xc0002ae3c0}, 0xc000622060, {0x131ab00, 0xc0005273c0})
      protocol.go:160  0x85
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4({0x131a940, 0xc0002ae3c0}, 0xc000622060, {0x131ab00, 0xc0005273c0})
      lsprpc.go:509  0x923
golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1({0x131a940, 0xc0002ae3c0}, 0xc000252540, {0x131ab00, 0xc0005273c0})
      handler.go:35  0xc6
golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2()
      handler.go:103  0x96
created by golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2 in goroutine 118
      handler.go:100  0x1c5
gopls stats -anon { "DirStats": { "Files": 408, "TestdataFiles": 0, "GoFiles": 4, "ModFiles": 0, "Dirs": 237 }, "GOARCH": "amd64", "GOOS": "linux", "GOPACKAGESDRIVER": "", "GOPLSCACHE": "", "GoVersion": "go1.22.3", "GoplsVersion": "v0.16.0", "InitialWorkspaceLoadDuration": "297.60698ms", "MemStats": { "HeapAlloc": 21433088, "HeapInUse": 36306944, "TotalAlloc": 334530672 }, "WorkspaceStats": { "Files": { "Total": 1384, "Largest": 395026, "Errs": 0 }, "Views": [ { "GoCommandVersion": "go1.22.4", "AllPackages": { "Packages": 218, "LargestPackage": 161, "CompiledGoFiles": 1380, "Modules": 20 }, "WorkspacePackages": { "Packages": 13, "LargestPackage": 10, "CompiledGoFiles": 35, "Modules": 1 }, "Diagnostics": 8 } ] } }

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.

Logs have been attached as a file: logs.txt

Comment From: gabyhelp

Similar Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: gopherbot

Change https://go.dev/cl/594796 mentions this issue: gopls/internal/golang/completion: fix package clause completion suffix

Comment From: findleyr

Thanks for the detailed reproducer -- it made it much easier to test and fix this crash.

Fixed in the CL above.

Comment From: gopherbot

Change https://go.dev/cl/595575 mentions this issue: [gopls-release-branch.0.16] gopls/internal/golang/completion: fix package clause completion suffix