highlighted_code_block: Take input text as &str

This removes a handful of allocations for functions calling into the
function, which is nice because the prompt may call this function on
every keypress.
pull/7764/head
Michael Davis 1 year ago committed by Blaž Hrastnik
parent 98ef05d768
commit 953073a679

@ -62,7 +62,7 @@ impl Component for SignatureHelp {
}); });
let sig_text = crate::ui::markdown::highlighted_code_block( let sig_text = crate::ui::markdown::highlighted_code_block(
self.signature.clone(), &self.signature,
&self.language, &self.language,
Some(&cx.editor.theme), Some(&cx.editor.theme),
Arc::clone(&self.config_loader), Arc::clone(&self.config_loader),
@ -109,7 +109,7 @@ impl Component for SignatureHelp {
let max_text_width = (viewport.0 - PADDING).min(120); let max_text_width = (viewport.0 - PADDING).min(120);
let signature_text = crate::ui::markdown::highlighted_code_block( let signature_text = crate::ui::markdown::highlighted_code_block(
self.signature.clone(), &self.signature,
&self.language, &self.language,
None, None,
Arc::clone(&self.config_loader), Arc::clone(&self.config_loader),

@ -17,7 +17,7 @@ use helix_view::{
Theme, Theme,
}; };
fn styled_multiline_text<'a>(text: String, style: Style) -> Text<'a> { fn styled_multiline_text<'a>(text: &str, style: Style) -> Text<'a> {
let spans: Vec<_> = text let spans: Vec<_> = text
.lines() .lines()
.map(|line| Span::styled(line.to_string(), style)) .map(|line| Span::styled(line.to_string(), style))
@ -27,7 +27,7 @@ fn styled_multiline_text<'a>(text: String, style: Style) -> Text<'a> {
} }
pub fn highlighted_code_block<'a>( pub fn highlighted_code_block<'a>(
text: String, text: &str,
language: &str, language: &str,
theme: Option<&Theme>, theme: Option<&Theme>,
config_loader: Arc<syntax::Loader>, config_loader: Arc<syntax::Loader>,
@ -267,7 +267,7 @@ impl Markdown {
CodeBlockKind::Indented => "", CodeBlockKind::Indented => "",
}; };
let tui_text = highlighted_code_block( let tui_text = highlighted_code_block(
text.to_string(), &text,
language, language,
theme, theme,
Arc::clone(&self.config_loader), Arc::clone(&self.config_loader),

@ -476,7 +476,7 @@ impl Prompt {
} }
} else if let Some((language, loader)) = self.language.as_ref() { } else if let Some((language, loader)) = self.language.as_ref() {
let mut text: ui::text::Text = crate::ui::markdown::highlighted_code_block( let mut text: ui::text::Text = crate::ui::markdown::highlighted_code_block(
self.line.clone(), &self.line,
language, language,
Some(&cx.editor.theme), Some(&cx.editor.theme),
loader.clone(), loader.clone(),

Loading…
Cancel
Save