duat-base 0.10.0

Basic components common in Duat, included by default on duat
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
//! A gutter to add side information relating to the [`Buffer`]
//!
//! This struct is meant to be used by plugins like `duat-lsp`, which
//! can show diagnostics about a `Buffer`. This [`Widget`] will then
//! be used to show that there are errors in the `Buffer`.
//!
//! Additionally, this module contains functions that are used to add
//! errors to a `Buffer`.
//!
//! [`Buffer`]: duat_core::buffer::Buffer
use std::{collections::HashMap, ops::Range, sync::Once};

use duat_core::{
    Ns,
    buffer::{Buffer, Moment},
    context::{self, Handle},
    data::Pass,
    form::{self, Form, FormId},
    hook::{self, BufferOpened, BufferUpdated, OnMouseEvent},
    text::{Inlay, Text, TextParts, TextRange, TwoPoints},
    txt,
    ui::{Coord, PushSpecs, Side, Widget},
};

/// A struct to hold diagnostic hints about a [`Buffer`].
///
/// It sits on the sides of the `Buffer`, and tells you when there are
/// things to note about specific lines. These may be hints, warnings,
/// errors, or custom annotations.
///
/// [`Buffer`]: duat_core::buffer::Buffer
pub struct Gutter {
    text: Text,
    entries: HashMap<Ns, Vec<GutterEntry>>,
    opts: GutterOpts,
    mouse_coord: Option<Coord>,
}

fn initial_setup() {
    form::set_weak("gutter.hint", Form::mimic("default.info"));
    form::set_weak("gutter.warning", Form::mimic("default.warning"));
    form::set_weak("gutter.error", Form::mimic("default.error"));
    form::set_weak("buffer.hint", Form::new().underline_grey().underlined());
    form::set_weak(
        "buffer.warning",
        Form::new().underline_yellow().underlined(),
    );
    form::set_weak("buffer.error", Form::new().underline_red().underlined());

    let ns = Ns::new();
    let msg_ns = Ns::new();

    hook::add::<BufferOpened>(move |pa, buffer| _ = buffer.read(pa).moment_for(ns));
    hook::add::<BufferUpdated>(move |pa, buffer| {
        let Some((gutter, _)) = buffer.get_related::<Gutter>(pa).first().cloned() else {
            return;
        };

        let printed_line_ranges = buffer.printed_line_ranges(pa);

        let (gtr, buf) = pa.write_many((&gutter, buffer));
        gtr.apply_changes(buf.moment_for(ns));

        let (gt, buf, area) = pa.write_many((&gutter, buffer, buffer.area()));
        buf.text_parts().tags.remove(msg_ns, ..);
        let opts = buf.print_opts();

        let mouse_point = gt
            .mouse_coord
            .filter(|&coord| coord >= area.top_left() && coord < area.bottom_right())
            .and_then(|coord| {
                Some(
                    area.points_at_coord(buf.text(), coord, opts)?
                        .as_within()?
                        .real,
                )
            });

        let entries = gt
            .entries
            .iter()
            .flat_map(|(_, entries)| entries)
            .filter(|entry| {
                let is_onscreen = printed_line_ranges
                    .iter()
                    .any(|range| range.contains(&entry.range.end));

                let display = match entry.kind {
                    EntryKind::Hint => gt.opts.hint.display,
                    EntryKind::Warning => gt.opts.warning.display,
                    EntryKind::Error => gt.opts.error.display,
                    EntryKind::_Custom(..) => todo!(),
                };

                let do_show = match display {
                    GutterDisplay::OwnLines(always) => {
                        always
                            || mouse_point.is_some_and(|point| entry.range.contains(&point.byte()))
                    }
                    GutterDisplay::Inline(_) => todo!(),
                    GutterDisplay::Spawn(_) => todo!(),
                    GutterDisplay::SpawnCorner(..) => todo!(),
                };

                do_show && is_onscreen
            });

        for entry in entries {
            let Some(line) = buf.text()[entry.range.clone()].lines().last() else {
                continue;
            };

            let range = line.range();
            let lnum = range.start.line();
            let Some(columns) =
                area.columns_at(buf.text(), TwoPoints::new_after_ghost(range.start), opts)
            else {
                continue;
            };

            let mut parts = buf.text_parts();

            let inlay = Inlay::new(txt!("{}{entry.msg}\n", " ".repeat(columns.wrapped)));
            let line_end = parts.strs.line(lnum).byte_range().end;
            parts.tags.insert(msg_ns, line_end, inlay)
        }
    })
    .lateness(100_000_000);

    hook::add::<BufferUpdated>(|pa, buffer| {
        let Some((gutter, _)) = buffer.get_related::<Gutter>(pa).first().cloned() else {
            return;
        };

        gutter.write(pa).text = Gutter::form_text(gutter.read(pa), pa, buffer);
    })
    .lateness(usize::MAX);

    hook::add::<OnMouseEvent<Buffer>>(move |pa, event| {
        let Some((gutter, _)) = event.handle.get_related::<Gutter>(pa).first().cloned() else {
            return;
        };

        gutter.write(pa).mouse_coord = Some(event.coord);
    })
    .lateness(usize::MAX);

    hook::add::<OnMouseEvent>(move |pa, _| {
        for gutter in context::windows().handles_of::<Gutter>(pa) {
            let gt = gutter.write(pa);
            if gt.mouse_coord.take().is_some() {
                let (buffer, _) = gutter.get_related::<Buffer>(pa).first().cloned().unwrap();
                buffer.request_update();
            }
        }
    })
    .lateness(usize::MAX);
}

