Skip to content

Commit 2984075

Browse files
committed
optimize hover and fix some bug
1 parent b4ec3e1 commit 2984075

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ pub fn analyze_return(analyzer: &mut DocAnalyzer, tag: LuaDocTagReturn) -> Optio
167167
} else {
168168
None
169169
};
170+
170171
if let Some(closure) = find_owner_closure(analyzer) {
172+
let signature_id = LuaSignatureId::new(analyzer.file_id, &closure);
171173
let returns = tag.get_type_and_name_list();
172174
for (doc_type, name_token) in returns {
173175
let name = if let Some(name) = name_token {
@@ -182,8 +184,11 @@ pub fn analyze_return(analyzer: &mut DocAnalyzer, tag: LuaDocTagReturn) -> Optio
182184
type_ref,
183185
description: description.clone(),
184186
};
185-
let id = LuaSignatureId::new(analyzer.file_id, &closure);
186-
let signature = analyzer.db.get_signature_index_mut().get_or_create(id);
187+
188+
let signature = analyzer
189+
.db
190+
.get_signature_index_mut()
191+
.get_or_create(signature_id);
187192
signature.return_docs.push(return_info);
188193
}
189194
}

crates/code_analysis/src/compilation/analyzer/lua/stats.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ pub fn analyze_local_stat(analyzer: &mut LuaAnalyzer, local_stat: LuaLocalStat)
2727
let expr = expr.unwrap();
2828
let expr_type = analyzer.infer_expr(expr);
2929
match expr_type {
30-
Some(expr_type) => {
30+
Some(mut expr_type) => {
31+
if let LuaType::MuliReturn(multi) = expr_type {
32+
expr_type = multi.get_type(0)?.clone();
33+
}
34+
3135
let decl_id = LuaDeclId::new(analyzer.file_id, position);
3236
merge_decl_expr_type(analyzer.db, decl_id, expr_type);
3337
}

crates/code_analysis/src/db_index/type/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl LuaType {
264264
}
265265

266266
pub fn is_optional(&self) -> bool {
267-
matches!(self, LuaType::Nil | LuaType::Nullable(_) | LuaType::Any)
267+
matches!(self, LuaType::Nil | LuaType::Nullable(_))
268268
}
269269

270270
pub fn is_tuple(&self) -> bool {

crates/code_analysis/src/diagnostic/checker/missing_parameter.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ fn check_call_expr(
5959
}
6060

6161
let typ = param_info.1.clone();
62-
if typ.is_none() || !typ.unwrap().is_optional() {
62+
if typ.is_none() {
6363
miss_parameter_info.push(t!("missing parameter: %{name}", name = param_info.0));
64+
} else if let Some(typ) = typ {
65+
if !typ.is_any() && !typ.is_optional() {
66+
miss_parameter_info
67+
.push(t!("missing parameter: %{name}", name = param_info.0,));
68+
}
6469
}
6570
}
6671

crates/emmylua_ls/src/handlers/hover/build_hover.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,7 @@ fn add_signature_description(
191191
}
192192
s.push_str("\n");
193193
}
194-
195-
for return_info in &signature.return_docs {
196-
s.push_str("@return ");
197-
if let Some(name) = &return_info.name {
198-
s.push_str(&format!("`{}`", name));
199-
}
200-
if let Some(description) = &return_info.description {
201-
s.push_str(&format!(" - {}", description));
202-
}
203-
s.push_str("\n");
204-
}
205-
194+
206195
if !s.is_empty() {
207196
marked_strings.push(MarkedString::from_markdown(s));
208197
}

0 commit comments

Comments
 (0)