From 4e58f8f09d6d4762e6f22c0ca9ba3eba103c2ad9 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Tue, 8 Jun 2021 11:40:16 -0400 Subject: [PATCH] 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 Run-TryBot: Rebecca Stambler Reviewed-by: Robert Findley gopls-CI: kokoro TryBot-Result: Go Bot --- internal/lsp/template/parse.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/lsp/template/parse.go b/internal/lsp/template/parse.go index 8077bfc2c2..0853612a70 100644 --- a/internal/lsp/template/parse.go +++ b/internal/lsp/template/parse.go @@ -86,6 +86,7 @@ func parseBuffer(buf []byte) *Parsed { ans := &Parsed{ buf: buf, check: -1, + nls: []int{-1}, } if len(buf) == 0 { ans.ParseErr = errors.New("empty buffer") @@ -103,7 +104,6 @@ func parseBuffer(buf []byte) *Parsed { } // 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)