From 3c6a7b6a9b34e6a0d87dc6fb631d7276615ce3ed Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Oct 2025 10:34:13 +0800 Subject: [PATCH] highlighter: Make SyntaxHighlighter::styles method public for external use (#1415) --- crates/ui/src/highlighter/highlighter.rs | 26 +++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/crates/ui/src/highlighter/highlighter.rs b/crates/ui/src/highlighter/highlighter.rs index 75a278ee..1df549cf 100644 --- a/crates/ui/src/highlighter/highlighter.rs +++ b/crates/ui/src/highlighter/highlighter.rs @@ -565,10 +565,30 @@ impl SyntaxHighlighter { (language_name, content_node, include_children) } - /// The argument `range` is the range of the line in the text. + /// Returns the syntax highlight styles for a range of text. /// - /// Returns `range` is the range in the line. - pub(crate) fn styles( + /// The argument `range` is the range of bytes in the text to highlight. + /// + /// Returns a vector of tuples where each tuple contains: + /// - A byte range relative to the text + /// - The corresponding highlight style for that range + /// + /// # Example + /// + /// ```no_run + /// use gpui_component::highlighter::{HighlightTheme, SyntaxHighlighter}; + /// use ropey::Rope; + /// + /// let code = "fn main() {\n println!(\"Hello\");\n}"; + /// let rope = Rope::from_str(code); + /// let mut highlighter = SyntaxHighlighter::new("rust"); + /// highlighter.update(None, &rope); + /// + /// let theme = HighlightTheme::default_dark(); + /// let range = 0..code.len(); + /// let styles = highlighter.styles(&range, &theme); + /// ``` + pub fn styles( &self, range: &Range, theme: &HighlightTheme,