kanata_parser/
lsp_hints.rs

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
pub use inner::*;

#[cfg(not(feature = "lsp"))]
mod inner {
    #[derive(Debug, Default)]
    pub struct LspHints {}
}

#[cfg(feature = "lsp")]
mod inner {
    use crate::cfg::sexpr::{Span, Spanned};
    type HashMap<K, V> = rustc_hash::FxHashMap<K, V>;

    #[derive(Debug, Default)]
    pub struct LspHints {
        pub inactive_code: Vec<InactiveCode>,
        pub definition_locations: DefinitionLocations,
        pub reference_locations: ReferenceLocations,
    }

    #[derive(Debug, Clone)]
    pub struct InactiveCode {
        pub span: Span,
        pub reason: String,
    }

    #[derive(Debug, Default, Clone)]
    pub struct DefinitionLocations {
        pub alias: HashMap<String, Span>,
        pub variable: HashMap<String, Span>,
        pub virtual_key: HashMap<String, Span>,
        pub layer: HashMap<String, Span>,
        pub template: HashMap<String, Span>,
    }

    #[derive(Debug, Default, Clone)]
    pub struct ReferenceLocations {
        pub alias: ReferencesMap,
        pub variable: ReferencesMap,
        pub virtual_key: ReferencesMap,
        pub layer: ReferencesMap,
        pub template: ReferencesMap,
        pub include: ReferencesMap,
    }

    #[derive(Debug, Default, Clone)]
    pub struct ReferencesMap(pub HashMap<String, Vec<Span>>);

    #[allow(unused)]
    impl ReferencesMap {
        pub(crate) fn push_from_atom(&mut self, atom: &Spanned<String>) {
            match self.0.get_mut(&atom.t) {
                Some(refs) => refs.push(atom.span.clone()),
                None => {
                    self.0.insert(atom.t.clone(), vec![atom.span.clone()]);
                }
            };
        }

        pub(crate) fn push(&mut self, name: &str, span: Span) {
            match self.0.get_mut(name) {
                Some(refs) => refs.push(span),
                None => {
                    self.0.insert(name.to_owned(), vec![span]);
                }
            };
        }
    }
}