mirror of https://github.com/golang/go.git
internal/lsp: handle incorrect import with CRLF line endings
Going from an import line to an import block with CRLF endings did not previously work. Fixes golang/go#47200 Change-Id: I51334587ad51b828bd0828217ba39fb745d7e835 Reviewed-on: https://go-review.googlesource.com/c/tools/+/334890 Trust: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
251092de1b
commit
c740bfd9b2
|
|
@ -171,7 +171,7 @@ func TestFormattingOnSave(t *testing.T) {
|
|||
// Import organization in these files has historically been a source of bugs.
|
||||
func TestCRLFLineEndings(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
issue, want string
|
||||
issue, input, want string
|
||||
}{
|
||||
{
|
||||
issue: "41057",
|
||||
|
|
@ -222,12 +222,40 @@ func main() {
|
|||
type Tree struct {
|
||||
arr []string
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
issue: "47200",
|
||||
input: `package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
math.Sqrt(9)
|
||||
fmt.Println("hello")
|
||||
}
|
||||
`,
|
||||
want: `package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
math.Sqrt(9)
|
||||
fmt.Println("hello")
|
||||
}
|
||||
`,
|
||||
},
|
||||
} {
|
||||
t.Run(tt.issue, func(t *testing.T) {
|
||||
Run(t, "-- main.go --", func(t *testing.T, env *Env) {
|
||||
crlf := strings.ReplaceAll(tt.want, "\n", "\r\n")
|
||||
input := tt.input
|
||||
if input == "" {
|
||||
input = tt.want
|
||||
}
|
||||
crlf := strings.ReplaceAll(input, "\n", "\r\n")
|
||||
env.CreateBuffer("main.go", crlf)
|
||||
env.Await(env.DoneWithOpen())
|
||||
env.OrganizeImports("main.go")
|
||||
|
|
|
|||
Loading…
Reference in New Issue