@@ -4,7 +4,9 @@ use emmylua_parser::{LuaAstNode, LuaSyntaxId, LuaSyntaxNode, LuaTableExpr};
4
4
use smol_str:: SmolStr ;
5
5
6
6
use crate :: {
7
- db_index:: { DbIndex , LuaGenericType , LuaType } , semantic:: { infer_expr, LuaInferConfig } , LuaFunctionType , LuaUnionType
7
+ db_index:: { DbIndex , LuaGenericType , LuaType } ,
8
+ semantic:: { infer_expr, LuaInferConfig } ,
9
+ LuaFunctionType , LuaUnionType ,
8
10
} ;
9
11
10
12
#[ allow( unused) ]
@@ -178,35 +180,46 @@ fn func_tpl_pattern_match(
178
180
) -> Option < ( ) > {
179
181
match target {
180
182
LuaType :: DocFunction ( target_doc_func) => {
181
- for i in 0 ..doc_func. get_params ( ) . len ( ) {
182
- let param_type = & doc_func. get_params ( ) [ i] . clone ( ) . 1 ?;
183
- let target_param_type = & target_doc_func. get_params ( ) . get ( i) ?. clone ( ) . 1 ?;
184
- tpl_pattern_match ( db, config, root, param_type, target_param_type, result) ;
183
+ let params = doc_func. get_params ( ) ;
184
+ let target_params = target_doc_func. get_params ( ) ;
185
+ for ( i, param_tuple) in params. iter ( ) . enumerate ( ) {
186
+ let target_param_tuple = target_params. get ( i) ?;
187
+ if param_tuple. 1 . is_some ( ) && target_param_tuple. 1 . is_some ( ) {
188
+ let param_type = param_tuple. 1 . clone ( ) ?;
189
+ let target_param_type = target_param_tuple. 1 . clone ( ) ?;
190
+ tpl_pattern_match ( db, config, root, & param_type, & target_param_type, result) ;
191
+ }
185
192
}
186
193
187
- for i in 0 ..doc_func. get_ret ( ) . len ( ) {
188
- let ret_type = & doc_func. get_ret ( ) [ i] ;
189
- let target_ret_type = & target_doc_func. get_ret ( ) . get ( i) ?;
190
- tpl_pattern_match ( db, config, root, ret_type, target_ret_type, result) ;
194
+ let rets = doc_func. get_ret ( ) ;
195
+ for ( i, ret_type) in rets. iter ( ) . enumerate ( ) {
196
+ if let Some ( target_ret_type) = & target_doc_func. get_ret ( ) . get ( i) {
197
+ tpl_pattern_match ( db, config, root, ret_type, target_ret_type, result) ;
198
+ }
191
199
}
192
200
}
193
201
LuaType :: Signature ( signature_id) => {
202
+ let params = doc_func. get_params ( ) ;
194
203
let signature = db. get_signature_index ( ) . get ( & signature_id) ?;
195
204
196
- for i in 0 ..doc_func. get_params ( ) . len ( ) {
197
- let param_type = & doc_func. get_params ( ) [ i] . clone ( ) . 1 ?;
198
- let target_param_type = & signature. param_docs . get ( & i) ?. type_ref ;
199
- tpl_pattern_match ( db, config, root, param_type, target_param_type, result) ;
205
+ for ( i, param_tuple) in params. iter ( ) . enumerate ( ) {
206
+ let signature_param_info = signature. get_param_info_by_id ( i) ;
207
+ if param_tuple. 1 . is_some ( ) && signature_param_info. is_some ( ) {
208
+ let param_type = param_tuple. 1 . clone ( ) ?;
209
+ let target_param_type = & signature_param_info. unwrap ( ) . type_ref ;
210
+ tpl_pattern_match ( db, config, root, & param_type, target_param_type, result) ;
211
+ }
200
212
}
201
213
202
- for i in 0 ..doc_func. get_ret ( ) . len ( ) {
203
- let ret_type = & doc_func. get_ret ( ) [ i] ;
204
- let target_ret_type = & signature. return_docs . get ( i) ?. type_ref ;
205
- tpl_pattern_match ( db, config, root, ret_type, target_ret_type, result) ;
214
+ let rets = doc_func. get_ret ( ) ;
215
+ for ( i, ret_type) in rets. iter ( ) . enumerate ( ) {
216
+ if let Some ( signature_ret_info) = & signature. return_docs . get ( i) {
217
+ tpl_pattern_match ( db, config, root, ret_type, & signature_ret_info. type_ref , result) ;
218
+ }
206
219
}
207
220
}
208
221
_ => { }
209
222
}
210
223
211
224
Some ( ( ) )
212
- }
225
+ }
0 commit comments