Skip to content

Commit

Permalink
feat(rust): Scope function definitions marked async
Browse files Browse the repository at this point in the history
alexpovel committed Aug 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 0cd4ac4 commit 156f34c
Showing 4 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`)
8 changes: 8 additions & 0 deletions src/scoping/langs/rust.rs
Original file line number Diff line number Diff line change
@@ -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<PreparedRustQuery> 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
5 changes: 5 additions & 0 deletions tests/langs/mod.rs
Original file line number Diff line number Diff line change
@@ -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"),
55 changes: 55 additions & 0 deletions tests/langs/snapshots/r#mod__langs__base.rs_async-fn.snap
Original file line number Diff line number Diff line change
@@ -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: "^ "

0 comments on commit 156f34c

Please sign in to comment.