mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-30 19:49:36 +00:00 
			
		
		
		
	Render layout and other extra informations on hovering Self
				
					
				
			This commit is contained in:
		
							parent
							
								
									32fa60f3a6
								
							
						
					
					
						commit
						ecc1ff8f33
					
				
					 3 changed files with 73 additions and 7 deletions
				
			
		|  | @ -18,7 +18,11 @@ use ide_db::{ | ||||||
| }; | }; | ||||||
| use itertools::{Itertools, multizip}; | use itertools::{Itertools, multizip}; | ||||||
| use span::Edition; | use span::Edition; | ||||||
| use syntax::{AstNode, SyntaxKind::*, SyntaxNode, T, ast}; | use syntax::{ | ||||||
|  |     AstNode, | ||||||
|  |     SyntaxKind::{self, *}, | ||||||
|  |     SyntaxNode, T, ast, | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     FileId, FilePosition, NavigationTarget, RangeInfo, Runnable, TryToNav, |     FileId, FilePosition, NavigationTarget, RangeInfo, Runnable, TryToNav, | ||||||
|  | @ -274,11 +278,13 @@ fn hover_offset( | ||||||
|                         } |                         } | ||||||
| 
 | 
 | ||||||
|                         class => { |                         class => { | ||||||
|                             let is_def = matches!(class, IdentClass::NameClass(_)); |                             let render_extras = matches!(class, IdentClass::NameClass(_)) | ||||||
|  |                                 // Render extra information for `Self` keyword as well
 | ||||||
|  |                                 || ast::NameRef::cast(node.clone()).is_some_and(|name_ref| name_ref.token_kind() == SyntaxKind::SELF_TYPE_KW); | ||||||
|                             multizip(( |                             multizip(( | ||||||
|                                 class.definitions(), |                                 class.definitions(), | ||||||
|                                 iter::repeat(None), |                                 iter::repeat(None), | ||||||
|                                 iter::repeat(is_def), |                                 iter::repeat(render_extras), | ||||||
|                                 iter::repeat(node), |                                 iter::repeat(node), | ||||||
|                             )) |                             )) | ||||||
|                             .collect::<Vec<_>>() |                             .collect::<Vec<_>>() | ||||||
|  | @ -422,7 +428,7 @@ pub(crate) fn hover_for_definition( | ||||||
|     subst: Option<GenericSubstitution>, |     subst: Option<GenericSubstitution>, | ||||||
|     scope_node: &SyntaxNode, |     scope_node: &SyntaxNode, | ||||||
|     macro_arm: Option<u32>, |     macro_arm: Option<u32>, | ||||||
|     hovered_definition: bool, |     render_extras: bool, | ||||||
|     config: &HoverConfig, |     config: &HoverConfig, | ||||||
|     edition: Edition, |     edition: Edition, | ||||||
|     display_target: DisplayTarget, |     display_target: DisplayTarget, | ||||||
|  | @ -456,7 +462,7 @@ pub(crate) fn hover_for_definition( | ||||||
|         famous_defs.as_ref(), |         famous_defs.as_ref(), | ||||||
|         ¬able_traits, |         ¬able_traits, | ||||||
|         macro_arm, |         macro_arm, | ||||||
|         hovered_definition, |         render_extras, | ||||||
|         subst_types.as_ref(), |         subst_types.as_ref(), | ||||||
|         config, |         config, | ||||||
|         edition, |         edition, | ||||||
|  |  | ||||||
|  | @ -477,7 +477,7 @@ pub(super) fn definition( | ||||||
|     famous_defs: Option<&FamousDefs<'_, '_>>, |     famous_defs: Option<&FamousDefs<'_, '_>>, | ||||||
|     notable_traits: &[(Trait, Vec<(Option<Type>, Name)>)], |     notable_traits: &[(Trait, Vec<(Option<Type>, Name)>)], | ||||||
|     macro_arm: Option<u32>, |     macro_arm: Option<u32>, | ||||||
|     hovered_definition: bool, |     render_extras: bool, | ||||||
|     subst_types: Option<&Vec<(Symbol, Type)>>, |     subst_types: Option<&Vec<(Symbol, Type)>>, | ||||||
|     config: &HoverConfig, |     config: &HoverConfig, | ||||||
|     edition: Edition, |     edition: Edition, | ||||||
|  | @ -640,6 +640,12 @@ pub(super) fn definition( | ||||||
|         Definition::Local(it) => { |         Definition::Local(it) => { | ||||||
|             render_memory_layout(config.memory_layout, || it.ty(db).layout(db), |_| None, |_| None) |             render_memory_layout(config.memory_layout, || it.ty(db).layout(db), |_| None, |_| None) | ||||||
|         } |         } | ||||||
|  |         Definition::SelfType(it) => render_memory_layout( | ||||||
|  |             config.memory_layout, | ||||||
|  |             || it.self_ty(db).layout(db), | ||||||
|  |             |_| None, | ||||||
|  |             |_| None, | ||||||
|  |         ), | ||||||
|         _ => None, |         _ => None, | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  | @ -741,7 +747,7 @@ pub(super) fn definition( | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     let mut extra = String::new(); |     let mut extra = String::new(); | ||||||
|     if hovered_definition { |     if render_extras { | ||||||
|         if let Some(notable_traits) = |         if let Some(notable_traits) = | ||||||
|             render_notable_trait(db, notable_traits, edition, display_target) |             render_notable_trait(db, notable_traits, edition, display_target) | ||||||
|         { |         { | ||||||
|  |  | ||||||
|  | @ -2089,6 +2089,10 @@ impl Thing { | ||||||
|                 x: u32, |                 x: u32, | ||||||
|             } |             } | ||||||
|             ``` |             ``` | ||||||
|  | 
 | ||||||
|  |             --- | ||||||
|  | 
 | ||||||
|  |             size = 4, align = 4 | ||||||
|         "#]],
 |         "#]],
 | ||||||
|     ); |     ); | ||||||
|     check_hover_fields_limit( |     check_hover_fields_limit( | ||||||
|  | @ -2109,6 +2113,10 @@ impl Thing { | ||||||
|             ```rust |             ```rust | ||||||
|             struct Thing |             struct Thing | ||||||
|             ``` |             ``` | ||||||
|  | 
 | ||||||
|  |             --- | ||||||
|  | 
 | ||||||
|  |             size = 4, align = 4 | ||||||
|         "#]],
 |         "#]],
 | ||||||
|     ); |     ); | ||||||
|     check( |     check( | ||||||
|  | @ -2130,6 +2138,10 @@ impl Thing { | ||||||
|                 x: u32, |                 x: u32, | ||||||
|             } |             } | ||||||
|             ``` |             ``` | ||||||
|  | 
 | ||||||
|  |             --- | ||||||
|  | 
 | ||||||
|  |             size = 4, align = 4 | ||||||
|         "#]],
 |         "#]],
 | ||||||
|     ); |     ); | ||||||
|     check( |     check( | ||||||
|  | @ -2151,6 +2163,10 @@ impl Thing { | ||||||
|                 A, |                 A, | ||||||
|             } |             } | ||||||
|             ``` |             ``` | ||||||
|  | 
 | ||||||
|  |             --- | ||||||
|  | 
 | ||||||
|  |             size = 0, align = 1 | ||||||
|         "#]],
 |         "#]],
 | ||||||
|     ); |     ); | ||||||
|     check( |     check( | ||||||
|  | @ -2172,6 +2188,10 @@ impl Thing { | ||||||
|                 A, |                 A, | ||||||
|             } |             } | ||||||
|             ``` |             ``` | ||||||
|  | 
 | ||||||
|  |             --- | ||||||
|  | 
 | ||||||
|  |             size = 0, align = 1 | ||||||
|         "#]],
 |         "#]],
 | ||||||
|     ); |     ); | ||||||
|     check( |     check( | ||||||
|  | @ -2190,6 +2210,10 @@ impl usize { | ||||||
|             ```rust |             ```rust | ||||||
|             usize |             usize | ||||||
|             ``` |             ``` | ||||||
|  | 
 | ||||||
|  |             --- | ||||||
|  | 
 | ||||||
|  |             size = 8, align = 8 | ||||||
|         "#]],
 |         "#]],
 | ||||||
|     ); |     ); | ||||||
|     check( |     check( | ||||||
|  | @ -2208,6 +2232,36 @@ impl fn() -> usize { | ||||||
|             ```rust |             ```rust | ||||||
|             fn() -> usize |             fn() -> usize | ||||||
|             ``` |             ``` | ||||||
|  | 
 | ||||||
|  |             --- | ||||||
|  | 
 | ||||||
|  |             size = 8, align = 8, niches = 1 | ||||||
|  |         "#]],
 | ||||||
|  |     ); | ||||||
|  |     check( | ||||||
|  |         r#" | ||||||
|  | pub struct Foo | ||||||
|  | where | ||||||
|  |     Self$0:; | ||||||
|  | "#,
 | ||||||
|  |         expect![[r#" | ||||||
|  |             *Self* | ||||||
|  | 
 | ||||||
|  |             ```rust | ||||||
|  |             ra_test_fixture | ||||||
|  |             ``` | ||||||
|  | 
 | ||||||
|  |             ```rust | ||||||
|  |             pub struct Foo | ||||||
|  |             ``` | ||||||
|  | 
 | ||||||
|  |             --- | ||||||
|  | 
 | ||||||
|  |             size = 0, align = 1 | ||||||
|  | 
 | ||||||
|  |             --- | ||||||
|  | 
 | ||||||
|  |             does not contain types with destructors (drop glue); doesn't have a destructor | ||||||
|         "#]],
 |         "#]],
 | ||||||
|     ); |     ); | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Shoyu Vanilla
						Shoyu Vanilla