impl Gutter {
    /// A builder for a `Gutter`.
    pub fn builder() -> GutterOpts {
        static ONCE: Once = Once::new();
        ONCE.call_once(initial_setup);

        GutterOpts {
            hint: GutterSymbolOpts {
                symbol: 'i',
                display: GutterDisplay::OwnLines(false),
            },
            warning: GutterSymbolOpts {
                symbol: '!',
                display: GutterDisplay::OwnLines(false),
            },
            error: GutterSymbolOpts {
                symbol: '*',
                display: GutterDisplay::OwnLines(true),
            },
            renderer: Some(Box::new(default_renderer)),
        }
    }

    fn form_text(&self, pa: &Pass, buffer: &Handle) -> Text {
        let printed_line_numbers = buffer.printed_line_numbers(pa);
        let text = buffer.text(pa);

        let mut builder = Text::builder();

        for (idx, line) in printed_line_numbers.iter().enumerate() {
            if idx > 0 && (line.is_wrapped || line.is_ghost) {
                builder.push(" \n");
                continue;
            };

            let mut kind = None;
            let range = text.line(line.number).byte_range();

            for (_, entries) in self.entries.iter() {
                let (Ok(idx) | Err(idx)) =
                    entries.binary_search_by(|entry| entry.range.start.cmp(&range.start));

                let mut iter = entries[idx..].iter();
                while let Some(entry) = iter.next()
                    && entry.range.start < range.end
                {
                    kind = kind.max(Some(entry.kind))
                }
            }

            if let Some(kind) = kind {
                let (symbol, symbol_form) = match kind {
                    EntryKind::Hint => (self.opts.hint.symbol, form::id_of!("gutter.hint")),
                    EntryKind::Warning => {
                        (self.opts.warning.symbol, form::id_of!("gutter.warning"))
                    }
                    EntryKind::Error => (self.opts.error.symbol, form::id_of!("gutter.error")),
                    EntryKind::_Custom(symbol, symbol_form, _) => (symbol, symbol_form),
                };

                builder.push(symbol_form);
                builder.push(symbol);
                builder.push(FormId::default());
                builder.push("\n");
            } else {
                builder.push(" \n");
            }
        }

        builder.build()
    }

    fn apply_changes(&mut self, moment: Moment) {
        let sh = |value: &mut usize, shift: i32| {
            *value = value.saturating_add_signed(shift as isize);
        };

        for (_, entries) in self.entries.iter_mut() {
            let mut shift = 0;
            let mut iter = entries.iter_mut().enumerate();
            let mut to_remove = Vec::new();

            for change in moment.iter() {
                let mut is_contained = |i: usize, range: Range<usize>| {
                    let change_range = change.taken_range();
                    let change_range = change_range.start.byte()..change_range.end.byte();
                    if change_range.contains(&range.start) || change_range.contains(&range.end) {
                        to_remove.push(i);
                        true
                    } else {
                        false
                    }
                };

                if let Some((_, entry)) = iter.find_map(|(i, entry)| {
                    sh(&mut entry.range.start, shift);
                    sh(&mut entry.range.end, shift);

                    (!is_contained(i, entry.range.clone())
                        && entry.range.end > change.start().byte())
                    .then_some((i, entry))
                }) {
                    let start_shift =
                        change.shift()[0] * (entry.range.start > change.start().byte()) as i32;

                    sh(&mut entry.range.start, start_shift);
                    sh(&mut entry.range.end, change.shift()[0]);
                }
                shift += change.shift()[0];
            }

            for idx in to_remove.into_iter().rev() {
                entries.remove(idx);
            }
        }
    }
}

