aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-11-22 07:45:52 +0000
committerBlaž Hrastnik2021-11-29 02:00:28 +0000
commitba45db84d4b49913836a949472366a30a620e67b (patch)
tree44baec10e64e81ff4554fcaa2ef5cb1403a93e09 /helix-term/src
parentc71c9f69e21a80c5c9c744bddbde7d5041da99a5 (diff)
Tie the GutterFn lifetime to the doc so we can avoid cloning data
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/ui/editor.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 8c4ea9cc..2cc212ea 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -421,19 +421,19 @@ impl EditorView {
.map(|range| range.cursor_line(text))
.collect();
- fn diagnostic(
- doc: &Document,
+ fn diagnostic<'doc>(
+ doc: &'doc Document,
_view: &View,
theme: &Theme,
_config: &Config,
_is_focused: bool,
_width: usize,
- ) -> GutterFn {
+ ) -> GutterFn<'doc> {
let warning = theme.get("warning");
let error = theme.get("error");
let info = theme.get("info");
let hint = theme.get("hint");
- let diagnostics = doc.diagnostics().to_vec(); // TODO
+ let diagnostics = doc.diagnostics();
Box::new(move |line: usize, _selected: bool| {
use helix_core::diagnostic::Severity;
@@ -452,14 +452,14 @@ impl EditorView {
})
}
- fn line_number(
- doc: &Document,
+ fn line_number<'doc>(
+ doc: &'doc Document,
view: &View,
theme: &Theme,
config: &Config,
is_focused: bool,
width: usize,
- ) -> GutterFn {
+ ) -> GutterFn<'doc> {
let text = doc.text().slice(..);
let last_line = view.last_line(doc);
// 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 Gutter = fn(&Document, &View, &Theme, &Config, bool, usize) -> GutterFn;
+ type GutterFn<'doc> = Box<dyn Fn(usize, bool) -> Option<(String, Style)> + 'doc>;
+ type Gutter =
+ for<'doc> fn(&'doc Document, &View, &Theme, &Config, bool, usize) -> GutterFn<'doc>;
let gutters: &[(Gutter, usize)] = &[(diagnostic, 1), (line_number, 5)];
let mut offset = 0;