diff --git a/src/analysis.zig b/src/analysis.zig index 76f025a..b1a0c64 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -2692,9 +2692,20 @@ fn makeScopeInternal(context: ScopeContext, node_idx: Ast.Node.Index) error{OutO .block_two_semicolon, => { const first_token = tree.firstToken(node_idx); + const last_token = ast.lastToken(tree, node_idx); + + // the last token may not always be the closing brace because of broken ast + // so we look at most 16 characters ahead to find the closing brace + // TODO this should automatically be done by `ast.lastToken` + var end_index = offsets.tokenToLoc(tree, last_token).start; + const lookahead_buffer = tree.source[end_index..@min(tree.source.len, end_index + 16)]; + end_index += std.mem.indexOfScalar(u8, lookahead_buffer, '}') orelse 0; const scope_index = try context.pushScope( - offsets.nodeToLoc(tree, node_idx), + .{ + .start = offsets.tokenToIndex(tree, main_tokens[node_idx]), + .end = end_index, + }, .{ .block = node_idx }, ); defer context.popScope();