From 04390f8ceb91a534280fd433cf1aa920f964e880 Mon Sep 17 00:00:00 2001 From: Damien Whitten Date: Thu, 4 Dec 2025 15:14:33 -0800 Subject: [PATCH] Fix a LSP bug with block header comments --- internal/bcl/internal/parser/fmt_test.go | 16 ++++++++++++++++ internal/bcl/internal/parser/parser.go | 1 + 2 files changed, 17 insertions(+) diff --git a/internal/bcl/internal/parser/fmt_test.go b/internal/bcl/internal/parser/fmt_test.go index 267e5a44..095af754 100644 --- a/internal/bcl/internal/parser/fmt_test.go +++ b/internal/bcl/internal/parser/fmt_test.go @@ -79,6 +79,22 @@ func TestFmtDiff(t *testing.T) { {1, 3, "\n"}, }, }) + + run("comment align", testCase{ + // Tests a bug where the comment on field f caused the block header not + // to have an end in the source, so the diff ranged from 2 to 0. + + input: s( + "", // ensures that the field with the comment is not on line 1, which would prevent the panic + "object {", + "field f // open", + "}", + ), + expected: []FmtDiff{ + {0, 1, ""}, + {2, 3, "\tfield f // open\n"}, + }, + }) } type slicePop[T any] struct { diff --git a/internal/bcl/internal/parser/parser.go b/internal/bcl/internal/parser/parser.go index d276e6b6..27504303 100644 --- a/internal/bcl/internal/parser/parser.go +++ b/internal/bcl/internal/parser/parser.go @@ -564,6 +564,7 @@ func (ww *Walker) walkStatement() (Fragment, *unexpectedTokenError) { if comment != nil { hdr.Comment = comment } + hdr.End = ww.currentPos() return hdr, nil case EOL, EOF: