1
//! Completions for the tag lists: looked up through `form-options` as the
2
//! cursor reaches a name or value cell, each answer dropped when superseded.
3

            
4
use cli_core::forms::parse_suggestions;
5
use forms::escape_str;
6

            
7
use crate::app::App;
8
use crate::modal::Modal;
9
use crate::route::RouteCtx;
10
use crate::widgets::Hint;
11

            
12
impl App {
13
    /// Asks for the lookup the open form's focused tag cell needs.
14
2064
    pub fn fetch_tag_hints(&mut self) {
15
2064
        if self.console_eval.is_none() {
16
1116
            return;
17
948
        }
18
948
        let Some(Modal::Form(form)) = self.overlays.top() else {
19
174
            return;
20
        };
21
774
        let Some(hint) = form.wanted_hint() else {
22
766
            return;
23
        };
24
8
        let seq = self.suggest_seq.advance();
25
8
        let call = format!("(form-options {})", escape_str(&hint.source()));
26
8
        let ctx = RouteCtx::Suggestion {
27
8
            seq,
28
8
            hint: hint.clone(),
29
8
        };
30
8
        if self.dispatch_app_eval(ctx, call).is_some()
31
8
            && let Some(Modal::Form(form)) = self.overlays.top_mut()
32
        {
33
8
            form.hint_asked(&hint, seq);
34
        }
35
2064
    }
36

            
37
5
    pub(super) fn deliver_tag_hints(&mut self, seq: u64, hint: &Hint, wire: &str) {
38
5
        let Some(strings) = parse_suggestions(wire) else {
39
1
            return;
40
        };
41
4
        if let Some(form) = self.form_mut(|_| true) {
42
4
            form.hint_arrived(hint, seq, strings);
43
        }
44
5
    }
45
}