@@ -1732,6 +1732,67 @@ test "decl literal function call" {
17321732 });
17331733}
17341734
1735+ test "function call struct parameter completion" {
1736+ try testCompletion (
1737+ \\fn foo(s: struct {field: u32}) void {}
1738+ \\fn bar() void {
1739+ \\ foo(.<cursor>);
1740+ \\}
1741+ , &.{
1742+ .{ .label = "field" , .kind = .Field , .detail = "u32" },
1743+ });
1744+ try testCompletion (
1745+ \\fn foo(s: struct {field: u32}) void {}
1746+ \\fn bar() void {
1747+ \\ foo(.{.<cursor>);
1748+ \\}
1749+ , &.{
1750+ .{ .label = "field" , .kind = .Field , .detail = "u32" },
1751+ });
1752+ try testCompletion (
1753+ \\fn foo(s: ?struct {field: u32}) void {}
1754+ \\fn bar() void {
1755+ \\ foo(.<cursor>);
1756+ \\}
1757+ , &.{
1758+ .{ .label = "field" , .kind = .Field , .detail = "u32" },
1759+ });
1760+ try testCompletion (
1761+ \\fn foo(s: ?struct {field: u32}) void {}
1762+ \\fn bar() void {
1763+ \\ foo(.{.<cursor>);
1764+ \\}
1765+ , &.{
1766+ .{ .label = "field" , .kind = .Field , .detail = "u32" },
1767+ });
1768+ try testCompletion (
1769+ \\fn foo(s: *const struct {field: u32}) void {}
1770+ \\fn bar() void {
1771+ \\ foo(.<cursor>);
1772+ \\}
1773+ , &.{
1774+ // While the completion won't actually result in code that will compile due to creating not a pointer
1775+ // This will still assist user in actually writing code - the compiler will do the rest.
1776+ .{ .label = "field" , .kind = .Field , .detail = "u32" },
1777+ });
1778+ try testCompletion (
1779+ \\fn foo(s: *const struct {field: u32}) void {}
1780+ \\fn bar() void {
1781+ \\ foo(.{.<cursor>);
1782+ \\}
1783+ , &.{
1784+ .{ .label = "field" , .kind = .Field , .detail = "u32" },
1785+ });
1786+ try testCompletion (
1787+ \\fn foo(s: *const struct {field: u32}) void {}
1788+ \\fn bar() void {
1789+ \\ foo(&.<cursor>);
1790+ \\}
1791+ , &.{
1792+ .{ .label = "field" , .kind = .Field , .detail = "u32" },
1793+ });
1794+ }
1795+
17351796test "enum literal" {
17361797 try testCompletion (
17371798 \\const literal = .foo;
@@ -2494,6 +2555,67 @@ test "structinit" {
24942555 });
24952556}
24962557
2558+ test "structinit - anonymous" {
2559+ try testCompletion (
2560+ \\fn foo() E {
2561+ \\ const foo2: struct { alpha: u32 } = .a<cursor>
2562+ \\}
2563+ , &.{
2564+ .{ .label = "alpha" , .kind = .Field , .detail = "u32" },
2565+ });
2566+ try testCompletion (
2567+ \\var foo: struct { alpha: u32 } = undefined;
2568+ \\foo = .<cursor>
2569+ , &.{
2570+ .{ .label = "alpha" , .kind = .Field , .detail = "u32" },
2571+ });
2572+ // try testCompletion(
2573+ // \\fn foo() E {
2574+ // \\ const foo2: struct { alpha: u32 } = .{.<cursor>
2575+ // \\}
2576+ // , &.{
2577+ // .{ .label = "alpha", .kind = .Field, .detail = "u32" },
2578+ // });
2579+ // try testCompletion(
2580+ // \\fn foo() E {
2581+ // \\ const foo2: struct { alpha: u32 } = .<cursor>
2582+ // \\}
2583+ // , &.{
2584+ // .{ .label = "alpha", .kind = .Field, .detail = "u32" },
2585+ // });
2586+ // try testCompletion(
2587+ // \\const foo2: struct { alpha: u32 } = .a<cursor>
2588+ // , &.{
2589+ // .{ .label = "alpha", .kind = .Field, .detail = "u32" },
2590+ // });
2591+ }
2592+
2593+ test "structinit - address of" {
2594+ try testCompletion (
2595+ \\const T = struct { a: u32 };
2596+ \\var t: ?*const T = &.<cursor>
2597+ , &.{
2598+ .{ .label = "a" , .kind = .Field , .detail = "u32" },
2599+ });
2600+ try testCompletion (
2601+ \\const T = struct { a: u32 };
2602+ \\var t: ?*const T = undefined;
2603+ \\t = &.<cursor>
2604+ , &.{
2605+ .{ .label = "a" , .kind = .Field , .detail = "u32" },
2606+ });
2607+ // try testCompletion(
2608+ // \\var t: *const struct { a: u32 } = &.<cursor>
2609+ // , &.{
2610+ // .{ .label = "a", .kind = .Field, .detail = "u32" },
2611+ // });
2612+ // try testCompletion(
2613+ // \\var t: ?*const struct { a: u32 } = &.<cursor>
2614+ // , &.{
2615+ // .{ .label = "a", .kind = .Field, .detail = "u32" },
2616+ // });
2617+ }
2618+
24972619test "structinit - fields with and without default value" {
24982620 try testCompletionWithOptions (
24992621 \\const S = struct {
0 commit comments