Skip to content

Commit

Permalink
feat(c#): Scope identifier names
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Aug 11, 2024
1 parent 5b530a1 commit 0267196
Show file tree
Hide file tree
Showing 4 changed files with 946 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,7 @@ Language scopes:
- destructor: Destructor definitions (in their entirety)
- field: Field definitions on types (in their entirety)
- attribute: Attribute names
- identifier: Identifier names

--csharp-query <TREE-SITTER-QUERY>
Scope C# code using a custom tree-sitter query.
Expand Down
3 changes: 3 additions & 0 deletions src/scoping/langs/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pub enum PreparedCSharpQuery {
Field,
/// Attribute names.
Attribute,
/// Identifier names.
Identifier,
}

impl From<PreparedCSharpQuery> for TSQuery {
Expand Down Expand Up @@ -80,6 +82,7 @@ impl From<PreparedCSharpQuery> for TSQuery {
PreparedCSharpQuery::Destructor => "(destructor_declaration) @destructor",
PreparedCSharpQuery::Field => "(field_declaration) @field",
PreparedCSharpQuery::Attribute => "(attribute) @attribute",
PreparedCSharpQuery::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 @@ -362,6 +362,11 @@ impl InScopeLinePart {
include_str!("csharp/base.cs"),
CSharp::new(CodeQuery::Prepared(PreparedCSharpQuery::Method)),
)]
#[case(
"base.cs_identifier",
include_str!("csharp/base.cs"),
CSharp::new(CodeQuery::Prepared(PreparedCSharpQuery::Identifier)),
)]
fn test_language_scopers(
#[case] snapshot_name: &str,
#[case] contents: &str,
Expand Down
Loading

0 comments on commit 0267196

Please sign in to comment.