highlighter: Make SyntaxHighlighter::styles method public for external use (#1415)

This commit is contained in:
Copilot 2025-10-23 10:34:13 +08:00 committed by GitHub
parent ab104b6ba9
commit 3c6a7b6a9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<usize>,
theme: &HighlightTheme,