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 <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
b5495a5ed7
commit
0c752f569a
|
@ -40,9 +40,6 @@ func ToUTF16Column(p Point, content []byte) (int, error) {
|
||||||
start := content[lineOffset:]
|
start := content[lineOffset:]
|
||||||
|
|
||||||
// Now, truncate down to the supplied column.
|
// 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]
|
start = start[:col]
|
||||||
// and count the number of utf16 characters
|
// and count the number of utf16 characters
|
||||||
// in theory we could do this by hand more efficiently...
|
// in theory we could do this by hand more efficiently...
|
||||||
|
|
|
@ -5,15 +5,12 @@
|
||||||
package span_test
|
package span_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"golang.org/x/tools/internal/span"
|
"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
|
// The funny character below is 4 bytes long in UTF-8; two UTF-16 code points
|
||||||
var funnyString = []byte(`
|
var funnyString = []byte(`
|
||||||
𐐀23
|
𐐀23
|
||||||
|
@ -89,14 +86,6 @@ var toUTF16Tests = []struct {
|
||||||
pre: "𐐀23",
|
pre: "𐐀23",
|
||||||
post: "",
|
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",
|
scenario: "cursor before funny character; second line",
|
||||||
input: funnyString,
|
input: funnyString,
|
||||||
|
@ -126,7 +115,6 @@ var toUTF16Tests = []struct {
|
||||||
resUTF16col: 5, // 2 + 1 + 1 + 1 (1-indexed)
|
resUTF16col: 5, // 2 + 1 + 1 + 1 (1-indexed)
|
||||||
pre: "𐐀45",
|
pre: "𐐀45",
|
||||||
post: "",
|
post: "",
|
||||||
issue: b31341,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
scenario: "cursor beyond end of file",
|
scenario: "cursor beyond end of file",
|
||||||
|
|
Loading…
Reference in New Issue