feat(rust): add more queries and tests

This commit is contained in:
Tom Kirchner 2024-02-23 15:44:53 -08:00 committed by Lewis Russell
parent 98bdd713ff
commit e4a259f050
3 changed files with 263 additions and 16 deletions

View file

@ -1,12 +1,35 @@
; standard if
(if_expression
consequence: (_ (_) @context.end)
) @context
; standard else
(else_clause
(block (_)) @context.end
) @context
; let if (its else is caught above)
(let_declaration
(if_expression
(block (_))) @context.end
) @context
; let else
(let_declaration
alternative: (block (_) @context.end)
) @context
; let (tuple) = (values)
(let_declaration
(tuple_pattern (_))
(tuple_expression _) @context.end
) @context
; helps with long array definitions
(let_declaration
(array_expression _) @context.end
) @context
(match_expression
body: (_ (_) @context.end)
) @context
@ -26,7 +49,7 @@
(loop_expression
body: (_ (_) @context.end)
) @context
(closure_expression
body: (_ (_) @context.end)
) @context
@ -47,6 +70,14 @@
body: (_ (_) @context.end)
) @context
(struct_expression
(type_identifier) @context.end
) @context
(union_item
body: (_ (_) @context.end)
) @context
(enum_item
body: (_ (_) @context.end)
) @context
@ -54,3 +85,33 @@
(mod_item
body: (_ (_) @context.end)
) @context
; extern
(foreign_mod_item
body: (_ (_) @context.end)
) @context
(async_block
(block (_) @context.end)
) @context
(try_block
(block (_) @context.end)
) @context
(unsafe_block
(block (_) @context.end)
) @context
; function call site; helps with long parameter lists
(call_expression
(arguments (_) @context.end)
) @context
(macro_invocation
(token_tree (_) @context.end)
) @context
(macro_definition
name: (_) @context.end
) @context

View file

@ -20,12 +20,181 @@ impl Foo {
// comment
foo(async move {
// comment
})
}
}
try {
let Foo::Bar {
texts,
values,
} = foo().bar() else {
let a = if b {
// comment
} else {
// comment
};
}
}
short_call_site(a, b);
long_call_site(
a,
b,
c,
d,
e,
);
macro_rules! x {
// comment
() => {};
}
x! {
// comment
}
unsafe {
*0 // run
}
let short_array = [];
let long_array = [
1,
2,
3,
4,
];
let (short, tuple) = (1, 2);
let (
a,
rather,
long,
tuple,
) = (
1,
2,
3,
4,
);
}
let s = BigStruct {
a,
b,
c,
d,
};
}
pub extern "C" {
pub fn foobar(_: *u8);
}
struct Foo {
@ -39,3 +208,13 @@ struct Foo {
sign_in_count: u64,
}
union Bar {
a: u8,
b: u16,
c: u32,
}

View file

@ -122,29 +122,36 @@ describe('ts_context', function()
{2: }{1:if}{2: }{3:condition}{2: }{14:{}{2: }|
{2: }{1:for}{2: }{3:i}{2: }{1:in}{2: }{10:0}{1:..}{10:100}{2: }{14:{}{2: }|
|
^ {15:}} |
{15:}} |
{15:}} |
{15:}} |
^ {5:foo}{15:(}{4:async} {4:move}|
|
{4:struct} {9:Foo} {15:{} |
|
{5:active}{15::} {9:bool}{15:,} |
|
{5:username}{15::} {9:String}{15:,} |
|
|
|
{8:// comment}|
|
|
|
]]}
feed'14<C-e>'
screen:expect{grid=[[
{1:struct}{2: }{7:Foo}{2: }{14:{}{2: }|
{1:impl}{2: }{7:Foo}{2: }{14:{}{2: }|
{2: }{1:fn}{2: }{3:bar}{14:(}{1:&}{3:self}{14:)}{2: }{14:{}{2: }|
{2: }{1:if}{2: }{3:condition}{2: }{14:{}{2: }|
{2: }{1:for}{2: }{3:i}{2: }{1:in}{2: }{10:0}{1:..}{10:100}{2: }{14:{}{2: }|
{2: }{3:foo}{14:(}{1:async}{2: }{1:move}|
^ {15:})} |
{15:}} |
{15:}} |
|
{5:email}{15::} {9:String}{15:,} |
|
{5:sign_in_count}{15::} {9:u64}{15:,} |
^ |
{15:}} |
{6:~ }|*8
|
|
|
{4:try} {15:{} |
|
|
]]}