Skip to content

Commit a5951d8

Browse files
committed
lsp: fix crash in documentHighlight
1 parent 1513553 commit a5951d8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/cli/lsp.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ pub fn findNode(doc: *const Document, offset: u32) u32 {
582582
var cur_idx: u32 = 1;
583583
while (cur_idx != 0) {
584584
const n = doc.html.nodes[cur_idx];
585+
if (!n.kind.isElement()) cur_idx = 0;
585586
if (n.open.start <= offset and n.open.end > offset) {
586587
break;
587588
}
@@ -599,7 +600,6 @@ pub fn findNode(doc: *const Document, offset: u32) u32 {
599600
return cur_idx;
600601
}
601602

602-
// TODO this should not allocate
603603
pub fn tagRanges(
604604
self: *Handler,
605605
arena: std.mem.Allocator,
@@ -626,6 +626,8 @@ pub fn tagRanges(
626626
}
627627
} else findNode(doc, @intCast(offset));
628628

629+
if (node_idx == 0) return &.{};
630+
629631
const node = doc.html.nodes[node_idx];
630632

631633
assert(node.kind.isElement());

0 commit comments

Comments
 (0)