@@ -33,6 +33,7 @@ use pyrefly_types::types::Type;
3333use pyrefly_util:: lined_buffer:: LineNumber ;
3434use pyrefly_util:: visit:: Visit ;
3535use ruff_python_ast:: AnyNodeRef ;
36+ use ruff_python_ast:: Identifier ;
3637use ruff_python_ast:: Stmt ;
3738use ruff_python_ast:: name:: Name ;
3839use ruff_text_size:: Ranged ;
@@ -431,6 +432,16 @@ fn parameter_definition_documentation(
431432 docs. get ( key) . cloned ( ) . map ( |doc| ( key. to_owned ( ) , doc) )
432433}
433434
435+ fn keyword_argument_identifier (
436+ transaction : & Transaction < ' _ > ,
437+ handle : & Handle ,
438+ position : TextSize ,
439+ ) -> Option < Identifier > {
440+ let identifier = transaction. identifier_at ( handle, position) ?;
441+ matches ! ( identifier. context, IdentifierContext :: KeywordArgument ( _) )
442+ . then_some ( identifier. identifier )
443+ }
444+
434445/// Check if the cursor position is on the `in` keyword within a for loop or comprehension.
435446/// Returns Some(iterable_range) if found, None otherwise.
436447fn in_keyword_in_iteration_at (
@@ -549,13 +560,8 @@ pub fn get_hover(
549560 }
550561
551562 let fallback_name_from_type = fallback_hover_name_from_type ( & type_) ;
552- let ( kind, name, docstring_range, module) = if let Some ( FindDefinitionItemWithDocstring {
553- metadata,
554- definition_range : definition_location,
555- module,
556- docstring_range,
557- display_name,
558- } ) = transaction
563+ let keyword_argument_identifier = keyword_argument_identifier ( transaction, handle, position) ;
564+ let definition = transaction
559565 . find_definition (
560566 handle,
561567 position,
@@ -566,9 +572,22 @@ pub fn get_hover(
566572 )
567573 . map ( Vec1 :: into_vec)
568574 . unwrap_or_default ( )
569- // TODO: handle more than 1 definition
570575 . into_iter ( )
571576 . next ( )
577+ . filter ( |item| {
578+ keyword_argument_identifier
579+ . as_ref ( )
580+ . is_none_or ( |identifier| {
581+ item. module . code_at ( item. definition_range ) == identifier. id . as_str ( )
582+ } )
583+ } ) ;
584+ let ( kind, name, docstring_range, module) = if let Some ( FindDefinitionItemWithDocstring {
585+ metadata,
586+ definition_range : definition_location,
587+ module,
588+ docstring_range,
589+ display_name,
590+ } ) = definition
572591 {
573592 let kind = metadata. symbol_kind ( ) ;
574593 let name = {
0 commit comments