1- use std:: sync:: Arc ;
2-
3- use emmylua_parser:: LuaCallExpr ;
4-
51use crate :: {
6- infer_expr, instantiate_doc_function, instantiate_type, resolve_signature, DbIndex , InferGuard ,
7- LuaDocParamInfo , LuaFunctionType , LuaGenericType , LuaInferConfig , LuaOperatorMetaMethod ,
8- LuaSignatureId , LuaType , LuaTypeDeclId ,
2+ infer_call_expr_func, infer_expr, DbIndex , InferGuard , LuaDocParamInfo , LuaInferConfig , LuaType ,
93} ;
104
115use super :: UnResolveClosureParams ;
@@ -19,7 +13,7 @@ pub fn try_resolve_closure_params(
1913 let prefix_expr = call_expr. get_prefix_expr ( ) ?;
2014 let call_expr_type = infer_expr ( db, config, prefix_expr. into ( ) ) ?;
2115
22- let call_doc_func = infer_doc_func (
16+ let call_doc_func = infer_call_expr_func (
2317 db,
2418 config,
2519 call_expr,
@@ -42,7 +36,6 @@ pub fn try_resolve_closure_params(
4236 return Some ( true ) ;
4337 } ;
4438
45-
4639 let signature_params = & mut signature. param_docs ;
4740 for ( idx, ( name, type_ref) ) in expr_closure_params. iter ( ) . enumerate ( ) {
4841 if signature_params. contains_key ( & idx) {
@@ -62,160 +55,3 @@ pub fn try_resolve_closure_params(
6255
6356 Some ( true )
6457}
65-
66- fn infer_doc_func (
67- db : & DbIndex ,
68- config : & mut LuaInferConfig ,
69- call_expr : LuaCallExpr ,
70- call_expr_type : LuaType ,
71- infer_guard : & mut InferGuard ,
72- ) -> Option < Arc < LuaFunctionType > > {
73- match call_expr_type {
74- LuaType :: DocFunction ( func) => Some ( func) ,
75- LuaType :: Signature ( signature_id) => {
76- infer_signature_doc_function ( db, config, signature_id. clone ( ) , call_expr. clone ( ) )
77- }
78- LuaType :: Def ( type_def_id) => infer_type_doc_function (
79- db,
80- config,
81- type_def_id. clone ( ) ,
82- call_expr. clone ( ) ,
83- infer_guard,
84- ) ,
85- LuaType :: Ref ( type_ref_id) => infer_type_doc_function (
86- db,
87- config,
88- type_ref_id. clone ( ) ,
89- call_expr. clone ( ) ,
90- infer_guard,
91- ) ,
92- LuaType :: Generic ( generic) => {
93- infer_generic_type_doc_function ( db, config, & generic, call_expr. clone ( ) , infer_guard)
94- }
95- _ => return None ,
96- }
97- }
98-
99- fn infer_signature_doc_function (
100- db : & DbIndex ,
101- config : & mut LuaInferConfig ,
102- signature_id : LuaSignatureId ,
103- call_expr : LuaCallExpr ,
104- ) -> Option < Arc < LuaFunctionType > > {
105- let signature = db. get_signature_index ( ) . get ( & signature_id) ?;
106- let overloads = & signature. overloads ;
107- if overloads. is_empty ( ) {
108- let mut fake_doc_function = LuaFunctionType :: new (
109- false ,
110- signature. is_colon_define ,
111- signature. get_type_params ( ) ,
112- vec ! [ ] ,
113- ) ;
114- if signature. is_generic ( ) {
115- let instantiate_func = instantiate_doc_function (
116- db,
117- config,
118- & fake_doc_function,
119- call_expr,
120- signature. is_colon_define ,
121- ) ?;
122-
123- fake_doc_function = instantiate_func;
124- }
125-
126- Some ( fake_doc_function. into ( ) )
127- } else {
128- let mut new_overloads = signature. overloads . clone ( ) ;
129- let fake_doc_function = Arc :: new ( LuaFunctionType :: new (
130- false ,
131- signature. is_colon_define ,
132- signature. get_type_params ( ) ,
133- vec ! [ ] ,
134- ) ) ;
135- new_overloads. push ( fake_doc_function) ;
136-
137- let doc_func = resolve_signature (
138- db,
139- config,
140- new_overloads,
141- call_expr. clone ( ) ,
142- signature. is_colon_define ,
143- signature. is_generic ( ) ,
144- ) ?;
145-
146- Some ( doc_func)
147- }
148- }
149-
150- fn infer_type_doc_function (
151- db : & DbIndex ,
152- config : & mut LuaInferConfig ,
153- type_id : LuaTypeDeclId ,
154- call_expr : LuaCallExpr ,
155- infer_guard : & mut InferGuard ,
156- ) -> Option < Arc < LuaFunctionType > > {
157- infer_guard. check ( & type_id) ?;
158- let type_decl = db. get_type_index ( ) . get_type_decl ( & type_id) ?;
159- if type_decl. is_alias ( ) {
160- let alias_type = type_decl. get_alias_origin ( ) ?;
161- return infer_doc_func ( db, config, call_expr, alias_type. clone ( ) , infer_guard) ;
162- } else if type_decl. is_enum ( ) {
163- return None ;
164- }
165-
166- let operator_index = db. get_operator_index ( ) ;
167- let operator_map = operator_index. get_operators_by_type ( & type_id) ?;
168- let operator_ids = operator_map. get ( & LuaOperatorMetaMethod :: Call ) ?;
169- let mut overloads = Vec :: new ( ) ;
170- for overload_id in operator_ids {
171- let operator = operator_index. get_operator ( overload_id) ?;
172- let func = operator. get_call_operator_type ( ) ?;
173- match func {
174- LuaType :: DocFunction ( f) => {
175- overloads. push ( f. clone ( ) ) ;
176- }
177- _ => { }
178- }
179- }
180-
181- let doc_func = resolve_signature ( db, config, overloads, call_expr. clone ( ) , false , false ) ?;
182- Some ( doc_func)
183- }
184-
185- fn infer_generic_type_doc_function (
186- db : & DbIndex ,
187- config : & mut LuaInferConfig ,
188- generic : & LuaGenericType ,
189- call_expr : LuaCallExpr ,
190- infer_guard : & mut InferGuard ,
191- ) -> Option < Arc < LuaFunctionType > > {
192- let type_id = generic. get_base_type_id ( ) ;
193- infer_guard. check ( & type_id) ?;
194- let type_decl = db. get_type_index ( ) . get_type_decl ( & type_id) ?;
195- if type_decl. is_alias ( ) {
196- let alias_type = type_decl. get_alias_origin ( ) ?;
197- return infer_doc_func ( db, config, call_expr, alias_type. clone ( ) , infer_guard) ;
198- } else if type_decl. is_enum ( ) {
199- return None ;
200- }
201-
202- let generic_params = generic. get_params ( ) ;
203- let operator_index = db. get_operator_index ( ) ;
204- let operator_map = operator_index. get_operators_by_type ( & type_id) ?;
205- let operator_ids = operator_map. get ( & LuaOperatorMetaMethod :: Call ) ?;
206- let mut overloads = Vec :: new ( ) ;
207- for overload_id in operator_ids {
208- let operator = operator_index. get_operator ( overload_id) ?;
209- let func = operator. get_call_operator_type ( ) ?;
210- let new_f = instantiate_type ( db, func, generic_params) ;
211- match new_f {
212- LuaType :: DocFunction ( f) => {
213- overloads. push ( f. clone ( ) ) ;
214- }
215- _ => { }
216- }
217- }
218-
219- let doc_func = resolve_signature ( db, config, overloads, call_expr. clone ( ) , false , false ) ?;
220- Some ( doc_func)
221- }
0 commit comments