Skip to content

Commit c27c263

Browse files
Add helper function isTaggedUnionFieldWithOPV
1 parent b244a79 commit c27c263

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

src/features/completions.zig

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,19 @@ fn getReturnTypeNode(tree: *const Ast, nodes: []const Ast.Node.Index) ?Ast.Node.
14801480
return null;
14811481
}
14821482

1483+
fn isTaggedUnionFieldWithOPV(
1484+
builder: *Builder,
1485+
container: Analyser.Type,
1486+
field_type: Analyser.Type,
1487+
) bool {
1488+
if (!container.isTaggedUnion()) return false;
1489+
const ip_index = switch (field_type.data) {
1490+
.ip_index => |payload| payload.type,
1491+
else => return false,
1492+
};
1493+
return builder.analyser.ip.onePossibleValue(ip_index) != .none;
1494+
}
1495+
14831496
/// Given a Type that is a container, adds it's `.container_field*`s to completions
14841497
fn collectContainerFields(
14851498
builder: *Builder,
@@ -1518,13 +1531,9 @@ fn collectContainerFields(
15181531

15191532
const insert_text, const insert_text_format: types.InsertTextFormat = insert_text: {
15201533
if (likely != .struct_field and likely != .enum_comparison and likely != .switch_case and kind == .Field) {
1521-
if (container.isTaggedUnion() and
1522-
maybe_resolved_ty != null and
1523-
maybe_resolved_ty.?.data == .ip_index and
1524-
maybe_resolved_ty.?.data.ip_index.type != .unknown_type and
1525-
builder.analyser.ip.onePossibleValue(maybe_resolved_ty.?.data.ip_index.type) != .none)
1526-
{
1527-
break :insert_text .{ name, .PlainText };
1534+
if (maybe_resolved_ty) |ty| {
1535+
if (isTaggedUnionFieldWithOPV(builder, container, ty))
1536+
break :insert_text .{ name, .PlainText };
15281537
}
15291538

15301539
if (!builder.use_snippets) {

0 commit comments

Comments
 (0)