Skip to content

Commit b10edc0

Browse files
committed
completions: add parser dependent tests
1 parent be9c87d commit b10edc0

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

tests/lsp_features/completion.zig

+120
Original file line numberDiff line numberDiff line change
@@ -2995,6 +2995,126 @@ test "insert replace behaviour - file system completions" {
29952995
// zig fmt: on
29962996
}
29972997

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

0 commit comments

Comments
 (0)