-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: unimported completions produces invalid edits with windows line endings when CRLF is used #46791
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
Comments
Thank you for the report. This may be an formatting issue related to the use of go-diff v1.2.0: https://golang.org/issue/45732. Could you run |
Sure! PS > go version -m "C:\Users\dtsp\YandexDisk\go\bin\gopls.exe" |
Thanks! Well, that rules out this known issue. Are you able to reliably reproduce? If so, would you be able to collect rpc trace logs during a repro session, and share them here? Instructions for how to collect logs are here: |
OK, I've created simple src file before bug occurs. Then I've cleaned output and then I've added line which causes bug. Logs are attached. |
I started to record log when I had this snippet:
Then I've added And gopls autoimported
|
Thanks for your responsiveness! We're a bit baffled by the edits in your log. It looks like gopls sends the following edits:
But then the editor sends edits to insert
Do you by any chance have other extensions installed that might be triggering these edits? It looks like something is fighting with gopls. |
Don't know but this bug occures only when i switched to gopls. I can reproduce this on two my macnines. They are pretty much identical, but extensions are the same as before gopls. |
My format tool is |
I seem to recall that extensions which could previously coexist with vscode-go might night coexist well with gopls, because of the way they interact with buffer state (gopls maintains an active copy of all open buffers). So just because there was no collision before gopls was enabled does not mean that there won't be collision with gopls. So, with that being said, do you have any other extensions installed that format Go code?
If you have gopls enabled, that tool should not run. Just to narrow things down, can you run |
I cannot reproduce this with CLI. But have another interesting result:
There is no "fmt" package :) Or this is by design? Original isuue does not reproduce after I've imported packages properly. Only on the first import. Maybe there is a conflict, I don't know. But if I recreate src file bug occures. |
I think the first thing to check is to disable all other extensions and see if it's still reproducible. And, can you please share your vscode settings so we can try to locally produce it? (Command Palette -> "Preferences: Open Settings (JSON)", "Preferences: Open Workspace Settings (JSON)") |
Does it occurred for multi-module repo? Does it occurred after save file action? Does your workspace contain more than one repository? |
Screenshot shows workspace with only one folder with single file. Autoimports occures when I type exported method (or press tab for autocompetion). I don't even press "Save". Folder is part of the module. There are no nested modules. |
Can you please remove /cc @hyangah |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I've tried, even restarted VS Code, but result is the same. |
Ok, thanks for trying. One more idea--can you please remove the
settings as well? |
No luck :) Here is short video with this issue. |
Change https://golang.org/cl/319089 mentions this issue: |
Thanks for the video, which made it clear that the problem was with unimported completions. With that context we can spot in your logs an incorrect completion item:
This edit shows that gopls is trying to insert an edit after the newline (line 2 character 13), rather than on the next line. Per the LSP spec: "Positions are line end character agnostic. So you can not specify a position that denotes \r|\n or \n| where | represents the character offset." Presumably VS Code is interpreting this position as the end of the line, rather than the start of the next line, resulting in the broken formatting you experience. This is a gopls bug, and I'm not sure how we haven't encountered it before. In any case I've reproduced in a regression test, and we should be able to fix. I should say I'm only 98% sure this is the underlying problem, but we're going to fix this first. Let me reiterate how much we appreciate your willingness to follow up on this report. |
Change https://golang.org/cl/319129 mentions this issue: |
Unimported completion computes invalid text edits with windows line endings. To enable this test, add support for windows line endings in the regtest framework. Doing this required decoupling the txtar encoding from the sandbox, which was a good change anyway. For golang/vscode-go#1489 Change-Id: I6c1075fd38d24090271a7a7f33b11ddd8f9decf5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/319089 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
The root cause was confirmed and it needs fix in |
@Piotr1215 verified https://go-review.googlesource.com/c/tools/+/319129/ fixed the issue, but reported a minor problem - gopls adds an extra newline at the end of the import block - See golang/vscode-go#1646 (comment) |
@Piotr1215: Do you mind sharing a complete Go file that reproduces the extra newline issue? I can't seem to reproduce that issue. |
hi @stamblerre , no problem. Here is also another recording, showing the extra line and some jitter: https://www.screencast.com/t/Fsvwlu3j0o Code file package main
import (
"fmt"
)
func main() {
fmt.Println("hello world")
} |
@Piotr1215: Can you please share your |
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.) |
Hi, sorry for late reply. I’ve swapped to Linux a while ago and the problem disappeared. I gave the same plugins and settings synced. |
What version of Go, VS Code & VS Code Go extension are you using?
go version
to get version of Go from the VS Code integrated terminal.gopls -v version
to get version of Gopls from the VS Code integrated terminal.code -v
orcode-insiders -v
to get version of VS Code or VS Code Insiders.Go: Locate Configured Go Tools
command.gopath: C:\Users\dtsp\YandexDisk\go
GOROOT: c:\go
PATH: C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Program Files\Graphviz 2.44.1\bin;C:\Go\bin;C:\Users\dtsp\AppData\Local\Microsoft\WindowsApps;C:\Users\dtsp\AppData\Roaming\npm;C:\Users\dtsp\go\bin;C:\Users\dtsp\YandexDisk\go\bin;C:\Users\dtsp\AppData\Local\GitHubDesktop\bin;c:\flutter\bin;C:\msys64\mingw64\bin;C:\Users\dtsp\AppData\Local\Microsoft\WindowsApps;C:\Users\dtsp\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\dtsp\go\bin
gopkgs: C:\Users\dtsp\YandexDisk\go\bin\gopkgs.exe installed
go-outline: C:\Users\dtsp\YandexDisk\go\bin\go-outline.exe installed
gotests: C:\Users\dtsp\YandexDisk\go\bin\gotests.exe installed
gomodifytags: C:\Users\dtsp\YandexDisk\go\bin\gomodifytags.exe installed
impl: C:\Users\dtsp\YandexDisk\go\bin\impl.exe installed
goplay: C:\Users\dtsp\YandexDisk\go\bin\goplay.exe installed
dlv: C:\Users\dtsp\YandexDisk\go\bin\dlv.exe installed
dlv-dap: dlv-dap not installed
staticcheck: C:\Users\dtsp\YandexDisk\go\bin\staticcheck.exe installed
gopls: C:\Users\dtsp\YandexDisk\go\bin\gopls.exe installed
Describe the bug
When second imported package is called in source code it is autoimported in the same line as first one.
Steps to reproduce the behavior:
Then add for ex.
math.Sqrt(2)
package ex
Screenshots or recordings
The text was updated successfully, but these errors were encountered: