internal/lsp: handle out of range panic in template parsing

Fixes golang/vscode-go#1548

Change-Id: I95911a417cecc514151e75a60253ef119803885e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/326089
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
diff --git a/internal/lsp/template/parse.go b/internal/lsp/template/parse.go
index 8077bfc..0853612 100644
--- a/internal/lsp/template/parse.go
+++ b/internal/lsp/template/parse.go
@@ -86,6 +86,7 @@
 	ans := &Parsed{
 		buf:   buf,
 		check: -1,
+		nls:   []int{-1},
 	}
 	if len(buf) == 0 {
 		ans.ParseErr = errors.New("empty buffer")
@@ -103,7 +104,6 @@
 	}
 	// at the cost of complexity we could fold this into the allAscii loop
 	ans.lines = bytes.Split(buf, []byte{'\n'})
-	ans.nls = []int{-1}
 	for i, p := range ans.buf {
 		if p == '\n' {
 			ans.nls = append(ans.nls, i)