feat: Support Dart again (#2534)

This commit is contained in:
Kasper Overgård Nielsen
2026-04-04 17:48:21 +02:00
committed by GitHub
parent dabd337ebd
commit ee226af4b1
7 changed files with 1352 additions and 3 deletions
Generated
+11
View File
@@ -189,6 +189,7 @@ dependencies = [
"tree-sitter-c-sharp",
"tree-sitter-cpp",
"tree-sitter-css",
"tree-sitter-dart",
"tree-sitter-elixir",
"tree-sitter-go",
"tree-sitter-haskell",
@@ -2117,6 +2118,16 @@ dependencies = [
"tree-sitter-language",
]
[[package]]
name = "tree-sitter-dart"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bba6bf8675e6fe92ba6da371a5497ee5df2a04d2c503e3599c8ad771f6f1faec"
dependencies = [
"cc",
"tree-sitter-language",
]
[[package]]
name = "tree-sitter-elixir"
version = "0.3.5"
+2
View File
@@ -21,6 +21,7 @@ tree-sitter-bash = { version = "0.25.0", optional = true }
tree-sitter-cpp = { version = "0.23.0", optional = true }
tree-sitter-c-sharp = { version = "0.23.0", optional = true }
tree-sitter-css = { version = "0.25.0", optional = true }
tree-sitter-dart = { version = "0.1.0", optional = true }
tree-sitter-c = { version = "0.24.0", optional = true }
tree-sitter-elixir = { version = "0.3.0", optional = true }
tree-sitter-go = { version = "0.25.0", optional = true }
@@ -50,6 +51,7 @@ builtin-parser = [
"tree-sitter-cpp",
"tree-sitter-c-sharp",
"tree-sitter-css",
"tree-sitter-dart",
"tree-sitter-elixir",
"tree-sitter-go",
"tree-sitter-haskell",
+34
View File
@@ -0,0 +1,34 @@
#![cfg(test)]
use super::*;
fn test_match(query: &str, source: &str) {
use crate::test::test_match_lang;
test_match_lang(query, source, Dart);
}
fn test_non_match(query: &str, source: &str) {
use crate::test::test_non_match_lang;
test_non_match_lang(query, source, Dart);
}
#[test]
fn test_dart_class() {
test_match("class $A {}", "class Foo {}");
test_non_match("class $A {}", "class Foo { int x = 1; }");
}
#[test]
fn test_dart_class_with_body() {
test_match("class $A { $$$BODY }", "class Foo { int x = 1; }");
}
fn test_replace(src: &str, pattern: &str, replacer: &str) -> String {
use crate::test::test_replace_lang;
test_replace_lang(src, pattern, replacer, Dart)
}
#[test]
fn test_dart_replace() {
let ret = test_replace("class Foo {}", "class $A {}", "class $A extends Base {}");
assert_eq!(ret, "class Foo extends Base {}");
}
+7 -1
View File
@@ -22,6 +22,7 @@ mod bash;
mod cpp;
mod csharp;
mod css;
mod dart;
mod elixir;
mod go;
mod haskell;
@@ -247,6 +248,7 @@ impl_lang!(Scala, language_scala);
impl_lang!(Solidity, language_solidity);
impl_lang!(Tsx, language_tsx);
impl_lang!(TypeScript, language_typescript);
impl_lang!(Dart, language_dart);
impl_lang!(Yaml, language_yaml);
// See ripgrep for extensions
// https://github.com/BurntSushi/ripgrep/blob/master/crates/ignore/src/default_types.rs
@@ -259,6 +261,7 @@ pub enum SupportLang {
Cpp,
CSharp,
Css,
Dart,
Go,
Elixir,
Haskell,
@@ -286,7 +289,7 @@ impl SupportLang {
pub const fn all_langs() -> &'static [SupportLang] {
use SupportLang::*;
&[
Bash, C, Cpp, CSharp, Css, Elixir, Go, Haskell, Hcl, Html, Java, JavaScript, Json, Kotlin,
Bash, C, Cpp, CSharp, Css, Dart, Elixir, Go, Haskell, Hcl, Html, Java, JavaScript, Json, Kotlin,
Lua, Nix, Php, Python, Ruby, Rust, Scala, Solidity, Swift, Tsx, TypeScript, Yaml,
]
}
@@ -373,6 +376,7 @@ impl_aliases! {
Cpp => &["cc", "c++", "cpp", "cxx"],
CSharp => &["cs", "csharp"],
Css => &["css"],
Dart => &["dart"],
Elixir => &["ex", "elixir"],
Go => &["go", "golang"],
Haskell => &["hs", "haskell"],
@@ -420,6 +424,7 @@ macro_rules! execute_lang_method {
S::Cpp => Cpp.$method($($pname,)*),
S::CSharp => CSharp.$method($($pname,)*),
S::Css => Css.$method($($pname,)*),
S::Dart => Dart.$method($($pname,)*),
S::Elixir => Elixir.$method($($pname,)*),
S::Go => Go.$method($($pname,)*),
S::Haskell => Haskell.$method($($pname,)*),
@@ -492,6 +497,7 @@ fn extensions(lang: SupportLang) -> &'static [&'static str] {
Cpp => &["cc", "hpp", "cpp", "c++", "hh", "cxx", "cu", "ino"],
CSharp => &["cs"],
Css => &["css", "scss"],
Dart => &["dart"],
Elixir => &["ex", "exs"],
Go => &["go"],
Haskell => &["hs"],
+3
View File
@@ -34,6 +34,9 @@ pub fn language_cpp() -> TSLanguage {
pub fn language_c_sharp() -> TSLanguage {
conditional_lang!(tree_sitter_c_sharp, "tree-sitter-c-sharp")
}
pub fn language_dart() -> TSLanguage {
conditional_lang!(tree_sitter_dart, "tree-sitter-dart")
}
pub fn language_css() -> TSLanguage {
conditional_lang!(tree_sitter_css, "tree-sitter-css")
}
File diff suppressed because it is too large Load Diff
+3 -2
View File
@@ -4,8 +4,8 @@ use ast_grep_core::matcher::{Pattern, PatternBuilder, PatternError};
use ast_grep_core::tree_sitter::{LanguageExt, TSLanguage};
use ast_grep_core::Language;
use ast_grep_language::{
Alias, Bash, CSharp, Cpp, Css, Elixir, Go, Haskell, Html, Java, JavaScript, Json, Kotlin, Lua,
Php, Python, Ruby, Rust, Scala, Swift, Tsx, TypeScript, Yaml, C,
Alias, Bash, CSharp, Cpp, Css, Dart, Elixir, Go, Haskell, Html, Java, JavaScript, Json, Kotlin,
Lua, Php, Python, Ruby, Rust, Scala, Swift, Tsx, TypeScript, Yaml, C,
};
use schemars::{json_schema, schema_for, JsonSchema, Schema, SchemaGenerator};
use serde_json::{to_writer_pretty, Value};
@@ -30,6 +30,7 @@ fn generate_lang_schemas() -> Result<()> {
generate_lang_schema(Cpp, "cpp")?;
generate_lang_schema(CSharp, "csharp")?;
generate_lang_schema(Css, "css")?;
generate_lang_schema(Dart, "dart")?;
generate_lang_schema(Go, "go")?;
generate_lang_schema(Elixir, "elixir")?;
generate_lang_schema(Haskell, "haskell")?;