diff --git a/README.md b/README.md index 7558184b..ae524dd7 100644 --- a/README.md +++ b/README.md @@ -1493,6 +1493,7 @@ Language scopes: - pub-self-fn: Function definitions marked `pub(self)` - pub-super-fn: Function definitions marked `pub(super)` - const-fn: Function definitions marked `const` + - async-fn: Function definitions marked `async` - mod: `mod` blocks - mod-tests: `mod tests` blocks - type-def: Type definitions (`struct`, `enum`, `union`) diff --git a/src/scoping/langs/rust.rs b/src/scoping/langs/rust.rs index b8c4d1a4..029e9e52 100644 --- a/src/scoping/langs/rust.rs +++ b/src/scoping/langs/rust.rs @@ -62,6 +62,8 @@ pub enum PreparedRustQuery { PubSuperFn, /// Function definitions marked `const` ConstFn, + /// Function definitions marked `async` + AsyncFn, /// `mod` blocks. Mod, /// `mod tests` blocks. @@ -203,6 +205,12 @@ impl From for TSQuery { (#match? @funcmods "const") ) @function_item"# } + PreparedRustQuery::AsyncFn => { + r#"(function_item + (function_modifiers) @funcmods + (#match? @funcmods "async") + ) @function_item"# + } PreparedRustQuery::Mod => "(mod_item) @mod_item", PreparedRustQuery::ModTests => { r#"(mod_item diff --git a/tests/langs/mod.rs b/tests/langs/mod.rs index 19577f79..56fdfae4 100644 --- a/tests/langs/mod.rs +++ b/tests/langs/mod.rs @@ -297,6 +297,11 @@ impl InScopeLinePart { include_str!("rust/base.rs"), Rust::new(CodeQuery::Prepared(PreparedRustQuery::ConstFn)), )] +#[case( + "base.rs_async-fn", + include_str!("rust/base.rs"), + Rust::new(CodeQuery::Prepared(PreparedRustQuery::AsyncFn)), +)] #[case( "base.rs_mod", include_str!("rust/base.rs"), diff --git a/tests/langs/snapshots/r#mod__langs__base.rs_async-fn.snap b/tests/langs/snapshots/r#mod__langs__base.rs_async-fn.snap new file mode 100644 index 00000000..d201d9c2 --- /dev/null +++ b/tests/langs/snapshots/r#mod__langs__base.rs_async-fn.snap @@ -0,0 +1,55 @@ +--- +source: tests/langs/mod.rs +expression: inscope_parts +--- +- n: 182 + l: "async fn async_main() -> Result<(), ()> {\n" + m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- n: 183 + l: " // Open a connection to the mini-redis address.\n" + m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- n: 184 + l: " let mut client = client::connect(\"127.0.0.1:6379\").await?;\n" + m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- n: 185 + l: "\n" + m: ^^ +- n: 186 + l: " // Set the key \"hello\" with value \"world\"\n" + m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- n: 187 + l: " client.set(\"hello\", \"world\".into()).await?;\n" + m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- n: 188 + l: "\n" + m: ^^ +- n: 189 + l: " // Get key \"hello\"\n" + m: ^^^^^^^^^^^^^^^^^^^^^^^^^^ +- n: 190 + l: " let result = client.get(\"hello\").await?;\n" + m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- n: 191 + l: "\n" + m: ^^ +- n: 192 + l: " println!(\"got value from the server; result={:?}\", result);\n" + m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- n: 193 + l: "\n" + m: ^^ +- n: 194 + l: " Ok(())\n" + m: ^^^^^^^^^^^^ +- n: 195 + l: "}\n" + m: "^ " +- n: 197 + l: "pub async fn async_pub_fn() -> Result<(), ()> {\n" + m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- n: 198 + l: " Ok(())\n" + m: ^^^^^^^^^^^^ +- n: 199 + l: "}\n" + m: "^ "