Skip to content

Commit

Permalink
feat(c#): Scope field definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Aug 11, 2024
1 parent 31dc2cb commit 3f2d919
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ Language scopes:
- usings: `using` directives (including periods)
- struct: `struct` definitions (in their entirety)
- enum: `enum` definitions (in their entirety)
- field: Field definitions on types (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 @@ -26,6 +26,8 @@ pub enum PreparedCSharpQuery {
Struct,
/// `enum` definitions (in their entirety).
Enum,
/// Field definitions on types (in their entirety).
Field,
}

impl From<PreparedCSharpQuery> for TSQuery {
Expand Down Expand Up @@ -53,6 +55,7 @@ impl From<PreparedCSharpQuery> for TSQuery {
}
PreparedCSharpQuery::Struct => "(struct_declaration) @struct",
PreparedCSharpQuery::Enum => "(enum_declaration) @enum",
PreparedCSharpQuery::Field => "(field_declaration) @field",
},
)
.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 @@ -317,6 +317,11 @@ impl InScopeLinePart {
include_str!("csharp/base.cs"),
CSharp::new(CodeQuery::Prepared(PreparedCSharpQuery::Enum)),
)]
#[case(
"base.cs_field",
include_str!("csharp/base.cs"),
CSharp::new(CodeQuery::Prepared(PreparedCSharpQuery::Field)),
)]
fn test_language_scopers(
#[case] snapshot_name: &str,
#[case] contents: &str,
Expand Down
31 changes: 31 additions & 0 deletions tests/langs/snapshots/r#mod__langs__base.cs_field.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
source: tests/langs/mod.rs
expression: inscope_parts
---
- n: 13
l: " public T Value;\n"
m: " ^^^^^^^^^^^^^^^ "
- n: 14
l: " public fixed byte ErrorCode[16];\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 35
l: " protected internal const double Epsilon = 1e-6;\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 36
l: " public static readonly DateTime TestStartTime = DateTime.Now;\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 38
l: " private TestStatus _status;\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 60
l: " private readonly Func<double, double> _functionUnderTest;\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 61
l: " private readonly int _iterations;\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 113
l: " private readonly List<TestBase> _tests = new List<TestBase>();\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 114
l: " private TestLogger _logger;\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^ "

0 comments on commit 3f2d919

Please sign in to comment.