impl Widget for Gutter {
    fn text(&self) -> &Text {
        &self.text
    }

    fn text_mut(&mut self) -> duat_core::text::TextMut<'_> {
        self.text.as_mut()
    }
}

/// Options for the [`Gutter`].
///
/// You can change the character of hints, warnings and errors, and
/// you can also set how they should be displayed by default.
pub struct GutterOpts {
    /// Hints are information that doesn't necessarily indicate that
    /// something's wrong, but may be related to an actual issue.
    ///
    /// By default, they are shown as `'i'` on the [`Gutter`], and the
    /// hint's [`Text`] is only shown when hovering over it.
    ///
    /// On the `Gutter`, it makes use of the `gutter.hint` [`Form`],
    /// while on the [`Buffer`], it makes use of the `buffer.hint`
    /// `Form`.
    ///
    /// [`Buffer`]: duat_core::buffer::Buffer
    pub hint: GutterSymbolOpts,
    /// Warnings are problems with your code that don't necessarily
    /// prevent it from working or compiling, but otherwise represent
    /// inadequacies or things that could be improved upon.
    ///
    /// By default, they are shown as `'!'` on the [`Gutter`], and the
    /// hint's [`Text`] is only shown when hovering over it.
    ///
    /// On the `Gutter`, it makes use of the `gutter.warning`
    /// [`Form`], while on the [`Buffer`], it makes use of the
    /// `buffer.warning` `Form`.
    ///
    /// [`Buffer`]: duat_core::buffer::Buffer
    pub warning: GutterSymbolOpts,
    /// Errors are fundamental issues with your code. Either the
    /// compiler couldn't figure out what you meant, or the code is
    /// invalid for some reason.
    ///
    /// By default, they are shown as `'*'` on the [`Gutter`], and the
    /// hint's [`Text`] is shown as [`Inlay`] text on separate lines.
    ///
    /// On the `Gutter`, it makes use of the `gutter.error`
    /// [`Form`], while on the [`Buffer`], it makes use of the
    /// `buffer.error` `Form`.
    ///
    /// [`Buffer`]: duat_core::buffer::Buffer
    pub error: GutterSymbolOpts,
    renderer: Option<Box<Renderer>>,
}

