diff --git a/crates/grammars/src/rust/injections.scm b/crates/grammars/src/rust/injections.scm index 89d839282d3388..4d6b67b9f8198d 100644 --- a/crates/grammars/src/rust/injections.scm +++ b/crates/grammars/src/rust/injections.scm @@ -10,7 +10,7 @@ (scoped_identifier (identifier) @_macro_name .) ] - (#not-any-of? @_macro_name "view" "html") + (#not-any-of? @_macro_name "view" "html" "json") (token_tree) @injection.content (#set! injection.language "rust")) diff --git a/crates/language/src/syntax_map/syntax_map_tests.rs b/crates/language/src/syntax_map/syntax_map_tests.rs index 247076b6f25e3c..3ca2fa83c37ec1 100644 --- a/crates/language/src/syntax_map/syntax_map_tests.rs +++ b/crates/language/src/syntax_map/syntax_map_tests.rs @@ -349,6 +349,56 @@ fn test_dynamic_language_injection(cx: &mut App) { assert!(!syntax_map.contains_unknown_injections()); } +#[gpui::test] +fn test_rust_json_macro_empty_string_highlighting(cx: &mut App) { + let registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone())); + let language = rust_lang(); + registry.add(language.clone()); + + let buffer = Buffer::new( + ReplicaId::LOCAL, + BufferId::new(1).unwrap(), + r#" + serde_json::json!({ + "email": "", + "password": "password123", + "requires2FA": false + }) + "# + .unindent(), + ); + + let mut syntax_map = SyntaxMap::new(&buffer); + syntax_map.set_language_registry(registry); + syntax_map.reparse(language, &buffer); + + assert_capture_ranges( + &syntax_map, + &buffer, + &["string"], + r#" + serde_json::json!({ + «"email"»: «""», + «"password"»: «"password123"», + «"requires2FA"»: false + }) + "#, + ); + + assert_capture_ranges( + &syntax_map, + &buffer, + &["boolean"], + r#" + serde_json::json!({ + "email": "", + "password": "password123", + "requires2FA": «false» + }) + "#, + ); +} + #[gpui::test] fn test_typing_multiple_new_injections(cx: &mut App) { let (buffer, syntax_map) = test_edit_sequence(