@@ -4,8 +4,8 @@ use emmylua_parser::{LuaAstNode, LuaIndexMemberExpr, LuaTableExpr, LuaVarExpr};
44
55use crate :: {
66 DbIndex , InferFailReason , InferGuard , InferGuardRef , LuaDocParamInfo , LuaDocReturnInfo ,
7- LuaFunctionType , LuaInferCache , LuaSignature , LuaType , SignatureReturnStatus , TypeOps ,
8- get_real_type, infer_call_expr_func, infer_expr, infer_table_should_be,
7+ LuaFunctionType , LuaInferCache , LuaMemberId , LuaSignature , LuaType , SignatureReturnStatus ,
8+ TypeOps , get_real_type, infer_call_expr_func, infer_expr, infer_table_should_be,
99} ;
1010
1111use super :: {
@@ -205,7 +205,7 @@ pub fn try_resolve_closure_parent_params(
205205 if !signature. param_docs . is_empty ( ) {
206206 return Ok ( ( ) ) ;
207207 }
208- let self_type;
208+ let mut self_type = None ;
209209 let member_type = match & closure_params. parent_ast {
210210 UnResolveParentAst :: LuaFuncStat ( func_stat) => {
211211 let func_name = func_stat. get_func_name ( ) . ok_or ( InferFailReason :: None ) ?;
@@ -227,19 +227,36 @@ pub fn try_resolve_closure_parent_params(
227227 }
228228 }
229229 UnResolveParentAst :: LuaTableField ( table_field) => {
230- let parnet_table_expr = table_field
231- . get_parent :: < LuaTableExpr > ( )
232- . ok_or ( InferFailReason :: None ) ?;
233- let parent_table_type = infer_table_should_be ( db, cache, parnet_table_expr) ?;
234- self_type = Some ( parent_table_type. clone ( ) ) ;
235- find_best_function_type (
236- db,
237- cache,
238- & parent_table_type,
239- LuaIndexMemberExpr :: TableField ( table_field. clone ( ) ) ,
240- signature,
241- )
242- . ok_or ( InferFailReason :: None ) ?
230+ let parent_member_type = if let Some ( parent_table_expr) =
231+ table_field. get_parent :: < LuaTableExpr > ( )
232+ {
233+ if let Ok ( parent_table_type) = infer_table_should_be ( db, cache, parent_table_expr) {
234+ self_type = Some ( parent_table_type. clone ( ) ) ;
235+ find_best_function_type (
236+ db,
237+ cache,
238+ & parent_table_type,
239+ LuaIndexMemberExpr :: TableField ( table_field. clone ( ) ) ,
240+ signature,
241+ )
242+ } else {
243+ None
244+ }
245+ } else {
246+ None
247+ } ;
248+
249+ if let Some ( parent_member_type) = parent_member_type {
250+ parent_member_type
251+ } else {
252+ let member_id =
253+ LuaMemberId :: new ( table_field. get_syntax_id ( ) , closure_params. file_id ) ;
254+ db. get_type_index ( )
255+ . get_type_cache ( & member_id. into ( ) )
256+ . filter ( |type_cache| type_cache. is_doc ( ) )
257+ . map ( |type_cache| type_cache. as_type ( ) . clone ( ) )
258+ . ok_or ( InferFailReason :: None ) ?
259+ }
243260 }
244261 UnResolveParentAst :: LuaAssignStat ( assign) => {
245262 let ( vars, exprs) = assign. get_var_and_expr_list ( ) ;
0 commit comments