Skip to content

Commit

Permalink
feat(rust): Scope function definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Aug 15, 2024
1 parent fc0a9db commit c2dd0c3
Show file tree
Hide file tree
Showing 4 changed files with 515 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1474,8 +1474,9 @@ Language scopes:
- strings: Strings (regular, raw, byte; includes interpolation parts in
format strings!)
- attribute: Attributes like `#[attr]`
- mod: Anything in `mod` blocks
- mod-tests: Anything in `mod tests` blocks
- fn: Function definitions
- mod: `mod` blocks
- mod-tests: `mod tests` blocks

--rust-query <TREE-SITTER-QUERY>
Scope Rust code using a custom tree-sitter query.
Expand Down
7 changes: 5 additions & 2 deletions src/scoping/langs/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ pub enum PreparedRustQuery {
Strings,
/// Attributes like `#[attr]`.
Attribute,
/// Anything in `mod` blocks.
/// Function definitions.
Fn,
/// `mod` blocks.
Mod,
/// Anything in `mod tests` blocks.
/// `mod tests` blocks.
ModTests,
}

Expand Down Expand Up @@ -72,6 +74,7 @@ impl From<PreparedRustQuery> for TSQuery {
}
PreparedRustQuery::Strings => "(string_content) @string",
PreparedRustQuery::Attribute => "(attribute) @attribute",
PreparedRustQuery::Fn => "(function_item) @function_item",
PreparedRustQuery::Mod => "(mod_item) @mod_item",
PreparedRustQuery::ModTests => {
r#"(mod_item
Expand Down
5 changes: 5 additions & 0 deletions tests/langs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ impl InScopeLinePart {
include_str!("rust/base.rs"),
Rust::new(CodeQuery::Prepared(PreparedRustQuery::Attribute)),
)]
#[case(
"base.rs_fn",
include_str!("rust/base.rs"),
Rust::new(CodeQuery::Prepared(PreparedRustQuery::Fn)),
)]
#[case(
"base.rs_mod",
include_str!("rust/base.rs"),
Expand Down
Loading

0 comments on commit c2dd0c3

Please sign in to comment.