Skip to content

Commit ca60277

Browse files
committed
completions: add parser dependent tests
1 parent 2317ebe commit ca60277

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

Diff for: tests/lsp_features/completion.zig

+120
Original file line numberDiff line numberDiff line change
@@ -2978,6 +2978,126 @@ test "insert replace behaviour - file system completions" {
29782978
// zig fmt: on
29792979
}
29802980

2981+
// These only work with the modified parser
2982+
test "parser dependent" {
2983+
try testCompletion(
2984+
\\fn alias() void {
2985+
\\ var s = Alias{.<cursor>};
2986+
\\}
2987+
\\pub const Outer = struct {
2988+
\\ pub const Inner = struct {
2989+
\\ isf1: bool = true,
2990+
\\ isf2: bool = false,
2991+
\\ };
2992+
\\};
2993+
\\const Alias0 = Outer.Inner;
2994+
\\const Alias = Alias0;
2995+
, &.{
2996+
.{ .label = "isf1", .kind = .Field, .detail = "bool = true" },
2997+
.{ .label = "isf2", .kind = .Field, .detail = "bool = false" },
2998+
});
2999+
try testCompletion(
3000+
\\const MyStruct = struct {
3001+
\\ a: bool,
3002+
\\ b: bool,
3003+
\\ fn inside() void {
3004+
\\ var s = MyStruct{.<cursor>};
3005+
\\ }
3006+
\\};
3007+
, &.{
3008+
.{ .label = "a", .kind = .Field, .detail = "bool" },
3009+
.{ .label = "b", .kind = .Field, .detail = "bool" },
3010+
});
3011+
try testCompletion(
3012+
\\const Birdie = enum {
3013+
\\ canary,
3014+
\\};
3015+
\\const E = enum {
3016+
\\ foo,
3017+
\\ bar,
3018+
\\ fn foo(e: E) void {
3019+
\\ switch (e) {.<cursor>};
3020+
\\ }
3021+
\\};
3022+
, &.{
3023+
.{ .label = "foo", .kind = .EnumMember },
3024+
.{ .label = "bar", .kind = .EnumMember },
3025+
});
3026+
try testCompletion(
3027+
\\pub const bar = struct {
3028+
\\ pub const baz = struct {
3029+
\\ pub const Foo = struct {
3030+
\\ alpha: u32 = 0,
3031+
\\ };
3032+
\\
3033+
\\ pub fn qux() u32 {
3034+
\\ return Foo{
3035+
\\ .<cursor>
3036+
\\ };
3037+
\\ }
3038+
\\ };
3039+
\\};
3040+
, &.{
3041+
.{ .label = "alpha", .kind = .Field },
3042+
});
3043+
try testCompletion(
3044+
\\pub var state: S = undefined;
3045+
\\pub const S = struct { foo: u32 };
3046+
\\
3047+
\\pub fn main() void {
3048+
\\ state.<cursor>
3049+
\\ {
3050+
\\ _ = state.foo;
3051+
\\ }
3052+
\\ state.foo;
3053+
\\}
3054+
, &.{
3055+
.{ .label = "foo", .kind = .Field },
3056+
});
3057+
try testCompletion(
3058+
\\const Birdie = enum {
3059+
\\ canary,
3060+
\\};
3061+
\\fn foo(e: Enum) void {
3062+
\\ switch (e) {.<cursor>}
3063+
\\}
3064+
\\
3065+
\\const Enum = enum {
3066+
\\ foo,
3067+
\\};
3068+
, &.{
3069+
.{ .label = "foo", .kind = .EnumMember },
3070+
});
3071+
// TODO
3072+
// Test for `fnCall(.{.})` and `fnCall(Parser.Node{. .some})` because they are handled in different places
3073+
// Test for completions after `.{` and every `,` in the following snippet
3074+
// ```
3075+
// pub fn gamma(p: Parser) void {
3076+
// return p.addNode(.{
3077+
// .tag = 1,
3078+
// .main_token = 1,
3079+
// .data = .{
3080+
// .lhs = undefined,
3081+
// .rhs = p.addNode(Parser.Node{
3082+
// .tag,
3083+
// }),
3084+
// },
3085+
// });
3086+
// }
3087+
// const Parser = struct {
3088+
// const Node = struct {
3089+
// tag: u32,
3090+
// main_token: u32,
3091+
// data: struct {
3092+
// lhs: u32,
3093+
// rhs: u32,
3094+
// },
3095+
// };
3096+
// pub fn addNode(_: Node) u32 {}
3097+
// };
3098+
// ```
3099+
}
3100+
29813101
fn testCompletion(source: []const u8, expected_completions: []const Completion) !void {
29823102
try testCompletionWithOptions(source, expected_completions, .{});
29833103
}

0 commit comments

Comments
 (0)