Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/features/completions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
40 changes: 40 additions & 0 deletions tests/lsp_features/completion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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<cursor> });
, &.{
.{ .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<cursor>);
, &.{
.{ .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(.<cursor>);
// , &.{
// .{ .label = "alpha", .kind = .Field, .detail = "u32" },
// });
}

test "anytype resolution based on callsite-references" {
try testCompletion(
\\const Writer1 = struct {
Expand Down
Loading