diff --git a/Cargo.lock b/Cargo.lock index 88db657..7f01149 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -782,6 +782,17 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae62f7eae5eb549c71b76658648b72cc6111f2d87d24a1e31fa907f4943e3ce" +[[package]] +name = "tree-sitter-rbs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "737ba7f61f95da9cbf3af40ef4167cc500fd2b2f9be7030d67e7ec43a84ae079" +dependencies = [ + "cc", + "tree-sitter", + "tree-sitter-language", +] + [[package]] name = "tree-sitter-ruby" version = "0.23.1" @@ -1056,6 +1067,7 @@ dependencies = [ "serde_json", "tree-sitter", "tree-sitter-embedded-template", + "tree-sitter-rbs", "tree-sitter-ruby", "zed_extension_api", ] diff --git a/Cargo.toml b/Cargo.toml index 2a59901..93d9bc3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,4 +20,5 @@ anyhow = "1.0.89" tree-sitter = "0.26" tree-sitter-ruby = "0.23.1" tree-sitter-embedded-template = "0.25.0" +tree-sitter-rbs = "0.2.3" insta = { version = "1.46", features = ["yaml"] } diff --git a/languages/rbs/highlights.scm b/languages/rbs/highlights.scm index 5789d65..5757ae6 100644 --- a/languages/rbs/highlights.scm +++ b/languages/rbs/highlights.scm @@ -98,7 +98,7 @@ (type_variable) @constant (namespace - (constant) @module) + (constant) @type) (builtin_type) @type.builtin diff --git a/languages/rbs/indents.scm b/languages/rbs/indents.scm index 8d53ab1..130fac3 100644 --- a/languages/rbs/indents.scm +++ b/languages/rbs/indents.scm @@ -5,7 +5,7 @@ (parameters) (tuple_type) (record_type) -] @indent.begin +] @indent (_ "[" @@ -18,5 +18,3 @@ (_ "(" ")" @end) @indent - -(comment) @indent.ignore diff --git a/tests/rbs.rs b/tests/rbs.rs new file mode 100644 index 0000000..6bc0cb3 --- /dev/null +++ b/tests/rbs.rs @@ -0,0 +1,18 @@ +mod support; + +#[test] +fn parses_and_highlights_rbs() { + let source = "module Billing\n class Invoice\n def total: (Integer quantity) -> Numeric\n end\nend\n"; + let query = std::fs::read_to_string("languages/rbs/highlights.scm").unwrap(); + let captures = support::run_query(source, &query, "rbs"); + + assert!(captures + .iter() + .any(|capture| capture.name == "type" && capture.text == "Billing")); + assert!(captures + .iter() + .any(|capture| capture.name == "function.method" && capture.text == "total")); + assert!(captures + .iter() + .any(|capture| capture.name == "variable.parameter" && capture.text == "quantity")); +} diff --git a/tests/support/mod.rs b/tests/support/mod.rs index 3dbfaf0..6e8eb1c 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -19,6 +19,7 @@ fn language_for_id(language_id: &str) -> tree_sitter::Language { match language_id { "ruby" => tree_sitter_ruby::LANGUAGE.into(), "erb" => tree_sitter_embedded_template::LANGUAGE.into(), + "rbs" => tree_sitter_rbs::LANGUAGE.into(), _ => panic!("Unsupported language id for query tests: {language_id}"), } }