mirror of
https://github.com/golang/go
synced 2024-11-18 11:14:39 -07:00
internal/span: handle character values beyond end of line in FromUTF16Column
On the assumption these implementations are designed to support/implement the LSP spec, FromUTF16Column should handle the case where a character value is beyond the end of the line. https://github.com/Microsoft/language-server-protocol/blob/gh-pages/specification.md#position: > * If the character value is greater than the line length it defaults back to the > * line length. Fixes golang/go#31883 Change-Id: I370845b7f2f046d8e84048a26bae5b23e9c27d06 Reviewed-on: https://go-review.googlesource.com/c/tools/+/185058 Run-TryBot: Paul Jolly <paul@myitcv.org.uk> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
2214986f16
commit
72ffa07ba3
@ -69,7 +69,11 @@ func FromUTF16Column(p Point, chr int, content []byte) (Point, error) {
|
||||
}
|
||||
r, w := utf8.DecodeRune(remains)
|
||||
if r == '\n' {
|
||||
return Point{}, fmt.Errorf("FromUTF16Column: chr goes beyond the line")
|
||||
// Per the LSP spec:
|
||||
//
|
||||
// > If the character value is greater than the line length it
|
||||
// > defaults back to the line length.
|
||||
break
|
||||
}
|
||||
remains = remains[w:]
|
||||
if r >= 0x10000 {
|
||||
|
@ -185,12 +185,15 @@ var fromUTF16Tests = []struct {
|
||||
post: "",
|
||||
},
|
||||
{
|
||||
scenario: "cursor beyond last character on line",
|
||||
input: funnyString,
|
||||
line: 1,
|
||||
offset: 0,
|
||||
utf16col: 6,
|
||||
err: "FromUTF16Column: chr goes beyond the line",
|
||||
scenario: "cursor beyond last character on line",
|
||||
input: funnyString,
|
||||
line: 1,
|
||||
offset: 0,
|
||||
utf16col: 6,
|
||||
resCol: 7,
|
||||
resOffset: 6,
|
||||
pre: "𐐀23",
|
||||
post: "",
|
||||
},
|
||||
{
|
||||
scenario: "cursor before funny character; second line",
|
||||
|
Loading…
Reference in New Issue
Block a user