From 0c752f569a3efd362925ea641059c7c60856053f Mon Sep 17 00:00:00 2001 From: Ian Cottrell Date: Thu, 25 Apr 2019 17:29:46 -0400 Subject: [PATCH] internal/lsp: fix utf16 conversion for end of file cursor Also remove error case that can no longer happen and the related test. Fixes golang/go#31341 Change-Id: I534956f6e835dea4334b68d0ad0297cf93920af2 Reviewed-on: https://go-review.googlesource.com/c/tools/+/173960 Run-TryBot: Ian Cottrell TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/span/utf16.go | 3 --- internal/span/utf16_test.go | 12 ------------ 2 files changed, 15 deletions(-) diff --git a/internal/span/utf16.go b/internal/span/utf16.go index ee012d02..97c06c95 100644 --- a/internal/span/utf16.go +++ b/internal/span/utf16.go @@ -40,9 +40,6 @@ func ToUTF16Column(p Point, content []byte) (int, error) { start := content[lineOffset:] // Now, truncate down to the supplied column. - if col > len(start) { // col is 1-indexed - return -1, fmt.Errorf("ToUTF16Column: length of line (%v) is less than column (%v)", len(start), col) - } start = start[:col] // and count the number of utf16 characters // in theory we could do this by hand more efficiently... diff --git a/internal/span/utf16_test.go b/internal/span/utf16_test.go index 544ceaa2..32e95683 100644 --- a/internal/span/utf16_test.go +++ b/internal/span/utf16_test.go @@ -5,15 +5,12 @@ package span_test import ( - "flag" "strings" "testing" "golang.org/x/tools/internal/span" ) -var b31341 = flag.Bool("b31341", false, "Test for issue 31341") - // The funny character below is 4 bytes long in UTF-8; two UTF-16 code points var funnyString = []byte(` 𐐀23 @@ -89,14 +86,6 @@ var toUTF16Tests = []struct { pre: "𐐀23", post: "", }, - { - scenario: "cursor beyond last character on first line", - input: funnyString, - line: 1, - col: 7, // 4 + 1 + 1 + 1 (1-indexed) - offset: 13, // 4 + 1 + 1 - err: "ToUTF16Column: length of line (6) is less than column (7)", - }, { scenario: "cursor before funny character; second line", input: funnyString, @@ -126,7 +115,6 @@ var toUTF16Tests = []struct { resUTF16col: 5, // 2 + 1 + 1 + 1 (1-indexed) pre: "𐐀45", post: "", - issue: b31341, }, { scenario: "cursor beyond end of file",