Skip to content

Commit

Permalink
feat(c#): Scope struct definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Aug 11, 2024
1 parent 7aa8eb0 commit 5b53286
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,7 @@ Language scopes:
- strings: Strings (incl. verbatim, interpolated; incl. quotes, except for
interpolated)
- usings: `using` directives (including periods)
- struct: `struct` definitions (in their entirety)

--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 @@ -22,6 +22,8 @@ pub enum PreparedCSharpQuery {
Strings,
/// `using` directives (including periods).
Usings,
/// `struct` definitions (in their entirety).
Struct,
}

impl From<PreparedCSharpQuery> for TSQuery {
Expand All @@ -47,6 +49,7 @@ impl From<PreparedCSharpQuery> for TSQuery {
IGNORE
)
}
PreparedCSharpQuery::Struct => "(struct_declaration) @struct",
},
)
.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 @@ -307,6 +307,11 @@ impl InScopeLinePart {
include_str!("csharp/base.cs"),
CSharp::new(CodeQuery::Prepared(PreparedCSharpQuery::Comments)),
)]
#[case(
"base.cs_struct",
include_str!("csharp/base.cs"),
CSharp::new(CodeQuery::Prepared(PreparedCSharpQuery::Struct)),
)]
fn test_language_scopers(
#[case] snapshot_name: &str,
#[case] contents: &str,
Expand Down
19 changes: 19 additions & 0 deletions tests/langs/snapshots/r#mod__langs__base.cs_struct.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
source: tests/langs/mod.rs
expression: inscope_parts
---
- n: 11
l: " public unsafe struct TestResult<T> where T : struct\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
- n: 12
l: " {\n"
m: ^^^^^^^
- n: 13
l: " public T Value;\n"
m: ^^^^^^^^^^^^^^^^^^^^^^^^^
- n: 14
l: " public fixed byte ErrorCode[16];\n"
m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- n: 15
l: " }\n"
m: "^^^^^ "

0 comments on commit 5b53286

Please sign in to comment.