Skip to content

Commit e78c85d

Browse files
committed
fix: @type现在会绑定右侧的注释
1 parent cd46b18 commit e78c85d

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ use super::{
2525
};
2626

2727
pub fn analyze_type(analyzer: &mut DocAnalyzer, tag: LuaDocTagType) -> Option<()> {
28+
let description = if let Some(des) = tag.get_description() {
29+
Some(preprocess_description(&des.get_description_text(), None))
30+
} else {
31+
None
32+
};
33+
2834
let mut type_list = Vec::new();
2935
for lua_doc_type in tag.get_type_list() {
3036
let type_ref = infer_type(analyzer, lua_doc_type);
@@ -50,6 +56,17 @@ pub fn analyze_type(analyzer: &mut DocAnalyzer, tag: LuaDocTagType) -> Option<()
5056
.db
5157
.get_type_index_mut()
5258
.bind_type(decl_id.into(), LuaTypeCache::DocType(type_ref.clone()));
59+
60+
// bind description
61+
if let Some(ref desc) = description {
62+
if !desc.is_empty() {
63+
analyzer.db.get_property_index_mut().add_description(
64+
analyzer.file_id,
65+
LuaSemanticDeclId::LuaDecl(decl_id),
66+
desc.clone(),
67+
);
68+
}
69+
}
5370
}
5471
LuaVarExpr::IndexExpr(index_expr) => {
5572
let member_id =
@@ -58,6 +75,17 @@ pub fn analyze_type(analyzer: &mut DocAnalyzer, tag: LuaDocTagType) -> Option<()
5875
.db
5976
.get_type_index_mut()
6077
.bind_type(member_id.into(), LuaTypeCache::DocType(type_ref.clone()));
78+
79+
// bind description
80+
if let Some(ref desc) = description {
81+
if !desc.is_empty() {
82+
analyzer.db.get_property_index_mut().add_description(
83+
analyzer.file_id,
84+
LuaSemanticDeclId::Member(member_id),
85+
desc.clone(),
86+
);
87+
}
88+
}
6189
}
6290
}
6391
}
@@ -77,6 +105,17 @@ pub fn analyze_type(analyzer: &mut DocAnalyzer, tag: LuaDocTagType) -> Option<()
77105
.db
78106
.get_type_index_mut()
79107
.bind_type(decl_id.into(), LuaTypeCache::DocType(type_ref.clone()));
108+
109+
// bind description
110+
if let Some(ref desc) = description {
111+
if !desc.is_empty() {
112+
analyzer.db.get_property_index_mut().add_description(
113+
analyzer.file_id,
114+
LuaSemanticDeclId::LuaDecl(decl_id),
115+
desc.clone(),
116+
);
117+
}
118+
}
80119
}
81120
}
82121
LuaAst::LuaTableField(table_field) => {
@@ -87,6 +126,17 @@ pub fn analyze_type(analyzer: &mut DocAnalyzer, tag: LuaDocTagType) -> Option<()
87126
.db
88127
.get_type_index_mut()
89128
.bind_type(member_id.into(), LuaTypeCache::DocType(first_type.clone()));
129+
130+
// bind description
131+
if let Some(ref desc) = description {
132+
if !desc.is_empty() {
133+
analyzer.db.get_property_index_mut().add_description(
134+
analyzer.file_id,
135+
LuaSemanticDeclId::Member(member_id),
136+
desc.clone(),
137+
);
138+
}
139+
}
90140
}
91141
}
92142
_ => {}

crates/emmylua_ls/src/handlers/test/hover_test.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,22 @@ mod tests {
227227
},
228228
));
229229
}
230+
231+
#[test]
232+
fn test_type_desc() {
233+
let mut ws = ProviderVirtualWorkspace::new();
234+
assert!(ws.check_hover(
235+
r#"
236+
local export = {
237+
---@type number? activeSub
238+
vvv = nil
239+
}
240+
241+
export.v<??>vv
242+
"#,
243+
VirtualHoverResult {
244+
value: "```lua\n(field) vvv: number?\n```\n\n---\n\nactiveSub".to_string(),
245+
},
246+
));
247+
}
230248
}

0 commit comments

Comments
 (0)