impl GutterOpts {
    /// Places a [`Gutter`] around a [`Buffer`].
    ///
    /// The [`Widget`] will be pushed on the "outside". That is, if
    /// there are other widgets pushed on the buffer, this one will be
    /// placed around them.
    ///
    /// [`Buffer`]: duat_core::buffer::Buffer
    pub fn push_on(self, pa: &mut Pass, handle: &Handle) -> Handle<Gutter> {
        let text = Text::from(" \n".repeat(handle.text(pa).end_point().line()));

        handle.push_outer_widget(
            pa,
            Gutter {
                text,
                entries: HashMap::new(),
                opts: self,
                mouse_coord: None,
            },
            PushSpecs {
                side: Side::Left,
                width: Some(1.0),
                ..PushSpecs::default()
            },
        )
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct GutterSymbolOpts {
    symbol: char,
    display: GutterDisplay,
}

/// Related entries on the [`Gutter`].
pub struct GutterEntries {
    /// The entries that are related.
    list: Vec<GutterEntry>,
    /// How to display the entry's message.
    _display: GutterDisplay,
}

/// An entry in the [`Gutter`].
///
/// This contains a range in the [`Text`] and a message, in the form
/// of a `Text`.
pub struct GutterEntry {
    range: Range<usize>,
    msg: Text,
    kind: EntryKind,
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
enum EntryKind {
    Hint,
    Warning,
    Error,
    _Custom(char, FormId, FormId),
}

/// How to display the accompanying [`Text`] message to a [`Gutter`]
/// entry.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(unused)]
pub enum GutterDisplay {
    /// The [`Text`] will be shown at the end of the line, potentially
    /// running off out of screen.
    ///
    /// If [`GutterEntryBuilder::only_on_hover`] is not called, this
    /// display method will default to always be shown.
    Inline(OnlyOnHover),
    /// The [`Text`] will be shown as a spawned widget near the
    /// entry's range.
    ///
    /// If [`GutterEntryBuilder::only_on_hover`] is not called, this
    /// display method will default to show up only on hover.
    Spawn(OnlyOnHover),
    /// The [`Text`] will be show as a spawned widget on one of the
    /// corners.
    ///
    /// If [`OnWindow`] is set to true, this will spawn it on the
    /// corners of the window. Otherwise, it will be spawned on the
    /// corners of the [`Buffer`]
    ///
    /// If [`GutterEntryBuilder::only_on_hover`] is not called, this
    /// display method will default to show up only on hover.
    ///
    /// [`Buffer`]: duat_core::buffer::Buffer
    SpawnCorner(OnlyOnHover, Corner, OnWindow),
    /// The [`Text`] will be shown as [`Inlay`] lines under the
    /// entry's range.
    ///
    /// If [`GutterEntryBuilder::only_on_hover`] is not called, this
    /// display method will default to always be shown.
    OwnLines(OnlyOnHover),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(unused)]
pub enum Corner {
    TopLeft,
    TopRight,
    BottomRight,
    BottomLeft,
}

/// A builder for a [`Gutter`] entry.
///
/// This lets you add more related messages to this entry, which will
/// make their display cohesive. You may, for example, have an error
/// that happens in a specific line, because of a decision you made on
/// another line (e.g. borrowing errors on Rust), which should be
/// interlinked with this error, in order to show more cohesive
/// diagnostics.
pub struct GutterEntryBuilder<'p> {
    ns: Ns,
    pa: &'p mut Pass,
    buffer: &'p Handle,
    gutter: Handle<Gutter>,
    entries: GutterEntries,
}

impl<'g> GutterEntryBuilder<'g> {
    /// Add a hint that is related to this entry.
    ///
    /// This could be something like the first borrow, which prevented
    /// a future borrow from making sense (in Rust).
    pub fn add_related_hint(mut self, range: impl TextRange, msg: Text) -> Self {
        let text = self.buffer.text(self.pa);
        let range = range.to_range(text.len());

        self.entries
            .list
            .push(GutterEntry { range, msg, kind: EntryKind::Hint });

        self
    }

    /// Add a warning that is related to this entry.
    pub fn add_related_warning(mut self, range: impl TextRange, msg: Text) -> Self {
        let text = self.buffer.text(self.pa);
        let range = range.to_range(text.len());

        self.entries
            .list
            .push(GutterEntry { range, msg, kind: EntryKind::Warning });

        self
    }

    /// Add an error that is related to this entry.
    ///
    /// This could be more errors on the same range, since it's
    /// possible that multiple things went wrong, or more context
    /// would be helpful.
    pub fn add_related_error(mut self, range: impl TextRange, msg: Text) -> Self {
        let text = self.buffer.text(self.pa);
        let range = range.to_range(text.len());

        self.entries
            .list
            .push(GutterEntry { range, msg, kind: EntryKind::Error });

        self
    }
}

impl<'g> Drop for GutterEntryBuilder<'g> {
    fn drop(&mut self) {
        let (buf, gtr) = self.pa.write_many((self.buffer, &self.gutter));

        let mut renderer = gtr.opts.renderer.take().unwrap();
        renderer(&self.entries, self.ns, buf.text_mut().parts());
        gtr.opts.renderer = Some(renderer);

        let entries = gtr.entries.entry(self.ns).or_default();

        for entry in std::mem::take(&mut self.entries.list) {
            let (Ok(idx) | Err(idx)) =
                entries.binary_search_by(|e| e.range.start.cmp(&entry.range.start));
            entries.insert(idx, entry);
        }
    }
}

#[allow(private_bounds)]
trait Sealed {}
/// Trait for adding gutter entries to a [`Buffer`].
///
/// [`Buffer`]: duat_core::buffer::Buffer
#[allow(private_bounds)]
pub trait GutterBuffer: Sealed {
    /// Remove all [`Gutter`] entries from a given [`Ns`].
    fn remove_gutter_entries(&self, pa: &mut Pass, ns: Ns);

    /// Add a hint to the [`Gutter`] and the [`Buffer`].
    ///
    /// This could just be useful information, like the fact that
    /// something won't be included in compilation because of a `cfg`
    /// attribute.
    fn add_hint<'g>(
        &'g self,
        pa: &'g mut Pass,
        ns: Ns,
        range: impl TextRange,
        msg: Text,
    ) -> GutterEntryBuilder<'g>;

    /// Add a warning to the [`Gutter`] and the [`Buffer`].
    ///
    /// This could be improvements that you could do to your code, or
    /// ways in which it is innadequate that don't necessarily hinder
    /// it from working properly.
    fn add_warning<'g>(
        &'g self,
        pa: &'g mut Pass,
        ns: Ns,
        range: impl TextRange,
        msg: Text,
    ) -> GutterEntryBuilder<'g>;

