From 1e37be3517ab59cbbab50d780dfb042097324702 Mon Sep 17 00:00:00 2001 From: Tom Kirchner Date: Fri, 23 Feb 2024 15:44:53 -0800 Subject: [PATCH] feat(rust): add more queries and tests --- queries/rust/context.scm | 65 +++++++++++++- test/test.rs | 181 ++++++++++++++++++++++++++++++++++++++- test/ts_context_spec.lua | 33 ++++--- 3 files changed, 263 insertions(+), 16 deletions(-) diff --git a/queries/rust/context.scm b/queries/rust/context.scm index a9901e58..1f9141ec 100644 --- a/queries/rust/context.scm +++ b/queries/rust/context.scm @@ -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 diff --git a/test/test.rs b/test/test.rs index fa40a895..237dcde9 100644 --- a/test/test.rs +++ b/test/test.rs @@ -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, + +} diff --git a/test/ts_context_spec.lua b/test/ts_context_spec.lua index f98a7659..93ed0e96 100644 --- a/test/ts_context_spec.lua +++ b/test/ts_context_spec.lua @@ -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' 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:{} | + | | ]]}