diff --git a/Cargo.lock b/Cargo.lock index cec047f65a8..543cdc33fee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19147,6 +19147,7 @@ dependencies = [ "gpui_util", "icons", "itertools 0.14.0", + "log", "menu", "schemars 1.0.4", "serde", diff --git a/crates/ui/Cargo.toml b/crates/ui/Cargo.toml index 4ae0e6d2e46..8cd99a50783 100644 --- a/crates/ui/Cargo.toml +++ b/crates/ui/Cargo.toml @@ -20,6 +20,7 @@ gpui.workspace = true gpui_macros.workspace = true icons.workspace = true itertools.workspace = true +log.workspace = true menu.workspace = true schemars.workspace = true serde.workspace = true @@ -35,5 +36,8 @@ windows.workspace = true [dev-dependencies] gpui = { workspace = true, features = ["test-support"] } +[package.metadata.cargo-machete] +ignored = ["log"] + [features] default = [] diff --git a/crates/ui/src/components/label/highlighted_label.rs b/crates/ui/src/components/label/highlighted_label.rs index 73e03f82dfd..6d5b1d5645a 100644 --- a/crates/ui/src/components/label/highlighted_label.rs +++ b/crates/ui/src/components/label/highlighted_label.rs @@ -1,6 +1,7 @@ use std::ops::Range; use gpui::{FontWeight, HighlightStyle, StyleRefinement, StyledText}; +use gpui_util::debug_panic; use crate::{LabelCommon, LabelLike, LabelSize, LineHeightStyle, prelude::*}; @@ -14,14 +15,21 @@ pub struct HighlightedLabel { impl HighlightedLabel { /// Constructs a label with the given characters highlighted. /// Characters are identified by UTF-8 byte position. - pub fn new(label: impl Into, highlight_indices: Vec) -> Self { + #[track_caller] + pub fn new(label: impl Into, mut highlight_indices: Vec) -> Self { let label = label.into(); - for &run in &highlight_indices { - assert!( - label.is_char_boundary(run), - "highlight index {run} is not a valid UTF-8 boundary" + + if let Some(index) = highlight_indices + .iter() + .find(|&i| !label.is_char_boundary(*i)) + { + let location = std::panic::Location::caller(); + debug_panic!( + "highlight index {index} is not a valid UTF-8 boundary (called from {location})" ); + highlight_indices.clear(); } + Self { base: LabelLike::new(), label,