Skip to content

Commit

Permalink
feat(c#): Scope attribute names
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Aug 11, 2024
1 parent 3f2d919 commit c3fe051
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1359,13 +1359,14 @@ Language scopes:
[env: CSHARP=]

Possible values:
- comments: Comments (including XML, inline, doc comments)
- strings: Strings (incl. verbatim, interpolated; incl. quotes, except for
- comments: Comments (including XML, inline, doc comments)
- strings: Strings (incl. verbatim, interpolated; incl. quotes, except for
interpolated)
- 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)
- 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)
- attribute: Attribute 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 @@ -28,6 +28,8 @@ pub enum PreparedCSharpQuery {
Enum,
/// Field definitions on types (in their entirety).
Field,
/// Attribute names.
Attribute,
}

impl From<PreparedCSharpQuery> for TSQuery {
Expand Down Expand Up @@ -56,6 +58,7 @@ impl From<PreparedCSharpQuery> for TSQuery {
PreparedCSharpQuery::Struct => "(struct_declaration) @struct",
PreparedCSharpQuery::Enum => "(enum_declaration) @enum",
PreparedCSharpQuery::Field => "(field_declaration) @field",
PreparedCSharpQuery::Attribute => "(attribute) @attribute",
},
)
.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 @@ -322,6 +322,11 @@ impl InScopeLinePart {
include_str!("csharp/base.cs"),
CSharp::new(CodeQuery::Prepared(PreparedCSharpQuery::Field)),
)]
#[case(
"base.cs_attribute",
include_str!("csharp/base.cs"),
CSharp::new(CodeQuery::Prepared(PreparedCSharpQuery::Attribute)),
)]
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_attribute.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
source: tests/langs/mod.rs
expression: inscope_parts
---
- n: 7
l: "[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(\"TestAssembly\")]\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 17
l: " [Flags]\n"
m: " ^^^^^ "
- n: 32
l: " [Serializable]\n"
m: " ^^^^^^^^^^^^ "
- n: 144
l: " [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]\n"
m: " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
- n: 207
l: " [Benchmark(100)]\n"
m: " ^^^^^^^^^^^^^^ "

0 comments on commit c3fe051

Please sign in to comment.