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 goimports with line directives #51916
Comments
Thank you for the reproducer! Transferring to the Go issue tracker. |
For gopls developers, an easier example: put //line math.go:400 at the top of internal/imports/sortimports.go and save the file: panic: invalid line number 414 (should be < 21) goroutine 135 [running]: |
Change https://go.dev/cl/398395 mentions this issue: |
This is a minimal fix for the reported panic. The existing code used FileSet.Position() where it should have used FileSet.PositionFor(, false). gopls does this in lots of places; each use of Position() needs to be thought about. x/tools/go/ast/astutil/import.go:273,274 is another example. Fixes: golang/go#51916 Change-Id: I42de6affca2c97c09efb7974a9e44322556b3ffd Reviewed-on: https://go-review.googlesource.com/c/tools/+/398395 Run-TryBot: Peter Weinberger <pjw@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> Trust: Peter Weinberger <pjw@google.com>
gopls version: v0.8.1 (devel go1.19-e33711f8c1 Tue Mar 15 19:03:38 2022 -0700)
gopls flags:
update flags: proxy
extension version: 0.32.0
go version: devel 1.19-2f6c07744f
environment: Visual Studio Code darwin
initialization error: undefined
issue timestamp: Thu, 24 Mar 2022 04:46:28 GMT
restart history:
Thu, 24 Mar 2022 04:45:11 GMT: activation (enabled: true)
ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.
code .
(code
is a small script that launches VSCode with.
in this case)//line math.go:100
on the first line (before the copyright notice)import
keyword on line 10 (to provoke an error) and save the filego build -gcflags=-L
- this will produce an error like:import
keyword (don't yet save the file).I've been able to reproduce this fairly reliably with these 9 steps.
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.
<OPTIONAL: ATTACH LOGS HERE>
The text was updated successfully, but these errors were encountered: