Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/grammars/src/rust/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down
50 changes: 50 additions & 0 deletions crates/language/src/syntax_map/syntax_map_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading