Skip to content

Commit

Permalink
feat: Scope using namespace names (C#)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Dec 18, 2023
1 parent b211204 commit 200d482
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/scoping/langs/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub enum PremadeCSharpQuery {
/// Raw strings are not yet supported
/// (https://github.com/tree-sitter/tree-sitter-c-sharp/pull/240 not released yet).
Strings,
/// `using` directives (including periods).
Usings,
}

impl From<PremadeCSharpQuery> for TSQuery {
Expand All @@ -27,6 +29,9 @@ impl From<PremadeCSharpQuery> for TSQuery {
CSharp::lang(),
match value {
PremadeCSharpQuery::Comments => "(comment) @comment",
PremadeCSharpQuery::Usings => {
r"(using_directive [(identifier) (qualified_name)] @import)"
}
PremadeCSharpQuery::Strings => {
r#"
[
Expand Down
5 changes: 5 additions & 0 deletions tests/langs/csharp/in/usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Sys__T__tem;
using System__T__.IO;
using Project = __T__PC.MyCompany.Project;
using static System.__T__Math;
using Project = MyCompany.ProjectNames__T__pace.ProjectClass;
1 change: 1 addition & 0 deletions tests/langs/csharp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::{get_input_output, nuke_target};
#[rstest]
#[case("comments.cs", CSharpQuery::Premade(PremadeCSharpQuery::Comments))]
#[case("strings.cs", CSharpQuery::Premade(PremadeCSharpQuery::Strings))]
#[case("usings.cs", CSharpQuery::Premade(PremadeCSharpQuery::Usings))]
fn test_csharp_nuke(#[case] file: &str, #[case] query: CSharpQuery) {
let lang = CSharp::new(query);

Expand Down
5 changes: 5 additions & 0 deletions tests/langs/csharp/out/usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System;
using System.IO;
using Project = PC.MyCompany.Project;
using static System.Math;
using Project = MyCompany.ProjectNamespace.ProjectClass;

0 comments on commit 200d482

Please sign in to comment.