Skip to content

Commit 4143355

Browse files
committed
Fix a LSP bug with block header comments
1 parent 8e3938b commit 4143355

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

internal/bcl/internal/parser/fmt_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ func TestFmtDiff(t *testing.T) {
7979
{1, 3, "\n"},
8080
},
8181
})
82+
83+
run("comment align", testCase{
84+
// Tests a bug where the comment on field f caused the block header not
85+
// to have an end in the source, so the diff ranged from 2 to 0.
86+
87+
input: s(
88+
"", // ensures that the field with the comment is not on line 1, which would prevent the panic
89+
"object {",
90+
"field f // open",
91+
"}",
92+
),
93+
expected: []FmtDiff{
94+
{0, 1, ""},
95+
{2, 3, "\tfield f // open\n"},
96+
},
97+
})
8298
}
8399

84100
type slicePop[T any] struct {

internal/bcl/internal/parser/parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ func (ww *Walker) walkStatement() (Fragment, *unexpectedTokenError) {
564564
if comment != nil {
565565
hdr.Comment = comment
566566
}
567+
hdr.End = ww.currentPos()
567568
return hdr, nil
568569

569570
case EOL, EOF:

0 commit comments

Comments
 (0)