diff --git a/src/features/completions.zig b/src/features/completions.zig index 3d512e8be..944c734fe 100644 --- a/src/features/completions.zig +++ b/src/features/completions.zig @@ -1662,7 +1662,7 @@ fn collectContainerNodes( defer gpa.free(nodes); switch (handle.tree.nodeTag(nodes[0])) { - .field_access => { + .field_access, .enum_literal => { if (try builder.analyser.resolveTypeOfNode(.of(nodes[0], handle))) |ty| { try collectFieldAccessTypes(builder, dot_context, ty, &types_with_handles); return types_with_handles.keys(); diff --git a/tests/lsp_features/completion.zig b/tests/lsp_features/completion.zig index 2254f1fcb..937de10c6 100644 --- a/tests/lsp_features/completion.zig +++ b/tests/lsp_features/completion.zig @@ -3149,6 +3149,46 @@ test "function taking a generic struct arg" { }); } +test "function taking an anonymous struct arg" { + try testCompletion( + \\const Foo = struct { + \\ alpha: u32, + \\ fn init(opts: struct {alpha: u32}) Foo { + \\ return .{ .alpha = opts.alpha }; + \\ } + \\}; + \\const bar: Foo = .init(.{ .a }); + , &.{ + .{ .label = "alpha", .kind = .Field, .detail = "u32" }, + }); + + try testCompletion( + \\const Foo = struct { + \\ alpha: u32, + \\ fn init(opts: struct {alpha: u32}) Foo { + \\ return .{ .alpha = opts.alpha }; + \\ } + \\}; + \\const bar: Foo = .init(.a); + , &.{ + .{ .label = "alpha", .kind = .Field, .detail = "u32" }, + }); + + // // Not working due to parser limitations because the init function call is invalid syntax, ".init" is evaluated + // // as primitive value instead of a function call. + // try testCompletion( + // \\const Foo = struct { + // \\ alpha: u32, + // \\ fn init(opts: struct {alpha: u32}) Foo { + // \\ return .{ .alpha = opts.alpha }; + // \\ } + // \\}; + // \\const bar: Foo = .init(.); + // , &.{ + // .{ .label = "alpha", .kind = .Field, .detail = "u32" }, + // }); +} + test "anytype resolution based on callsite-references" { try testCompletion( \\const Writer1 = struct {