Skip to content

Commit 3c44a52

Browse files
committed
feat(struct): add basic handle for array
1 parent 673b5ba commit 3c44a52

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

plugins/coco_struct_analysis/src/coco_struct.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub struct MemberInfo {
55
pub name: String,
66
pub access: String,
77
pub data_type: String,
8+
pub pure_data_type: String,
89
}
910

1011
impl MemberInfo {
@@ -13,6 +14,7 @@ impl MemberInfo {
1314
name: name.to_string(),
1415
access: access.to_string(),
1516
data_type,
17+
pure_data_type: "".to_string(),
1618
}
1719
}
1820
}
@@ -22,6 +24,7 @@ pub struct MethodInfo {
2224
pub name: String,
2325
pub access: String,
2426
pub return_type: String,
27+
pub pure_return_type: String,
2528
}
2629

2730
impl MethodInfo {
@@ -30,6 +33,7 @@ impl MethodInfo {
3033
name: name.to_string(),
3134
access: access.to_string(),
3235
return_type,
36+
pure_return_type: "".to_string(),
3337
}
3438
}
3539
}

plugins/coco_struct_analysis/src/ctags_parser.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ lazy_static! {
6262
static ref RUST_TYPE: Regex = Regex::new(
6363
r"/\^([ ]*)([A-Za-z0-9_.]+)(\t|\s)([A-Za-z0-9_.]+)\s*:(\t|\s)*(?P<datatype>[A-Za-z0-9_.<>]+)"
6464
).unwrap();
65+
static ref PURE_RUST_TYPE: Regex = Regex::new(
66+
r"((Vec|Option|<)*)(?P<datatype>[A-Za-z0-9_]+)>*"
67+
).unwrap();
6568
static ref GO_TYPE: Regex =
6669
Regex::new(r"(?x)/\^([\s]*)
6770
([A-Za-z0-9_.]+)
@@ -183,6 +186,7 @@ impl CtagsParser {
183186
clazz.lang = language.to_string();
184187

185188
let mut data_type = "".to_string();
189+
let mut pure_data_type = "".to_string();
186190
match language {
187191
"Java" | "C#" | "C++" => {
188192
let without_keywords = CtagsParser::remove_keywords(line.to_string());
@@ -193,6 +197,10 @@ impl CtagsParser {
193197
"Rust" => {
194198
if let Some(capts) = RUST_TYPE.captures(line) {
195199
data_type = (&capts["datatype"]).to_string();
200+
201+
if let Some(ty) = PURE_RUST_TYPE.captures(data_type.as_str()) {
202+
pure_data_type = (&ty["datatype"]).to_string();
203+
}
196204
}
197205
}
198206
"Go" => {
@@ -204,10 +212,16 @@ impl CtagsParser {
204212
}
205213

206214
if tag_type.eq("member") || tag_type.eq("field") {
207-
let member = MemberInfo::new(name, access, data_type);
215+
let mut member = MemberInfo::new(name, access, data_type);
216+
if !pure_data_type.is_empty() {
217+
member.pure_data_type = pure_data_type;
218+
}
208219
clazz.members.push(member);
209220
} else if tag_type.eq("method") || tag_type.eq("function") {
210-
let method = MethodInfo::new(name, access, data_type);
221+
let mut method = MethodInfo::new(name, access, data_type);
222+
if !pure_data_type.is_empty() {
223+
method.pure_return_type = pure_data_type;
224+
}
211225
clazz.methods.push(method);
212226
}
213227
}
@@ -365,6 +379,7 @@ name src/coco_struct.rs /^ pub name: String,$/;\" field line:22 language:Rust
365379
assert_eq!(7, classes[0].members.len());
366380
assert_eq!("file", classes[0].members[0].name);
367381
assert_eq!("parents", classes[0].members[6].name);
382+
assert_eq!("String", classes[0].members[6].pure_data_type);
368383
}
369384

370385
#[test]

0 commit comments

Comments
 (0)