Skip to content

Commit

Permalink
fix position context on single character number literal
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Nov 20, 2024
1 parent 36982fd commit 28489a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3488,7 +3488,10 @@ pub fn getPositionContext(
// `tok` is the latter of the two.
if (!should_do_lookahead) break;
switch (tok.tag) {
.identifier, .builtin => should_do_lookahead = false,
.identifier,
.builtin,
.number_literal,
=> should_do_lookahead = false,
else => break,
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/utility/position_context.zig
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,24 @@ test "global error set" {
// , .global_error_set, .{});
}

test "number literal" {
try testContext(
\\var foo = <loc>5<cursor></loc>;
, .number_literal, .{});
try testContext(
\\var foo = <loc><cursor>5</loc>;
, .number_literal, .{ .lookahead = true });
}

test "char literal" {
try testContext(
\\var foo = <loc>'5<cursor>'</loc>;
, .char_literal, .{ .lookahead = true });
try testContext(
\\var foo = <loc>'<cursor>5'</loc>;
, .char_literal, .{ .lookahead = true });
}

test "enum literal" {
try testContext(
\\var foo = <loc>.<cursor>tag</loc>;
Expand Down

0 comments on commit 28489a2

Please sign in to comment.