Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
grammars: Highlight class instantiations in JavaScript, TypeScript, and TSX (#61890)
Ibrahim Khanb6b2148bd0e2
diff --git a/crates/grammars/src/javascript/highlights.scm b/crates/grammars/src/javascript/highlights.scmindex 336fcdd36a5..5835e710615 100644--- a/crates/grammars/src/javascript/highlights.scm+++ b/crates/grammars/src/javascript/highlights.scm@@ -30,7 +30,7 @@] @function.method))(new_expression- constructor: (identifier) @type)+ constructor: (identifier) @type.class)(nested_type_identifiermodule: (identifier) @type)diff --git a/crates/grammars/src/tsx/highlights.scm b/crates/grammars/src/tsx/highlights.scmindex 3dd9038782d..899737b6a6d 100644--- a/crates/grammars/src/tsx/highlights.scm+++ b/crates/grammars/src/tsx/highlights.scm@@ -30,7 +30,7 @@] @function.method))(new_expression- constructor: (identifier) @type)+ constructor: (identifier) @type.class)(nested_type_identifiermodule: (identifier) @type)diff --git a/crates/grammars/src/typescript/highlights.scm b/crates/grammars/src/typescript/highlights.scmindex c3ecf179465..58e26794487 100644--- a/crates/grammars/src/typescript/highlights.scm+++ b/crates/grammars/src/typescript/highlights.scm@@ -123,7 +123,7 @@] @function.method))(new_expression- constructor: (identifier) @type)+ constructor: (identifier) @type.class)(nested_type_identifiermodule: (identifier) @type)diff --git a/crates/languages/src/typescript.rs b/crates/languages/src/typescript.rsindex 0da1b63590e..806fa372d46 100644--- a/crates/languages/src/typescript.rs+++ b/crates/languages/src/typescript.rs@@ -908,10 +908,12 @@ async fn get_cached_ts_server_binary(mod tests {use std::path::Path;- use gpui::{AppContext as _, BackgroundExecutor, TestAppContext};+ use gpui::{AppContext as _, BackgroundExecutor, Hsla, TestAppContext};use project::FakeFs;+ use rope::Rope;use serde_json::json;use task::TaskTemplates;+ use theme::SyntaxTheme;use unindent::Unindent;use util::{path, rel_path::rel_path};@@ -919,6 +921,34 @@ mod tests {PackageJsonData, TypeScriptContextProvider, replace_test_name_parameters,};+ #[test]+ fn test_class_instantiation_highlighting() {+ let source = Rope::from("class Dog {}\nconst dog = new Dog();");+ let theme = SyntaxTheme::new_test([("type", Hsla::blue()), ("type.class", Hsla::green())]);++ for language in [+ crate::language(+ "typescript",+ tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into(),+ ),+ crate::language("tsx", tree_sitter_typescript::LANGUAGE_TSX.into()),+ crate::language("javascript", tree_sitter_typescript::LANGUAGE_TSX.into()),+ ] {+ language.set_theme(&theme);+ let class_highlight = language+ .grammar()+ .and_then(|grammar| grammar.highlight_id_for_name("type.class"))+ .expect("type.class highlight should be defined");++ assert_eq!(+ language.highlight_text(&source, 0..source.len()),+ vec![(6..9, class_highlight), (29..32, class_highlight)],+ "{} class instantiations should use the type.class highlight",+ language.name()+ );+ }+ }+#[gpui::test]async fn test_outline(cx: &mut TestAppContext) {for language in [