Skip to content

Commit

Permalink
internal/lsp: handle incorrect import with CRLF line endings
Browse files Browse the repository at this point in the history
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 <[email protected]>
Run-TryBot: Rebecca Stambler <[email protected]>
gopls-CI: kokoro <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
  • Loading branch information
stamblerre committed Jul 22, 2021
1 parent 251092d commit c740bfd
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions gopls/internal/regtest/misc/formatting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit c740bfd

Please sign in to comment.