Skip to content

Commit

Permalink
Customize it!
Browse files Browse the repository at this point in the history
  • Loading branch information
llogick committed Oct 17, 2023
1 parent 43ab6ca commit 1cffeb9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
17 changes: 13 additions & 4 deletions src/stage2/Parse.zig
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ fn parseGlobalVarDecl(p: *Parse) !Node.Index {

p.nodes.items(.data)[var_decl].rhs = init_node;

try p.expectSemicolon(.expected_semi_after_decl, false);
try p.expectSemicolon(.expected_semi_after_decl, true);
return var_decl;
}

Expand Down Expand Up @@ -2963,7 +2963,14 @@ fn parsePrimaryTypeExpr(p: *Parse) !Node.Index {
},
}
},
else => return null_node,
else => return p.addNode(.{
.tag = .unreachable_literal,
.main_token = p.tok_i,
.data = .{
.lhs = undefined,
.rhs = undefined,
},
}),
},
.keyword_error => switch (p.token_tags[p.tok_i + 1]) {
.l_brace => {
Expand Down Expand Up @@ -3312,9 +3319,11 @@ fn expectFieldInit(p: *Parse) !Node.Index {
if (p.token_tags[p.tok_i] != .period or
p.token_tags[p.tok_i + 1] != .identifier or
p.token_tags[p.tok_i + 2] != .equal)
return p.fail(.expected_initializer);
{
try p.warn(.expected_initializer); // return p.fail(.expected_initializer);
p.tok_i += 1;
} else p.tok_i += 3;

p.tok_i += 3;
return p.expectExpr();
}

Expand Down
22 changes: 14 additions & 8 deletions tests/lsp_features/completion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ test "completion - generic function" {
try testCompletion(
\\const S = struct { alpha: u32 };
\\fn foo(comptime T: type) T {}
\\const s = foo(S);
\\const foo = s.<cursor>
\\const S1 = foo(S);
\\const S2 = S1.<cursor>
, &.{
.{ .label = "alpha", .kind = .Field, .detail = "alpha: u32" },
});
try testCompletion(
\\const S = struct { alpha: u32 };
\\fn foo(any: anytype, comptime T: type) T {}
\\const s = foo(null, S);
\\const foo = s.<cursor>
\\const S1 = foo(null, S);
\\const S2 = S1.<cursor>
, &.{
.{ .label = "alpha", .kind = .Field, .detail = "alpha: u32" },
});
Expand Down Expand Up @@ -1082,7 +1082,9 @@ test "completion - struct init" {
\\ brefa: A,
\\ this_is_b: []const u8,
\\};
\\ref(.{ .arefb = .{ .brefa = .{.<cursor>} } });
\\test {
\\ ref(.{ .arefb = .{ .brefa = .{.<cursor>} } });
\\}
, &.{
.{ .label = "arefb", .kind = .Field, .detail = "arefb: B = 8" },
.{ .label = "this_is_a", .kind = .Field, .detail = "this_is_a: u32 = 9" },
Expand Down Expand Up @@ -1121,7 +1123,9 @@ test "completion - struct init" {
\\ const Self = @This();
\\ pub fn s3(self: *Self, p0: es, p1: S2) void {}
\\};
\\S3.s3(null, .{ .mye = .{} }, .{ .ref1 = .{ .ref3 = .{ .ref2 = .{ .ref1 = .{.<cursor>} } } } });
\\test {
\\ S3.s3(null, .{ .mye = .{} }, .{ .ref1 = .{ .ref3 = .{ .ref2 = .{ .ref1 = .{.<cursor>} } } } });
\\}
, &.{
.{ .label = "s1f1", .kind = .Field, .detail = "s1f1: u8" },
.{ .label = "s1f2", .kind = .Field, .detail = "s1f2: u32 = 1" },
Expand All @@ -1147,8 +1151,10 @@ test "completion - struct init" {
\\ const Self = @This();
\\ pub fn s3(self: Self, p0: es, p1: S1) void {}
\\};
\\const iofs3 = S3{};
\\iofs3.s3(.{.<cursor>});
\\test {
\\ const iofs3 = S3{};
\\ iofs3.s3(.{.<cursor>});
\\}
, &.{
.{ .label = "s1f1", .kind = .Field, .detail = "s1f1: u8" },
.{ .label = "s1f2", .kind = .Field, .detail = "s1f2: u32 = 1" },
Expand Down

0 comments on commit 1cffeb9

Please sign in to comment.