Skip to content

Commit

Permalink
Fix fallback logic in analysis.getPositionContext
Browse files Browse the repository at this point in the history
  • Loading branch information
llogick committed Feb 9, 2024
1 parent 0eb76c5 commit 63a54a8
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2945,10 +2945,10 @@ pub fn getPositionContext(
var stack = try std.ArrayListUnmanaged(StackState).initCapacity(allocator, 8);
defer stack.deinit(allocator);

{
var held_line = try allocator.dupeZ(u8, text[0..line_loc.end]);
defer allocator.free(held_line);
var held_line = try allocator.dupeZ(u8, text[0..line_loc.end]);
defer allocator.free(held_line);

{
var tokenizer: std.zig.Tokenizer = .{
.buffer = held_line,
.index = line_loc.start,
Expand Down Expand Up @@ -3095,19 +3095,26 @@ pub fn getPositionContext(
}
}

if (line.len == 0) return .empty;

const held_line = try allocator.dupeZ(u8, offsets.locToSlice(text, line_loc));
defer allocator.free(held_line);
const ltrimmed_line = std.mem.trimLeft(u8, line, " \t");
if (ltrimmed_line.len == 0) return .empty;

switch (line[0]) {
switch (ltrimmed_line[0]) {
'a'...'z', 'A'...'Z', '_', '@' => {},
else => return .empty,
}
var tokenizer = std.zig.Tokenizer.init(held_line);

var tokenizer: std.zig.Tokenizer = .{
.buffer = held_line,
.index = line_loc.start,
.pending_invalid_token = null,
};
const tok = tokenizer.next();

return if (tok.tag == .identifier) PositionContext{ .var_access = tok.loc } else .empty;
return switch (tok.tag) {
.identifier => PositionContext{ .var_access = tok.loc },
.builtin => PositionContext{ .builtin = tok.loc },

Check warning on line 3115 in src/analysis.zig

View check run for this annotation

Codecov / codecov/patch

src/analysis.zig#L3114-L3115

Added lines #L3114 - L3115 were not covered by tests
else => .empty,
};
}

pub const TokenWithHandle = struct {
Expand Down

0 comments on commit 63a54a8

Please sign in to comment.