emmylua_code_analysis/db_index/property/
property.rs

1use emmylua_parser::{LuaVersionCondition, VisibilityKind};
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct LuaCommonProperty {
5    pub visibility: VisibilityKind,
6    pub description: Option<Box<String>>,
7    pub source: Option<Box<String>>,
8    pub deprecated: Option<Box<LuaDeprecated>>,
9    pub version_conds: Option<Box<Vec<LuaVersionCondition>>>,
10    pub tag_content: Option<Box<LuaTagContent>>,
11    pub export: Option<LuaExport>,
12}
13
14impl LuaCommonProperty {
15    pub fn new() -> Self {
16        Self {
17            visibility: VisibilityKind::Public,
18            description: None,
19            source: None,
20            deprecated: None,
21            version_conds: None,
22            tag_content: None,
23            export: None,
24        }
25    }
26
27    pub fn description(&self) -> Option<&String> {
28        self.description.as_deref()
29    }
30
31    pub fn version_conds(&self) -> Option<&Vec<LuaVersionCondition>> {
32        self.version_conds.as_deref()
33    }
34
35    pub fn export(&self) -> Option<&LuaExport> {
36        self.export.as_ref()
37    }
38
39    pub fn tag_content(&self) -> Option<&LuaTagContent> {
40        self.tag_content.as_deref()
41    }
42
43    pub fn deprecated(&self) -> Option<&LuaDeprecated> {
44        self.deprecated.as_deref()
45    }
46
47    pub fn source(&self) -> Option<&String> {
48        self.source.as_deref()
49    }
50
51    pub fn add_extra_description(&mut self, description: String) {
52        self.description = Some(Box::new(description));
53    }
54
55    pub fn add_extra_source(&mut self, source: String) {
56        self.source = Some(Box::new(source));
57    }
58
59    pub fn add_extra_deprecated(&mut self, message: Option<String>) {
60        self.deprecated = match message {
61            Some(msg) => Some(Box::new(LuaDeprecated::DeprecatedWithMessage(msg))),
62            None => Some(Box::new(LuaDeprecated::Deprecated)),
63        };
64    }
65
66    pub fn add_extra_version_cond(&mut self, conds: Vec<LuaVersionCondition>) {
67        self.version_conds = Some(Box::new(conds));
68    }
69
70    pub fn add_extra_tag(&mut self, tag: String, content: String) {
71        self.tag_content
72            .get_or_insert_with(|| Box::new(LuaTagContent::new()))
73            .add_tag(tag, content);
74    }
75
76    pub fn add_extra_export(&mut self, export: LuaExport) {
77        self.export = Some(export);
78    }
79}
80
81#[derive(Debug, Clone, PartialEq, Eq)]
82pub enum LuaDeprecated {
83    Deprecated,
84    DeprecatedWithMessage(String),
85}
86
87#[derive(Debug, Clone, PartialEq, Eq)]
88pub enum LuaExportScope {
89    Global,
90    Namespace,
91}
92
93#[derive(Debug, Clone, PartialEq, Eq)]
94pub struct LuaTagContent {
95    pub tags: Vec<(String, String)>,
96}
97
98impl LuaTagContent {
99    pub fn new() -> Self {
100        Self { tags: Vec::new() }
101    }
102
103    pub fn add_tag(&mut self, tag: String, content: String) {
104        self.tags.push((tag, content));
105    }
106
107    pub fn get_all_tags(&self) -> &[(String, String)] {
108        &self.tags
109    }
110}
111
112#[derive(Debug, Clone, PartialEq, Eq)]
113pub struct LuaExport {
114    pub scope: LuaExportScope,
115}
116
117#[derive(Debug, Clone, Hash, PartialEq, Eq, Copy)]
118pub struct LuaPropertyId {
119    id: u32,
120}
121
122impl LuaPropertyId {
123    pub fn new(id: u32) -> Self {
124        Self { id }
125    }
126}