on master help sign in
Tie the GutterFn lifetime to the doc so we can avoid cloning data
commitba45db84d4b49913836a949472366a30a620e67b authorBlaž Hrastnik <blaz@mxxn.io> dateMon 22 Nov 2021, 16:45 (5 years ago) parentc71c9f6
1 file changed+10−9
helix-term/src/ui/editor.rs+10−9
helix-term/src/ui/editor.rs+10−9
@@ -421,19 +421,19 @@ impl EditorView {
421421 .map(|range| range.cursor_line(text))
422422 .collect();
423423
424− fn diagnostic(
425− doc: &Document,
424+ fn diagnostic<'doc>(
425+ doc: &'doc Document,
426426 _view: &View,
427427 theme: &Theme,
428428 _config: &Config,
429429 _is_focused: bool,
430430 _width: usize,
431− ) -> GutterFn {
431+ ) -> GutterFn<'doc> {
432432 let warning = theme.get("warning");
433433 let error = theme.get("error");
434434 let info = theme.get("info");
435435 let hint = theme.get("hint");
436− let diagnostics = doc.diagnostics().to_vec(); // TODO
436+ let diagnostics = doc.diagnostics();
437437
438438 Box::new(move |line: usize, _selected: bool| {
439439 use helix_core::diagnostic::Severity;
@@ -452,14 +452,14 @@ impl EditorView {
452452 })
453453 }
454454
455− fn line_number(
456− doc: &Document,
455+ fn line_number<'doc>(
456+ doc: &'doc Document,
457457 view: &View,
458458 theme: &Theme,
459459 config: &Config,
460460 is_focused: bool,
461461 width: usize,
462− ) -> GutterFn {
462+ ) -> GutterFn<'doc> {
463463 let text = doc.text().slice(..);
464464 let last_line = view.last_line(doc);
465465 // Whether to draw the line number for the last line of the
@@ -499,8 +499,9 @@ impl EditorView {
499499 })
500500 }
501501
502− type GutterFn = Box<dyn Fn(usize, bool) -> Option<(String, Style)>>;
503− type Gutter = fn(&Document, &View, &Theme, &Config, bool, usize) -> GutterFn;
502+ type GutterFn<'doc> = Box<dyn Fn(usize, bool) -> Option<(String, Style)> + 'doc>;
503+ type Gutter =
504+ for<'doc> fn(&'doc Document, &View, &Theme, &Config, bool, usize) -> GutterFn<'doc>;
504505 let gutters: &[(Gutter, usize)] = &[(diagnostic, 1), (line_number, 5)];
505506
506507 let mut offset = 0;