Skip to content

Commit b236a0c

Browse files
committed
Customize it!
1 parent 58d87ee commit b236a0c

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

Diff for: src/stage2/Parse.zig

+39-1
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ fn parseGlobalVarDecl(p: *Parse) !Node.Index {
873873

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

876-
try p.expectSemicolon(.expected_semi_after_decl, false);
876+
try p.expectSemicolon(.expected_semi_after_decl, true);
877877
return var_decl;
878878
}
879879

@@ -2432,6 +2432,11 @@ fn parseCurlySuffixExpr(p: *Parse) !Node.Index {
24322432
if (lhs == 0) return null_node;
24332433
const lbrace = p.eatToken(.l_brace) orelse return lhs;
24342434

2435+
if (p.token_tags[p.tok_i] == .period and p.token_tags[p.tok_i + 1] == .period) { // zls
2436+
try p.warn(.expected_initializer);
2437+
p.tok_i += 1;
2438+
}
2439+
24352440
// If there are 0 or 1 items, we can use ArrayInitOne/StructInitOne;
24362441
// otherwise we use the full ArrayInit/StructInit.
24372442

@@ -2451,6 +2456,12 @@ fn parseCurlySuffixExpr(p: *Parse) !Node.Index {
24512456
// Likely just a missing comma; give error but continue parsing.
24522457
else => try p.warn(.expected_comma_after_initializer),
24532458
}
2459+
if (p.token_tags[p.tok_i] == .period) { // zls
2460+
if (p.token_tags[p.tok_i + 1] == .period or p.token_tags[p.tok_i + 1] == .r_brace) {
2461+
try p.warn(.expected_initializer);
2462+
p.tok_i += 1;
2463+
}
2464+
}
24542465
if (p.eatToken(.r_brace)) |_| break;
24552466
const next = try p.expectFieldInit();
24562467
try p.scratch.append(p.gpa, next);
@@ -2479,6 +2490,10 @@ fn parseCurlySuffixExpr(p: *Parse) !Node.Index {
24792490
}
24802491

24812492
while (true) {
2493+
if (p.token_tags[p.tok_i] == .period and p.token_tags[p.tok_i + 1] == .r_brace) { // zls
2494+
try p.warn(.expected_expr);
2495+
p.tok_i += 1;
2496+
}
24822497
if (p.eatToken(.r_brace)) |_| break;
24832498
const elem_init = try p.expectExpr();
24842499
try p.scratch.append(p.gpa, elem_init);
@@ -2851,6 +2866,11 @@ fn parsePrimaryTypeExpr(p: *Parse) !Node.Index {
28512866
const lbrace = p.tok_i + 1;
28522867
p.tok_i = lbrace + 1;
28532868

2869+
if (p.token_tags[p.tok_i] == .period and p.token_tags[p.tok_i + 1] == .period) { // zls
2870+
try p.warn(.expected_initializer);
2871+
p.tok_i += 1;
2872+
}
2873+
28542874
// If there are 0, 1, or 2 items, we can use ArrayInitDotTwo/StructInitDotTwo;
28552875
// otherwise we use the full ArrayInitDot/StructInitDot.
28562876

@@ -2870,6 +2890,12 @@ fn parsePrimaryTypeExpr(p: *Parse) !Node.Index {
28702890
// Likely just a missing comma; give error but continue parsing.
28712891
else => try p.warn(.expected_comma_after_initializer),
28722892
}
2893+
if (p.token_tags[p.tok_i] == .period) { // zls
2894+
if (p.token_tags[p.tok_i + 1] == .period or p.token_tags[p.tok_i + 1] == .r_brace) {
2895+
try p.warn(.expected_initializer);
2896+
p.tok_i += 1;
2897+
}
2898+
}
28732899
if (p.eatToken(.r_brace)) |_| break;
28742900
const next = try p.expectFieldInit();
28752901
try p.scratch.append(p.gpa, next);
@@ -2909,6 +2935,10 @@ fn parsePrimaryTypeExpr(p: *Parse) !Node.Index {
29092935
}
29102936

29112937
while (true) {
2938+
if (p.token_tags[p.tok_i] == .period and p.token_tags[p.tok_i + 1] == .r_brace) { // zls
2939+
try p.warn(.expected_expr);
2940+
p.tok_i += 1;
2941+
}
29122942
if (p.eatToken(.r_brace)) |_| break;
29132943
const elem_init = try p.expectExpr();
29142944
try p.scratch.append(p.gpa, elem_init);
@@ -3130,6 +3160,10 @@ fn expectSwitchExpr(p: *Parse) !Node.Index {
31303160
_ = try p.expectToken(.l_brace);
31313161
const cases = try p.parseSwitchProngList();
31323162
const trailing_comma = p.token_tags[p.tok_i - 1] == .comma;
3163+
if (p.token_tags[p.tok_i] == .period and p.token_tags[p.tok_i + 1] == .r_brace) { // zls
3164+
try p.warn(.expected_expr);
3165+
p.tok_i += 1;
3166+
}
31333167
_ = try p.expectToken(.r_brace);
31343168

31353169
return p.addNode(.{
@@ -3439,6 +3473,10 @@ fn parseSwitchProng(p: *Parse) !Node.Index {
34393473

34403474
if (p.eatToken(.keyword_else) == null) {
34413475
while (true) {
3476+
if (p.token_tags[p.tok_i] == .period and p.token_tags[p.tok_i + 1] == .period) { // zls
3477+
try p.warn(.expected_expr);
3478+
p.tok_i += 1;
3479+
}
34423480
const item = try p.parseSwitchItem();
34433481
if (item == 0) break;
34443482
try p.scratch.append(p.gpa, item);

Diff for: tests/lsp_features/completion.zig

+14-8
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,16 @@ test "completion - generic function" {
178178
try testCompletion(
179179
\\const S = struct { alpha: u32 };
180180
\\fn foo(comptime T: type) T {}
181-
\\const s = foo(S);
182-
\\const foo = s.<cursor>
181+
\\const S1 = foo(S);
182+
\\const S2 = S1.<cursor>
183183
, &.{
184184
.{ .label = "alpha", .kind = .Field, .detail = "alpha: u32" },
185185
});
186186
try testCompletion(
187187
\\const S = struct { alpha: u32 };
188188
\\fn foo(any: anytype, comptime T: type) T {}
189-
\\const s = foo(null, S);
190-
\\const foo = s.<cursor>
189+
\\const S1 = foo(null, S);
190+
\\const S2 = S1.<cursor>
191191
, &.{
192192
.{ .label = "alpha", .kind = .Field, .detail = "alpha: u32" },
193193
});
@@ -1230,7 +1230,9 @@ test "completion - struct init" {
12301230
\\ brefa: A,
12311231
\\ this_is_b: []const u8,
12321232
\\};
1233-
\\ref(.{ .arefb = .{ .brefa = .{.<cursor>} } });
1233+
\\test {
1234+
\\ ref(.{ .arefb = .{ .brefa = .{.<cursor>} } });
1235+
\\}
12341236
, &.{
12351237
.{ .label = "arefb", .kind = .Field, .detail = "arefb: B = 8" },
12361238
.{ .label = "this_is_a", .kind = .Field, .detail = "this_is_a: u32 = 9" },
@@ -1269,7 +1271,9 @@ test "completion - struct init" {
12691271
\\ const Self = @This();
12701272
\\ pub fn s3(self: *Self, p0: es, p1: S2) void {}
12711273
\\};
1272-
\\S3.s3(null, .{ .mye = .{} }, .{ .ref1 = .{ .ref3 = .{ .ref2 = .{ .ref1 = .{.<cursor>} } } } });
1274+
\\test {
1275+
\\ S3.s3(null, .{ .mye = .{} }, .{ .ref1 = .{ .ref3 = .{ .ref2 = .{ .ref1 = .{.<cursor>} } } } });
1276+
\\}
12731277
, &.{
12741278
.{ .label = "s1f1", .kind = .Field, .detail = "s1f1: u8" },
12751279
.{ .label = "s1f2", .kind = .Field, .detail = "s1f2: u32 = 1" },
@@ -1295,8 +1299,10 @@ test "completion - struct init" {
12951299
\\ const Self = @This();
12961300
\\ pub fn s3(self: Self, p0: es, p1: S1) void {}
12971301
\\};
1298-
\\const iofs3 = S3{};
1299-
\\iofs3.s3(.{.<cursor>});
1302+
\\test {
1303+
\\ const iofs3 = S3{};
1304+
\\ iofs3.s3(.{.<cursor>});
1305+
\\}
13001306
, &.{
13011307
.{ .label = "s1f1", .kind = .Field, .detail = "s1f1: u8" },
13021308
.{ .label = "s1f2", .kind = .Field, .detail = "s1f2: u32 = 1" },

0 commit comments

Comments
 (0)