Skip to content

Commit 07b7bd0

Browse files
committed
rename LuaTypeAttribute to LuaTypeFlag
彻底区分语义
1 parent 05eb741 commit 07b7bd0

File tree

11 files changed

+84
-87
lines changed

11 files changed

+84
-87
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
.idea
33
.cursor
44
dhat-heap.json
5+
.claude
6+
7+
# MCP, 用于为AI提供lsp上下文
8+
.serena

crates/emmylua_code_analysis/src/compilation/analyzer/decl/docs.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rowan::TextRange;
88

99
use crate::{
1010
LuaTypeDecl, LuaTypeDeclId,
11-
db_index::{LuaDeclTypeKind, LuaTypeAttribute},
11+
db_index::{LuaDeclTypeKind, LuaTypeFlag},
1212
};
1313

1414
use super::DeclAnalyzer;
@@ -17,39 +17,39 @@ pub fn analyze_doc_tag_class(analyzer: &mut DeclAnalyzer, class: LuaDocTagClass)
1717
let name_token = class.get_name_token()?;
1818
let name = name_token.get_name_text().to_string();
1919
let range = name_token.syntax().text_range();
20-
let attrib = get_attrib_value(analyzer, class.get_attrib());
20+
let type_flag = get_type_flag_value(analyzer, class.get_type_flag());
2121

22-
add_type_decl(analyzer, &name, range, LuaDeclTypeKind::Class, attrib);
22+
add_type_decl(analyzer, &name, range, LuaDeclTypeKind::Class, type_flag);
2323
Some(())
2424
}
2525

