Tie the GutterFn lifetime to the doc so we can avoid cloning data

pull/1184/head
Blaž Hrastnik 3 years ago
parent c71c9f69e2
commit ba45db84d4

@ -421,19 +421,19 @@ impl EditorView {
.map(|range| range.cursor_line(text)) .map(|range| range.cursor_line(text))
.collect(); .collect();
fn diagnostic( fn diagnostic<'doc>(
doc: &Document, doc: &'doc Document,
_view: &View, _view: &View,
theme: &Theme, theme: &Theme,
_config: &Config, _config: &Config,
_is_focused: bool, _is_focused: bool,
_width: usize, _width: usize,
) -> GutterFn { ) -> GutterFn<'doc> {
let warning = theme.get("warning"); let warning = theme.get("warning");
let error = theme.get("error"); let error = theme.get("error");
let info = theme.get("info"); let info = theme.get("info");
let hint = theme.get("hint"); let hint = theme.get("hint");
let diagnostics = doc.diagnostics().to_vec(); // TODO let diagnostics = doc.diagnostics();
Box::new(move |line: usize, _selected: bool| { Box::new(move |line: usize, _selected: bool| {
use helix_core::diagnostic::Severity; use helix_core::diagnostic::Severity;
@ -452,14 +452,14 @@ impl EditorView {
}) })
} }
fn line_number( fn line_number<'doc>(
doc: &Document, doc: &'doc Document,
view: &View, view: &View,
theme: &Theme, theme: &Theme,
config: &Config, config: &Config,
is_focused: bool, is_focused: bool,
width: usize, width: usize,
) -> GutterFn { ) -> GutterFn<'doc> {
let text = doc.text().slice(..); let text = doc.text().slice(..);
let last_line = view.last_line(doc); let last_line = view.last_line(doc);
// Whether to draw the line number for the last line of the // Whether to draw the line number for the last line of the
@ -499,8 +499,9 @@ impl EditorView {
}) })
} }
type GutterFn = Box<dyn Fn(usize, bool) -> Option<(String, Style)>>; type GutterFn<'doc> = Box<dyn Fn(usize, bool) -> Option<(String, Style)> + 'doc>;
type Gutter = fn(&Document, &View, &Theme, &Config, bool, usize) -> GutterFn; type Gutter =
for<'doc> fn(&'doc Document, &View, &Theme, &Config, bool, usize) -> GutterFn<'doc>;
let gutters: &[(Gutter, usize)] = &[(diagnostic, 1), (line_number, 5)]; let gutters: &[(Gutter, usize)] = &[(diagnostic, 1), (line_number, 5)];
let mut offset = 0; let mut offset = 0;

Loading…
Cancel
Save