From 9d148dee5fe969393eaed78d9bc5d27a2e575bae Mon Sep 17 00:00:00 2001 From: Charlie Egan Date: Wed, 22 May 2024 11:29:07 +0100 Subject: [PATCH] lsp: Fix ast error line index bug (#736) Signed-off-by: Charlie Egan --- internal/lsp/lint.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/internal/lsp/lint.go b/internal/lsp/lint.go index d5629384..b1371784 100644 --- a/internal/lsp/lint.go +++ b/internal/lsp/lint.go @@ -67,17 +67,16 @@ func updateParse(cache *cache.Cache, uri string) (bool, error) { diags := make([]types.Diagnostic, 0) for _, astError := range astErrors { - lineLength := 1 - - if astError.Location.Row-1 < len(lines) { - lineLength = len(lines[astError.Location.Row-1]) - } - line := astError.Location.Row - 1 if line < 0 { line = 0 } + lineLength := 1 + if line < len(lines) { + lineLength = len(lines[line]) + } + key := "regal/parse" link := "https://docs.styra.com/opa/category/rego-parse-error"