go: x/tools/gopls: unimported completions produces invalid edits with windows line endings when CRLF is used

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.16.3 windows/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.6.11
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.56.0 x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.24.2
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
    • <Paste the output here>

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:

package ex

import "fmt"

func ex() {
	fmt.Println("ABC")
}

Then add for ex. math.Sqrt(2)

package ex

import (
	"fmt"	"math"
)


func ex() {
	fmt.Println("ABC")
	math.Sqrt(2)
}

Screenshots or recordings

image

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 32 (13 by maintainers)

Commits related to this issue

Most upvoted comments

@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 https://github.com/golang/vscode-go/issues/1646#issuecomment-885915102