Skip to content

Commit b95b65a

Browse files
FnControlOptionTechatrix
authored andcommitted
Support self parameter detection on branching types
1 parent c990fe8 commit b95b65a

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/analysis.zig

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,17 @@ pub fn firstParamIs(
415415
else => expected_type,
416416
};
417417

418-
return deref_type.eql(deref_expected_type);
418+
return switch (deref_type.data) {
419+
.either => |entries| {
420+
for (entries) |entry| {
421+
if (entry.type_data.eql(deref_expected_type.data)) {
422+
return true;
423+
}
424+
}
425+
return false;
426+
},
427+
else => deref_type.eql(deref_expected_type),
428+
};
419429
}
420430

421431
pub fn getVariableSignature(

tests/lsp_features/completion.zig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4338,6 +4338,34 @@ test "generic function with @This() as self param" {
43384338
});
43394339
}
43404340

4341+
test "methods of branching type" {
4342+
try testCompletion(
4343+
\\const Reader = switch (undefined) {
4344+
\\ .windows => struct {
4345+
\\ fn foo(_: *Reader) bool {}
4346+
\\ },
4347+
\\ else => struct {
4348+
\\ fn bar(_: *Reader) bool {}
4349+
\\ },
4350+
\\};
4351+
\\test {
4352+
\\ var reader: Reader = undefined;
4353+
\\ reader.<cursor>
4354+
\\}
4355+
, &.{
4356+
.{
4357+
.label = "foo",
4358+
.kind = .Function,
4359+
.detail = "fn (_: *either type) bool",
4360+
},
4361+
.{
4362+
.label = "bar",
4363+
.kind = .Function,
4364+
.detail = "fn (_: *either type) bool",
4365+
},
4366+
});
4367+
}
4368+
43414369
fn testCompletion(source: []const u8, expected_completions: []const Completion) !void {
43424370
try testCompletionWithOptions(source, expected_completions, .{});
43434371
}

0 commit comments

Comments
 (0)