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
use crate::{
    db::RirDatabase,
    middle::context::tls::CUR_ITEM,
    rir::{Item, NodeKind},
    Plugin,
};

#[derive(Clone, Copy)]
pub struct _WorkspacePlugin;

impl Plugin for _WorkspacePlugin {
    fn on_codegen_uint(&mut self, cx: &crate::Context, _items: &[crate::DefId]) {
        cx.entry_map.iter().for_each(|(k, v)| {
            cx.plugin_gen.insert(k.clone(), "".to_string());
            v.iter().for_each(|(def_id, _)| {
                CUR_ITEM.set(def_id, || {
                    let node = cx.node(*def_id).unwrap();
                    if let NodeKind::Item(item) = &node.kind {
                        self.on_item(cx, *def_id, item.clone());
                    }
                });
            })
        });
    }

    fn on_item(
        &mut self,
        cx: &crate::Context,
        def_id: crate::DefId,
        item: std::sync::Arc<crate::rir::Item>,
    ) {
        if let Item::Service(s) = &*item {
            if let Some(loc) = cx.location_map.get(&def_id) {
                if let Some(mut gen) = cx.plugin_gen.get_mut(loc) {
                    gen.push_str(&format!("pub struct {};", s.name.sym));
                }
            };
        }
    }
}