@@ -21,6 +21,7 @@ use pyrefly_types::callable::Param;
2121use pyrefly_types:: callable:: ParamList ;
2222use pyrefly_types:: callable:: Params ;
2323use pyrefly_types:: callable:: Required ;
24+ use pyrefly_types:: display:: format_hover_code_snippet;
2425use pyrefly_types:: types:: BoundMethodType ;
2526use pyrefly_types:: types:: Forallable ;
2627use pyrefly_types:: types:: Type ;
@@ -162,13 +163,6 @@ impl HoverValue {
162163 || "" . to_owned ( ) ,
163164 |content| format ! ( "\n ---\n {}" , content. trim( ) ) ,
164165 ) ;
165- let mut kind_formatted = self . kind . map_or ( "" . to_owned ( ) , |kind| {
166- format ! ( "{} " , kind. display_for_hover( ) )
167- } ) ;
168- let name_formatted = self
169- . name
170- . as_ref ( )
171- . map_or ( "" . to_owned ( ) , |s| format ! ( "{s}: " ) ) ;
172166 let symbol_def_formatted = if self . show_go_to_links {
173167 HoverValue :: format_symbol_def_locations ( & self . type_ ) . unwrap_or ( "" . to_owned ( ) )
174168 } else {
@@ -178,35 +172,32 @@ impl HoverValue {
178172 . display
179173 . clone ( )
180174 . unwrap_or_else ( || self . type_ . as_hover_string ( ) ) ;
181-
182- let is_function = self . type_ . is_function_type ( ) ;
183- if is_function && kind_formatted . trim ( ) . is_empty ( ) {
184- kind_formatted = "(function) " . to_owned ( ) ;
185- }
186- let trimmed_type_display = type_display . trim_start ( ) ;
187- let needs_def_wrapper = trimmed_type_display . starts_with ( '(' ) ;
188- let ( heading , body ) = if is_function {
189- let function_name = self . name . clone ( ) . unwrap_or_else ( || "function" . to_owned ( ) ) ;
190- let heading = format ! ( "{}{} \n " , kind_formatted , function_name ) ;
191- let body = if needs_def_wrapper {
192- format ! ( "def {}{}: ..." , function_name , trimmed_type_display )
193- } else {
194- type_display
195- } ;
196- ( heading , body )
175+ let snippet = format_hover_code_snippet ( & self . type_ , self . name . as_deref ( ) , type_display ) ;
176+ let kind_formatted = self . kind . map_or_else (
177+ || {
178+ snippet
179+ . default_kind_label
180+ . map ( str :: to_owned )
181+ . unwrap_or_default ( )
182+ } ,
183+ |kind| format ! ( "{} " , kind . display_for_hover ( ) ) ,
184+ ) ;
185+ let name_formatted = self
186+ . name
187+ . as_ref ( )
188+ . map_or ( "" . to_owned ( ) , |s| format ! ( "{s}: " ) ) ;
189+ let heading = if let Some ( callable_heading ) = snippet . heading . as_ref ( ) {
190+ format ! ( "{}{} \n " , kind_formatted , callable_heading )
197191 } else {
198- (
199- format ! ( "{}{}" , kind_formatted, name_formatted) ,
200- type_display,
201- )
192+ format ! ( "{}{}" , kind_formatted, name_formatted)
202193 } ;
203194
204195 Hover {
205196 contents : HoverContents :: Markup ( MarkupContent {
206197 kind : MarkupKind :: Markdown ,
207198 value : format ! (
208199 "```python\n {}{}\n ```{}{}" ,
209- heading, body, docstring_formatted, symbol_def_formatted
200+ heading, snippet . body, docstring_formatted, symbol_def_formatted
210201 ) ,
211202 } ) ,
212203 range : None ,
0 commit comments