    /// Add an error to the [`Gutter`] and the [`Buffer`].
    ///
    /// These are fundamental issues in your code, and either prevent
    /// compilation, or prevent it from working properly.
    fn add_error<'g>(
        &'g self,
        pa: &'g mut Pass,
        ns: Ns,
        range: impl TextRange,
        msg: Text,
    ) -> GutterEntryBuilder<'g>;
}

impl Sealed for Handle {}
impl GutterBuffer for Handle {
    #[track_caller]
    fn remove_gutter_entries(&self, pa: &mut Pass, ns: Ns) {
        let Some((gutter, _)) = self.get_related::<Gutter>(pa).first().cloned() else {
            panic!("Tried to remove Gutter entries on Buffer with no Gutter");
        };

        gutter.write(pa).entries.remove(&ns);
        self.text_mut(pa).remove_tags(ns, ..);
    }

    #[track_caller]
    fn add_hint<'g>(
        &'g self,
        pa: &'g mut Pass,
        ns: Ns,
        range: impl TextRange,
        msg: Text,
    ) -> GutterEntryBuilder<'g> {
        let Some((gutter, _)) = self.get_related::<Gutter>(pa).first().cloned() else {
            panic!("Tried to add a Gutter entry on Buffer with no Gutter");
        };

        let text = self.text(pa);
        let range = range.to_range(text.len());
        let display = gutter.read(pa).opts.hint.display;

        GutterEntryBuilder {
            ns,
            pa,
            buffer: self,
            gutter,
            entries: GutterEntries {
                list: vec![GutterEntry { range, msg, kind: EntryKind::Hint }],
                _display: display,
            },
        }
    }

    #[track_caller]
    fn add_warning<'g>(
        &'g self,
        pa: &'g mut Pass,
        ns: Ns,
        range: impl TextRange,
        msg: Text,
    ) -> GutterEntryBuilder<'g> {
        let Some((gutter, _)) = self.get_related::<Gutter>(pa).first().cloned() else {
            panic!("Tried to add a Gutter entry on Buffer with no Gutter");
        };

        let text = self.text(pa);
        let range = range.to_range(text.len());
        let display = gutter.read(pa).opts.hint.display;

        GutterEntryBuilder {
            ns,
            pa,
            buffer: self,
            gutter,
            entries: GutterEntries {
                list: vec![GutterEntry { range, msg, kind: EntryKind::Warning }],
                _display: display,
            },
        }
    }

    #[track_caller]
    fn add_error<'g>(
        &'g self,
        pa: &'g mut Pass,
        ns: Ns,
        range: impl TextRange,
        msg: Text,
    ) -> GutterEntryBuilder<'g> {
        let Some((gutter, _)) = self.get_related::<Gutter>(pa).first().cloned() else {
            panic!("Tried to add a Gutter entry on Buffer with no Gutter");
        };

        let text = self.text(pa);
        let range = range.to_range(text.len());
        let display = gutter.read(pa).opts.hint.display;

        GutterEntryBuilder {
            ns,
            pa,
            buffer: self,
            gutter,
            entries: GutterEntries {
                list: vec![GutterEntry { range, msg, kind: EntryKind::Error }],
                _display: display,
            },
        }
    }
}

/// The default [`Gutter`] renderer.
///
/// You can use this if you want to render things differently in some
/// situations, but not all.
pub fn default_renderer(entries: &GutterEntries, ns: Ns, mut parts: TextParts<'_>) {
    for entry in &entries.list {
        let form_tag = match entry.kind {
            EntryKind::Hint => form::id_of!("buffer.hint").to_tag(190),
            EntryKind::Warning => form::id_of!("buffer.warning").to_tag(191),
            EntryKind::Error => form::id_of!("buffer.error").to_tag(192),
            EntryKind::_Custom(.., text_form) => text_form.to_tag(193),
        };

        parts.tags.insert(ns, entry.range.clone(), form_tag);
    }
}

type Renderer = dyn FnMut(&GutterEntries, Ns, TextParts<'_>) + 'static + Send;
type OnlyOnHover = bool;
type OnWindow = bool;