Skip to content

Commit

Permalink
fix completion for branhes without braces
Browse files Browse the repository at this point in the history
  • Loading branch information
xdBronch committed Aug 31, 2024
1 parent af8ed6a commit 18c1c39
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3482,6 +3482,7 @@ pub fn getPositionContext(
.enum_literal => curr_ctx.ctx = .{
.enum_literal = tokenLocAppend(curr_ctx.ctx.loc().?, tok),
},
.parens_expr => curr_ctx.ctx = .{ .var_access = tok.loc },
else => {},
},
.builtin => curr_ctx.ctx = .{ .builtin = tok.loc },
Expand Down
2 changes: 1 addition & 1 deletion src/features/completions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ pub fn completionAtIndex(

switch (pos_context) {
.builtin => try completeBuiltin(&builder),
.var_access, .empty => try completeGlobal(&builder),
.var_access, .empty, .parens_expr => try completeGlobal(&builder),
.field_access => |loc| try completeFieldAccess(&builder, loc),
.global_error_set => try globalSetCompletions(&builder, .error_set),
.enum_literal => |loc| try completeDot(&builder, loc),
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 18c1c39

Please sign in to comment.