Skip to content

Commit

Permalink
feat(c#): Scope constructor definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Aug 11, 2024
1 parent 769ffef commit d8b5e7a
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 @@ -1369,6 +1369,7 @@ Language scopes:
- class: `class` definitions (in their entirety)
- variable-declaration: Variable declarations (in their entirety)
- property: Property definitions (in their entirety)
- constructor: Constructor definitions (in their entirety)
- field: Field definitions on types (in their entirety)
- attribute: Attribute names

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 @@ -34,6 +34,8 @@ pub enum PreparedCSharpQuery {
VariableDeclaration,
/// Property definitions (in their entirety).
Property,
/// Constructor definitions (in their entirety).
Constructor,
/// Field definitions on types (in their entirety).
Field,
/// Attribute names.
Expand Down Expand Up @@ -69,6 +71,7 @@ impl From<PreparedCSharpQuery> for TSQuery {
PreparedCSharpQuery::Class => "(class_declaration) @class",
PreparedCSharpQuery::VariableDeclaration => "(variable_declaration) @variable",
PreparedCSharpQuery::Property => "(property_declaration) @property",
PreparedCSharpQuery::Constructor => "(constructor_declaration) @constructor",
PreparedCSharpQuery::Field => "(field_declaration) @field",
PreparedCSharpQuery::Attribute => "(attribute) @attribute",
},
Expand Down
5 changes: 5 additions & 0 deletions tests/langs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ impl InScopeLinePart {
include_str!("csharp/base.cs"),
CSharp::new(CodeQuery::Prepared(PreparedCSharpQuery::Property)),
)]
#[case(
"base.cs_constructor",
include_str!("csharp/base.cs"),
CSharp::new(CodeQuery::Prepared(PreparedCSharpQuery::Constructor)),
)]
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_constructor.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
source: tests/langs/mod.rs
expression: inscope_parts
---
- n: 41
l: " protected TestBase() => _status = TestStatus.None;\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 63
l: " public PerformanceTest(Func<double, double> func, int iterations)\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
- n: 64
l: " {\n"
m: ^^^^^^^^^^^
- n: 65
l: " _functionUnderTest = func ?? throw new ArgumentNullException(nameof(func));\n"
m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- n: 66
l: " _iterations = iterations > 0 ? iterations : throw new ArgumentOutOfRangeException(nameof(iterations));\n"
m: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- n: 67
l: " }\n"
m: "^^^^^^^^^ "
- n: 118
l: " public TestRunner(TestLogger logger = null) => _logger = logger ?? Console.WriteLine;\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 141
l: " public TestException(string message) : base(message) { }\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 148
l: " public BenchmarkAttribute(int iterations) => Iterations = iterations;\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "

0 comments on commit d8b5e7a

Please sign in to comment.