Skip to content

Commit

Permalink
feat(rust): Scope identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Aug 16, 2024
1 parent d51290c commit 007f0be
Show file tree
Hide file tree
Showing 4 changed files with 688 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,7 @@ Language scopes:
- mod: `mod` blocks
- mod-tests: `mod tests` blocks
- type-def: Type definitions (`struct`, `enum`, `union`)
- identifier: Identifiers

--rust-query <TREE-SITTER-QUERY>
Scope Rust code using a custom tree-sitter query.
Expand Down
3 changes: 3 additions & 0 deletions src/scoping/langs/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ pub enum PreparedRustQuery {
ModTests,
/// Type definitions (`struct`, `enum`, `union`).
TypeDef,
/// Identifiers.
Identifier,
}

impl From<PreparedRustQuery> for TSQuery {
Expand Down Expand Up @@ -293,6 +295,7 @@ impl From<PreparedRustQuery> for TSQuery {
@typedef
"
}
PreparedRustQuery::Identifier => "(identifier) @identifier",
},
)
.expect("Prepared queries to be valid")
Expand Down
5 changes: 5 additions & 0 deletions tests/langs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ impl InScopeLinePart {
include_str!("rust/base.rs"),
Rust::new(CodeQuery::Prepared(PreparedRustQuery::TypeDef)),
)]
#[case(
"base.rs_identifier",
include_str!("rust/base.rs"),
Rust::new(CodeQuery::Prepared(PreparedRustQuery::Identifier)),
)]
#[case(
"base.tf_variable-block",
include_str!("hcl/base.tf"),
Expand Down
Loading

0 comments on commit 007f0be

Please sign in to comment.