Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,17 @@ pub fn firstParamIs(
else => expected_type,
};

return deref_type.eql(deref_expected_type);
return switch (deref_type.data) {
.either => |entries| {
for (entries) |entry| {
if (entry.type_data.eql(deref_expected_type.data)) {
return true;
}
}
return false;
},
else => deref_type.eql(deref_expected_type),
};
}

pub fn getVariableSignature(
Expand Down
28 changes: 28 additions & 0 deletions tests/lsp_features/completion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4338,6 +4338,34 @@ test "generic function with @This() as self param" {
});
}

test "methods of branching type" {
try testCompletion(
\\const Reader = switch (undefined) {
\\ .windows => struct {
\\ fn foo(_: *Reader) bool {}
\\ },
\\ else => struct {
\\ fn bar(_: *Reader) bool {}
\\ },
\\};
\\test {
\\ var reader: Reader = undefined;
\\ reader.<cursor>
\\}
, &.{
.{
.label = "foo",
.kind = .Function,
.detail = "fn (_: *either type) bool",
},
.{
.label = "bar",
.kind = .Function,
.detail = "fn (_: *either type) bool",
},
});
}

fn testCompletion(source: []const u8, expected_completions: []const Completion) !void {
try testCompletionWithOptions(source, expected_completions, .{});
}
Expand Down