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>
diff --git a/internal/span/utf16.go b/internal/span/utf16.go
index 5f90a51..55e6924 100644
--- a/internal/span/utf16.go
+++ b/internal/span/utf16.go
@@ -69,7 +69,11 @@
 		}
 		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 {
diff --git a/internal/span/utf16_test.go b/internal/span/utf16_test.go
index 2762772..0ae2749 100644
--- a/internal/span/utf16_test.go
+++ b/internal/span/utf16_test.go
@@ -185,12 +185,15 @@
 		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",