From 434ec9a774a5735840bc0e122338a3a7b1e18949 Mon Sep 17 00:00:00 2001 From: Charlie Egan Date: Tue, 10 Sep 2024 14:44:49 +0100 Subject: [PATCH] lsp: Fix Eval issue caused by missing comments Related https://github.com/StyraInc/regal/pull/1088 Signed-off-by: Charlie Egan --- internal/lsp/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/lsp/server.go b/internal/lsp/server.go index febb77dd..b8531697 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -552,7 +552,7 @@ func (l *LanguageServer) StartCommandWorker(ctx context.Context) { // nolint:mai // When the first comment in the file is `regal eval: use-as-input`, the AST of that module is // used as the input rather than the contents of input.json. This is a development feature for // working on rules (built-in or custom), allowing querying the AST of the module directly. - if regalEvalUseAsInputComment.Match(currentModule.Comments[0].Text) { + if len(currentModule.Comments) > 0 && regalEvalUseAsInputComment.Match(currentModule.Comments[0].Text) { bs, err := encoding.JSON().Marshal(currentModule) if err != nil { l.logError(fmt.Errorf("failed to marshal module: %w", err))