26-
fn get_attrib_value(
26+
fn get_type_flag_value(
2727
analyzer: &mut DeclAnalyzer,
28-
attrib: Option<LuaDocTypeFlag>,
29-
) -> FlagSet<LuaTypeAttribute> {
30-
let mut attr: FlagSet<LuaTypeAttribute> = if analyzer.is_meta {
31-
LuaTypeAttribute::Meta.into()
28+
flag: Option<LuaDocTypeFlag>,
29+
) -> FlagSet<LuaTypeFlag> {
30+
let mut attr: FlagSet<LuaTypeFlag> = if analyzer.is_meta {
31+
LuaTypeFlag::Meta.into()
3232
} else {
33-
LuaTypeAttribute::None.into()
33+
LuaTypeFlag::None.into()
3434
};
3535

36-
if let Some(attrib) = attrib {
37-
for token in attrib.get_attrib_tokens() {
36+
if let Some(flag) = flag {
37+
for token in flag.get_attrib_tokens() {
3838
match token.get_name_text() {
3939
"partial" => {
40-
attr |= LuaTypeAttribute::Partial;
40+
attr |= LuaTypeFlag::Partial;
4141
}
4242
"key" => {
43-
attr |= LuaTypeAttribute::Key;
43+
attr |= LuaTypeFlag::Key;
4444
}
4545
// "global" => {
4646
// attr |= LuaTypeAttribute::Global;
4747
// }
4848
"exact" => {
49-
attr |= LuaTypeAttribute::Exact;
49+
attr |= LuaTypeFlag::Exact;
5050
}
5151
"constructor" => {
52-
attr |= LuaTypeAttribute::Constructor;
52+
attr |= LuaTypeFlag::Constructor;
5353
}
5454
_ => {}
5555
}
@@ -63,9 +63,9 @@ pub fn analyze_doc_tag_enum(analyzer: &mut DeclAnalyzer, enum_: LuaDocTagEnum) -
6363
let name_token = enum_.get_name_token()?;
6464
let name = name_token.get_name_text().to_string();
6565
let range = name_token.syntax().text_range();
66-
let attrib = get_attrib_value(analyzer, enum_.get_attrib());
66+
let flag = get_type_flag_value(analyzer, enum_.get_type_flag());
6767

68-
add_type_decl(analyzer, &name, range, LuaDeclTypeKind::Enum, attrib);
68+
add_type_decl(analyzer, &name, range, LuaDeclTypeKind::Enum, flag);
6969
Some(())
7070
}
7171

@@ -79,7 +79,7 @@ pub fn analyze_doc_tag_alias(analyzer: &mut DeclAnalyzer, alias: LuaDocTagAlias)
7979
&name,
8080
range,
8181
LuaDeclTypeKind::Alias,
82-
LuaTypeAttribute::None.into(),
82+
LuaTypeFlag::None.into(),
8383
);
8484
Some(())
8585
}
@@ -92,14 +92,12 @@ pub fn analyze_doc_tag_attribute(
9292
let name = name_token.get_name_text().to_string();
9393
let range = name_token.syntax().text_range();
9494

95-
// LuaTypeAttribute 与 LuaDocTagAttribute 完全是两个不同的概念.
96-
// LuaTypeAttribute 描述类型的属性, LuaDocTagAttribute 类似于 C# 的特性, 附加了更多的信息.
9795
add_type_decl(
9896
analyzer,
9997
&name,
10098
range,
10199
LuaDeclTypeKind::Attribute,
102-
LuaTypeAttribute::None.into(),
100+
LuaTypeFlag::None.into(),
103101
);
104102
Some(())
105103
}
@@ -187,7 +185,7 @@ fn add_type_decl(
187185
name: &str,
188186
range: TextRange,
189187
kind: LuaDeclTypeKind,
190-
attrib: FlagSet<LuaTypeAttribute>,
188+
flag: FlagSet<LuaTypeFlag>,
191189
) {
192190
let file_id = analyzer.get_file_id();
193191
let type_index = analyzer.db.get_type_index_mut();
@@ -201,6 +199,6 @@ fn add_type_decl(
201199
let simple_name = id.get_simple_name();
202200
type_index.add_type_decl(
203201
file_id,
204-
LuaTypeDecl::new(file_id, range, simple_name.to_string(), kind, attrib, id),
202+
LuaTypeDecl::new(file_id, range, simple_name.to_string(), kind, flag, id),
205203
);
206204
}

crates/emmylua_code_analysis/src/compilation/analyzer/doc/field_or_operator_def_tags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub fn analyze_operator(analyzer: &mut DocAnalyzer, tag: LuaDocTagOperator) -> O
199199
}
200200

201201
fn get_visibility_from_field_attrib(tag: &LuaDocTagField) -> Option<VisibilityKind> {
202-
if let Some(attrib) = tag.get_attrib() {
202+
if let Some(attrib) = tag.get_type_flag() {
203203
for token in attrib.get_attrib_tokens() {
204204
let visibility = VisibilityKind::to_visibility_kind(token.get_name_text());
205205
if visibility.is_some() {

crates/emmylua_code_analysis/src/db_index/type/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use crate::{DbIndex, FileId, InFiled};
1212
pub use generic_param::GenericParam;
1313
pub use humanize_type::{RenderLevel, format_union_type, humanize_type};
1414
use std::collections::{HashMap, HashSet};
15-
pub use type_decl::{
16-
LuaDeclLocation, LuaDeclTypeKind, LuaTypeAttribute, LuaTypeDecl, LuaTypeDeclId,
17-
};
15+
pub use type_decl::{LuaDeclLocation, LuaDeclTypeKind, LuaTypeDecl, LuaTypeDeclId, LuaTypeFlag};
1816
pub use type_ops::TypeOps;
1917
pub use type_owner::{LuaTypeCache, LuaTypeOwner};
2018
pub use type_visit_trait::TypeVisitTrait;

crates/emmylua_code_analysis/src/db_index/type/test.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod test {
44

55
use crate::db_index::traits::LuaIndex;
66
use crate::db_index::r#type::LuaTypeIndex;
7-
use crate::db_index::{LuaDeclTypeKind, LuaTypeAttribute};
7+
use crate::db_index::{LuaDeclTypeKind, LuaTypeFlag};
88
use crate::{FileId, LuaTypeDecl, LuaTypeDeclId};
99

1010
fn create_type_index() -> LuaTypeIndex {
@@ -26,7 +26,7 @@ mod test {
2626
TextRange::new(0.into(), 4.into()),
2727
"new_type".to_string(),
2828
LuaDeclTypeKind::Alias,
29-
LuaTypeAttribute::Partial.into(),
29+
LuaTypeFlag::Partial.into(),
3030
LuaTypeDeclId::new("test.new_type"),
3131
),
3232
);
@@ -62,7 +62,7 @@ mod test {
6262
TextRange::new(0.into(), 4.into()),
6363
"new_type".to_string(),
6464
LuaDeclTypeKind::Alias,
65-
LuaTypeAttribute::Partial.into(),
65+
LuaTypeFlag::Partial.into(),
6666
LuaTypeDeclId::new("test.new_type"),
6767
),
6868
);
@@ -92,7 +92,7 @@ mod test {
9292
TextRange::new(0.into(), 4.into()),
9393
"new_type".to_string(),
9494
LuaDeclTypeKind::Class,
95-
LuaTypeAttribute::Partial.into(),
95+
LuaTypeFlag::Partial.into(),
9696
LuaTypeDeclId::new("new_type"),
9797
),
9898
);
@@ -110,7 +110,7 @@ mod test {
110110
TextRange::new(0.into(), 4.into()),
111111
"new_type".to_string(),
112112
LuaDeclTypeKind::Class,
113-
LuaTypeAttribute::Partial.into(),
113+
LuaTypeFlag::Partial.into(),
114114
LuaTypeDeclId::new(".new_type"),
115115
),
116116
);
@@ -123,7 +123,7 @@ mod test {
123123
TextRange::new(0.into(), 4.into()),
124124
"new_type".to_string(),
125125
LuaDeclTypeKind::Class,
126-
LuaTypeAttribute::Partial.into(),
126+
LuaTypeFlag::Partial.into(),
127127
LuaTypeDeclId::new("new_type"),
128128
),
129129
);
@@ -150,7 +150,7 @@ mod test {
150150
TextRange::new(0.into(), 4.into()),
151151
"new_type".to_string(),
152152
LuaDeclTypeKind::Class,
153-
LuaTypeAttribute::Partial.into(),
153+
LuaTypeFlag::Partial.into(),
154154
LuaTypeDeclId::new("test.new_type"),
155155
),
156156
);

crates/emmylua_code_analysis/src/db_index/type/type_decl.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub enum LuaDeclTypeKind {
1919
}
2020

2121
flags! {
22-
pub enum LuaTypeAttribute: u8 {
22+
pub enum LuaTypeFlag: u8 {
2323
None,
2424
Key,
2525
Partial,
@@ -43,15 +43,15 @@ impl LuaTypeDecl {
4343
range: TextRange,
4444
name: String,
4545
kind: LuaDeclTypeKind,
46-
attrib: FlagSet<LuaTypeAttribute>,
46+
flag: FlagSet<LuaTypeFlag>,
4747
id: LuaTypeDeclId,
4848
) -> Self {
4949
Self {
5050
simple_name: name,
5151
locations: vec![LuaDeclLocation {
5252
file_id,
5353
range,
54-
attrib,
54+
flag,
5555
}],
5656
id,
5757
extra: match kind {
@@ -94,19 +94,19 @@ impl LuaTypeDecl {
9494
pub fn is_exact(&self) -> bool {
9595
self.locations
9696
.iter()
97-
.any(|l| l.attrib.contains(LuaTypeAttribute::Exact))
97+
.any(|l| l.flag.contains(LuaTypeFlag::Exact))
9898
}
9999

100100
pub fn is_partial(&self) -> bool {
101101
self.locations
102102
.iter()
103-
.any(|l| l.attrib.contains(LuaTypeAttribute::Partial))
103+
.any(|l| l.flag.contains(LuaTypeFlag::Partial))
104104
}
105105

106106
pub fn is_enum_key(&self) -> bool {
107107
self.locations
108108
.iter()
109-
.any(|l| l.attrib.contains(LuaTypeAttribute::Key))
109+
.any(|l| l.flag.contains(LuaTypeFlag::Key))
110110
}
111111

112112
pub fn get_id(&self) -> LuaTypeDeclId {
@@ -321,7 +321,7 @@ impl<'de> Deserialize<'de> for LuaTypeDeclId {
321321
pub struct LuaDeclLocation {
322322
pub file_id: FileId,
323323
pub range: TextRange,
324-
pub attrib: FlagSet<LuaTypeAttribute>,
324+
pub flag: FlagSet<LuaTypeFlag>,
325325
}
326326

327327
#[derive(Debug, Clone, Hash, PartialEq, Eq)]

crates/emmylua_code_analysis/src/diagnostic/checker/duplicate_type.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use emmylua_parser::{
22
LuaAstNode, LuaAstToken, LuaDocTag, LuaDocTagAlias, LuaDocTagClass, LuaDocTagEnum,
33
};
44

5-
use crate::{DiagnosticCode, LuaTypeAttribute, SemanticModel};
5+
use crate::{DiagnosticCode, LuaTypeFlag, SemanticModel};
66

77
use super::{Checker, DiagnosticContext};
88

@@ -45,13 +45,13 @@ fn check_duplicate_class(context: &mut DiagnosticContext, class_tag: LuaDocTagCl
4545
let mut partial_times = 0;
4646
let mut constructor_times = 0;
4747
for location in locations {
48-
let attrib = location.attrib;
49-
if attrib.contains(LuaTypeAttribute::Meta) {
48+
let flag = location.flag;
49+
if flag.contains(LuaTypeFlag::Meta) {
5050
continue;
5151
}
52-
if attrib.contains(LuaTypeAttribute::Partial) {
52+
if flag.contains(LuaTypeFlag::Partial) {
5353
partial_times += 1;
54-
} else if attrib.contains(LuaTypeAttribute::Constructor) {
54+
} else if flag.contains(LuaTypeFlag::Constructor) {
5555
constructor_times += 1;
5656
} else {
5757
type_times += 1;
@@ -104,11 +104,11 @@ fn check_duplicate_enum(context: &mut DiagnosticContext, enum_tag: LuaDocTagEnum
104104
let mut type_times = 0;
105105
let mut partial_times = 0;
106106
for location in locations {
107-
let attrib = location.attrib;
108-
if attrib.contains(LuaTypeAttribute::Meta) {
107+
let flag = location.flag;
108+
if flag.contains(LuaTypeFlag::Meta) {
109109
continue;
110110
}
111-
if attrib.contains(LuaTypeAttribute::Partial) {
111+
if flag.contains(LuaTypeFlag::Partial) {
112112
partial_times += 1;
113113
} else {
114114
type_times += 1;
@@ -148,8 +148,8 @@ fn check_duplicate_alias(context: &mut DiagnosticContext, alias_tag: LuaDocTagAl
148148
if locations.len() > 1 {
149149
let mut type_times = 0;
150150
for location in locations {
151-
let attrib = location.attrib;
152-
if !attrib.contains(LuaTypeAttribute::Meta) {
151+
let flag = location.flag;
152+
if !flag.contains(LuaTypeFlag::Meta) {
153153
type_times += 1;
154154
}
155155
}

0 commit comments

Comments
 (0)