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: crash in completion.Selection.Suffix #68169

Closed
JorgeO3 opened this issue Jun 25, 2024 · 4 comments
Closed

x/tools/gopls: crash in completion.Selection.Suffix #68169

JorgeO3 opened this issue Jun 25, 2024 · 4 comments
Assignees
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@JorgeO3
Copy link

JorgeO3 commented Jun 25, 2024

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:
    // Package play -.
    package play
    to
    // 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

@JorgeO3 JorgeO3 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 25, 2024
@JorgeO3 JorgeO3 reopened this Jun 25, 2024
@findleyr findleyr changed the title gopls: automated issue report (crash) x/tools/gopls: crash in completion.Selection.Suffix Jun 25, 2024
@findleyr findleyr transferred this issue from golang/vscode-go Jun 25, 2024
@findleyr findleyr self-assigned this Jun 25, 2024
@findleyr findleyr added this to the gopls/v0.16.1 milestone Jun 25, 2024
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jun 25, 2024
@gopherbot
Copy link
Contributor

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

@findleyr
Copy link
Contributor

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

Fixed in the CL above.

@gopherbot
Copy link
Contributor

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

gopherbot pushed a commit to golang/tools that referenced this issue Jun 27, 2024
…kage clause completion suffix

CL 585275 introduced a call to completion.Surrounding.Suffix that
exposed a latent bug in package clause completions: the completion
content was not being correctly computed as containing the cursor.

Fix the heuristics for completing at "package<whitespace>|", so that the
surrounding content is correct.

As a result of this change the 'editRegexp' from some completion tests
now no longer includes the newline, which also seems more correct.

Fixes golang/go#68169

Change-Id: I32ea20a7f9f0096aef85ed77c64d3b4dfeedef45
Reviewed-on: https://go-review.googlesource.com/c/tools/+/594796
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Auto-Submit: Robert Findley <rfindley@google.com>
(cherry picked from commit 008ed2c)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/595575
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jul 7, 2024
This release addresses the following gopls issues:

    golang/go#68116, broken links to dependencies in the new integrated doc viewer.
    golang/go#68169, a crash in package name completion.
    golang/go#68213, a crash when hovering over an interface with an empty type set.
    golang/go#68240, additional telemetry instrumentation to help inform decisions for gopls@v0.17.0. (Note that this is local instrumentation only; a separate proposal will be filed to allow collection of this data from users who have opted in to sharing their telemetry data).
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. 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