kanata_parser/
lsp_hints.rs1pub use inner::*;
2
3#[cfg(not(feature = "lsp"))]
4mod inner {
5 #[derive(Debug, Default)]
6 pub struct LspHints {}
7}
8
9#[cfg(feature = "lsp")]
10mod inner {
11 use crate::cfg::sexpr::{Span, Spanned};
12 type HashMap<K, V> = rustc_hash::FxHashMap<K, V>;
13
14 #[derive(Debug, Default)]
15 pub struct LspHints {
16 pub inactive_code: Vec<InactiveCode>,
17 pub definition_locations: DefinitionLocations,
18 pub reference_locations: ReferenceLocations,
19 }
20
21 #[derive(Debug, Clone)]
22 pub struct InactiveCode {
23 pub span: Span,
24 pub reason: String,
25 }
26
27 #[derive(Debug, Default, Clone)]
28 pub struct DefinitionLocations {
29 pub alias: HashMap<String, Span>,
30 pub variable: HashMap<String, Span>,
31 pub virtual_key: HashMap<String, Span>,
32 pub layer: HashMap<String, Span>,
33 pub template: HashMap<String, Span>,
34 }
35
36 #[derive(Debug, Default, Clone)]
37 pub struct ReferenceLocations {
38 pub alias: ReferencesMap,
39 pub variable: ReferencesMap,
40 pub virtual_key: ReferencesMap,
41 pub layer: ReferencesMap,
42 pub template: ReferencesMap,
43 pub include: ReferencesMap,
44 }
45
46 #[derive(Debug, Default, Clone)]
47 pub struct ReferencesMap(pub HashMap<String, Vec<Span>>);
48
49 #[allow(unused)]
50 impl ReferencesMap {
51 pub(crate) fn push_from_atom(&mut self, atom: &Spanned<String>) {
52 match self.0.get_mut(&atom.t) {
53 Some(refs) => refs.push(atom.span.clone()),
54 None => {
55 self.0.insert(atom.t.clone(), vec![atom.span.clone()]);
56 }
57 };
58 }
59
60 pub(crate) fn push(&mut self, name: &str, span: Span) {
61 match self.0.get_mut(name) {
62 Some(refs) => refs.push(span),
63 None => {
64 self.0.insert(name.to_owned(), vec![span]);
65 }
66 };
67 }
68 }
69}