Add a live Rust style editor to inspector to edit a sequence of no-argument style modifiers (#31443)

Editing JSON styles is not very helpful for bringing style changes back
to the actual code. This PR adds a buffer that pretends to be Rust,
applying any style attribute identifiers it finds. Also supports
completions with display of documentation. The effect of the currently
selected completion is previewed. Warning diagnostics appear on any
unrecognized identifier.


https://github.com/user-attachments/assets/af39ff0a-26a5-4835-a052-d8f642b2080c

Adds a `#[derive_inspector_reflection]` macro which allows these methods
to be enumerated and called by their name. The macro code changes were
95% generated by Zed Agent + Opus 4.

Release Notes:

* Added an element inspector for development. On debug builds,
`dev::ToggleInspector` will open a pane allowing inspecting of element
info and modifying styles.
This commit is contained in:
Michael Sloan 2025-05-26 11:43:57 -06:00 committed by GitHub
parent 6253b95f82
commit 649072d140
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 1778 additions and 316 deletions

View file

@ -1213,6 +1213,28 @@ pub fn word_consists_of_emojis(s: &str) -> bool {
prev_end == s.len()
}
/// Similar to `str::split`, but also provides byte-offset ranges of the results. Unlike
/// `str::split`, this is not generic on pattern types and does not return an `Iterator`.
pub fn split_str_with_ranges(s: &str, pat: impl Fn(char) -> bool) -> Vec<(Range<usize>, &str)> {
let mut result = Vec::new();
let mut start = 0;
for (i, ch) in s.char_indices() {
if pat(ch) {
if i > start {
result.push((start..i, &s[start..i]));
}
start = i + ch.len_utf8();
}
}
if s.len() > start {
result.push((start..s.len(), &s[start..s.len()]));
}
result
}
pub fn default<D: Default>() -> D {
Default::default()
}
@ -1639,4 +1661,20 @@ Line 3"#
"这是什\n么 钢\n"
);
}
#[test]
fn test_split_with_ranges() {
let input = "hi";
let result = split_str_with_ranges(input, |c| c == ' ');
assert_eq!(result.len(), 1);
assert_eq!(result[0], (0..2, "hi"));
let input = "héllo🦀world";
let result = split_str_with_ranges(input, |c| c == '🦀');
assert_eq!(result.len(), 2);
assert_eq!(result[0], (0..6, "héllo")); // 'é' is 2 bytes
assert_eq!(result[1], (10..15, "world")); // '🦀' is 4 bytes
}
}