fix semantic tokens on if capture by ref

This commit is contained in:
Techatrix 2023-03-30 14:00:09 +02:00
parent 498517ba71
commit d9965c7834
2 changed files with 14 additions and 2 deletions

View File

@ -516,8 +516,10 @@ fn writeNodeTokens(builder: *Builder, node: Ast.Node.Index) error{OutOfMemory}!v
try writeToken(builder, if_node.ast.if_token, .keyword);
try callWriteNodeTokens(allocator, .{ builder, if_node.ast.cond_expr });
if (if_node.payload_token) |payload| {
try writeTokenMod(builder, payload, .variable, .{ .declaration = true });
if (if_node.payload_token) |payload_token| {
const capture_is_ref = token_tags[payload_token] == .asterisk;
const actual_payload = payload_token + @boolToInt(capture_is_ref);
try writeTokenMod(builder, actual_payload, .variable, .{ .declaration = true });
}
try callWriteNodeTokens(allocator, .{ builder, if_node.ast.then_expr });

View File

@ -808,6 +808,16 @@ test "semantic tokens - if" {
.{ "err", .variable, .{ .declaration = true } },
.{ "err", .variable, .{} },
});
try testSemanticTokens(
\\const foo = if (null) |*value| {};
, &.{
.{ "const", .keyword, .{} },
.{ "foo", .variable, .{ .declaration = true } },
.{ "=", .operator, .{} },
.{ "if", .keyword, .{} },
.{ "null", .keywordLiteral, .{} },
.{ "value", .variable, .{ .declaration = true } },
});
}
test "semantic tokens - while" {