Skip to content

feat(rust): add more queries and tests #407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2024
Merged
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
65 changes: 63 additions & 2 deletions queries/rust/context.scm
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,7 +49,7 @@
(loop_expression
body: (_ (_) @context.end)
) @context

(closure_expression
body: (_ (_) @context.end)
) @context
Expand All @@ -47,10 +70,48 @@
body: (_ (_) @context.end)
) @context

(struct_expression
(type_identifier) @context.end
) @context

(union_item
body: (_ (_) @context.end)
) @context

(enum_item
body: (_ (_) @context.end)
) @context

(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
181 changes: 180 additions & 1 deletion test/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -39,3 +208,13 @@ struct Foo {
sign_in_count: u64,

}

union Bar {

a: u8,

b: u16,

c: u32,

}
33 changes: 20 additions & 13 deletions test/ts_context_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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:{} |
|
|
]]}

Expand Down