Skip to content

Commit

Permalink
fix completion for branches without braces (#2015)
Browse files Browse the repository at this point in the history
  • Loading branch information
xdBronch committed Sep 8, 2024
1 parent a5e803b commit dd78968
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3473,7 +3473,11 @@ pub fn getPositionContext(
curr_ctx.ctx = .{ .string_literal = tok.loc };
},
.identifier => switch (curr_ctx.ctx) {
.empty, .pre_label, .var_access => curr_ctx.ctx = .{ .var_access = tok.loc },
.empty,
.pre_label,
.var_access,
.parens_expr,
=> curr_ctx.ctx = .{ .var_access = tok.loc },
.label => |filled| if (!filled) {
curr_ctx.ctx = .{ .label = true };
} else {
Expand Down Expand Up @@ -3561,6 +3565,7 @@ pub fn getPositionContext(
return state.ctx;
}
},
.parens_expr => |loc| return .{ .var_access = loc },
else => return state.ctx,
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/lsp_features/completion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,14 @@ test "if/for/while/catch scopes" {
, &.{
.{ .label = "T", .kind = .Constant, .detail = "u32" },
});
try testCompletion(
\\const S = struct { pub const T = u32; };
\\test {
\\ if (true) S.<cursor>
\\}
, &.{
.{ .label = "T", .kind = .Constant, .detail = "u32" },
});
try testCompletion(
\\const S = struct { pub const T = u32; };
\\test {
Expand Down

0 comments on commit dd78968

Please sign in to comment.