Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix json! empty-string highlighting in Rust (#55126)

saberoueslatif4f527073d2a
diff --git a/crates/grammars/src/rust/injections.scm b/crates/grammars/src/rust/injections.scm
index 89d839282d3..4d6b67b9f81 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 8bff7ce1415..98804037e31 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(