Skip to content

Commit 032363e

Browse files
committed
Optional first param is valid to use
1 parent 4944862 commit 032363e

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/analysis.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,13 @@ pub fn firstParamIs(
464464
.one => info.elem_ty.*,
465465
.many, .slice, .c => return false,
466466
},
467+
.optional => |opt| switch (opt.data) {
468+
.pointer => |info| switch (info.size) {
469+
.one => info.elem_ty.*,
470+
.many, .slice, .c => return false,
471+
},
472+
else => opt.*,
473+
},
467474
else => resolved_type,
468475
};
469476

tests/lsp_features/completion.zig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,22 @@ test "struct" {
13771377
.{ .label = "alpha", .kind = .Field, .detail = "u32" },
13781378
.{ .label = "beta", .kind = .Field, .detail = "[]const u8" },
13791379
});
1380+
1381+
try testCompletion(
1382+
\\const S = struct {
1383+
\\ alpha: u32,
1384+
\\ fn foo(self: S) void {
1385+
\\ self.<cursor>
1386+
\\ }
1387+
\\ fn optPtr(_: ?*S) void {}
1388+
\\ fn optValue(_: ?S) void {}
1389+
\\};
1390+
, &.{
1391+
.{ .label = "alpha", .kind = .Field, .detail = "u32" },
1392+
.{ .label = "foo", .kind = .Method, .detail = "fn (self: S) void" },
1393+
.{ .label = "optPtr", .kind = .Method, .detail = "fn (_: ?*S) void" },
1394+
.{ .label = "optValue", .kind = .Method, .detail = "fn (_: ?S) void" },
1395+
});
13801396
}
13811397

13821398
test "union" {

0 commit comments

Comments
 (0)