@@ -8,7 +8,6 @@ use crate::semantic_index::place::ScopeId;
88use crate :: semantic_index:: {
99 attribute_scopes, global_scope, imported_modules, place_table, semantic_index, use_def_map,
1010} ;
11- use crate :: types:: call:: Binding ;
1211use crate :: types:: call:: CallArguments ;
1312use crate :: types:: signatures:: Signature ;
1413use crate :: types:: { ClassBase , ClassLiteral , KnownClass , KnownInstanceType , Type } ;
@@ -397,36 +396,6 @@ pub struct CallSignatureDetails<'db> {
397396 pub argument_to_parameter_mapping : Box < [ Option < usize > ] > ,
398397}
399398
400- /// Extract signature details from a callable type.
401- fn extract_signature_details_from_callable < ' db > (
402- db : & ' db dyn Db ,
403- callable : crate :: types:: CallableType < ' db > ,
404- arguments : & ast:: Arguments ,
405- ) -> Vec < CallSignatureDetails < ' db > > {
406- callable
407- . signatures ( db)
408- . iter ( )
409- . map ( |signature| {
410- let display_details = signature. display ( db) . to_string_parts ( ) ;
411- let parameter_label_offsets = display_details. parameter_ranges . clone ( ) ;
412-
413- // Extract parameter names from the signature
414- let parameter_names = display_details. parameter_names . clone ( ) ;
415-
416- CallSignatureDetails {
417- signature : signature. clone ( ) ,
418- label : display_details. label ,
419- parameter_label_offsets,
420- parameter_names,
421- definition : signature. definition ( ) ,
422- argument_to_parameter_mapping : create_argument_mapping (
423- callable, signature, arguments,
424- ) ,
425- }
426- } )
427- . collect ( )
428- }
429-
430399/// Extract signature details from a function call expression.
431400/// This function analyzes the callable being invoked and returns zero or more
432401/// `CallSignatureDetails` objects, each representing one possible signature
@@ -441,54 +410,31 @@ pub fn call_signature_details<'db>(
441410
442411 // Use into_callable to handle all the complex type conversions
443412 if let Some ( callable_type) = func_type. into_callable ( db) {
444- match callable_type {
445- Type :: Callable ( callable) => {
446- extract_signature_details_from_callable ( db, callable, & call_expr. arguments )
447- }
448- Type :: Union ( union) => {
449- // Handle union of callable types by collecting signatures from all callable members
450- let mut all_signatures = Vec :: new ( ) ;
451- for element in union. elements ( db) {
452- if let Some ( Type :: Callable ( callable) ) = element. into_callable ( db) {
453- all_signatures. extend ( extract_signature_details_from_callable (
454- db,
455- callable,
456- & call_expr. arguments ,
457- ) ) ;
458- }
413+ let call_arguments = CallArguments :: from_arguments ( & call_expr. arguments ) ;
414+ let bindings = callable_type. bindings ( db) . match_parameters ( & call_arguments) ;
415+
416+ // Extract signature details from all callable bindings
417+ bindings
418+ . into_iter ( )
419+ . flat_map ( std:: iter:: IntoIterator :: into_iter)
420+ . map ( |binding| {
421+ let signature = & binding. signature ;
422+ let display_details = signature. display ( db) . to_string_parts ( ) ;
423+ let parameter_label_offsets = display_details. parameter_ranges . clone ( ) ;
424+ let parameter_names = display_details. parameter_names . clone ( ) ;
425+
426+ CallSignatureDetails {
427+ signature : signature. clone ( ) ,
428+ label : display_details. label ,
429+ parameter_label_offsets,
430+ parameter_names,
431+ definition : signature. definition ( ) ,
432+ argument_to_parameter_mapping : binding. argument_to_parameter_mapping ( ) ,
459433 }
460- all_signatures
461- }
462- _ => {
463- // This shouldn't happen since into_callable should return a Callable type,
464- // but handle it gracefully just in case
465- vec ! [ ]
466- }
467- }
434+ } )
435+ . collect ( )
468436 } else {
469437 // Type is not callable, return empty signatures
470438 vec ! [ ]
471439 }
472440}
473-
474- /// Create a mapping from argument indices to parameter indices.
475- fn create_argument_mapping (
476- callable : crate :: types:: CallableType < ' _ > ,
477- signature : & Signature < ' _ > ,
478- arguments : & ast:: Arguments ,
479- ) -> Box < [ Option < usize > ] > {
480- let call_arguments = CallArguments :: from_arguments ( arguments) ;
481-
482- let mut argument_forms = vec ! [ None ; call_arguments. len( ) ] ;
483- let mut conflicting_forms = vec ! [ false ; call_arguments. len( ) ] ;
484-
485- // Create a binding using the unified matching routine
486- let callable_type = Type :: Callable ( callable) ;
487- let mut binding = Binding :: single ( callable_type, signature. clone ( ) ) ;
488-
489- // Match the arguments to parameters
490- binding. match_parameters ( & call_arguments, & mut argument_forms, & mut conflicting_forms) ;
491-
492- // Get the argument mapping from the binding
493- binding. argument_to_parameter_mapping ( )
494- }
0 commit comments