diff --git a/README.md b/README.md index 715952b0..e5072a8d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/scoping/langs/csharp.rs b/src/scoping/langs/csharp.rs index 8a017570..b3ad8cd3 100644 --- a/src/scoping/langs/csharp.rs +++ b/src/scoping/langs/csharp.rs @@ -22,6 +22,8 @@ pub enum PreparedCSharpQuery { Strings, /// `using` directives (including periods). Usings, + /// `struct` definitions (in their entirety). + Struct, } impl From<PreparedCSharpQuery> for TSQuery { @@ -47,6 +49,7 @@ impl From<PreparedCSharpQuery> for TSQuery { IGNORE ) } + PreparedCSharpQuery::Struct => "(struct_declaration) @struct", }, ) .expect("Prepared queries to be valid") diff --git a/tests/langs/mod.rs b/tests/langs/mod.rs index 08f1bf40..a25a6078 100644 --- a/tests/langs/mod.rs +++ b/tests/langs/mod.rs @@ -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, diff --git a/tests/langs/snapshots/r#mod__langs__base.cs_struct.snap b/tests/langs/snapshots/r#mod__langs__base.cs_struct.snap new file mode 100644 index 00000000..30687577 --- /dev/null +++ b/tests/langs/snapshots/r#mod__langs__base.cs_struct.snap @@ -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: "^^^^^ "