mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-30 19:49:36 +00:00 
			
		
		
		
	Merge pull request #18483 from tareknaser/syntax_factory_introduce_named_generic
Migrate `introduce_named_generic` Assist to Use `SyntaxFactory`
This commit is contained in:
		
						commit
						2fd06545a6
					
				
					 4 changed files with 122 additions and 26 deletions
				
			
		|  | @ -2,7 +2,7 @@ | |||
| use itertools::Itertools; | ||||
| 
 | ||||
| use crate::{ | ||||
|     ast::{self, make, HasName}, | ||||
|     ast::{self, make, HasName, HasTypeBounds}, | ||||
|     syntax_editor::SyntaxMappingBuilder, | ||||
|     AstNode, | ||||
| }; | ||||
|  | @ -14,6 +14,32 @@ impl SyntaxFactory { | |||
|         make::name(name).clone_for_update() | ||||
|     } | ||||
| 
 | ||||
|     pub fn ty(&self, text: &str) -> ast::Type { | ||||
|         make::ty(text).clone_for_update() | ||||
|     } | ||||
| 
 | ||||
|     pub fn type_param( | ||||
|         &self, | ||||
|         name: ast::Name, | ||||
|         bounds: Option<ast::TypeBoundList>, | ||||
|     ) -> ast::TypeParam { | ||||
|         let ast = make::type_param(name.clone(), bounds.clone()).clone_for_update(); | ||||
| 
 | ||||
|         if let Some(mut mapping) = self.mappings() { | ||||
|             let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone()); | ||||
|             builder.map_node(name.syntax().clone(), ast.name().unwrap().syntax().clone()); | ||||
|             if let Some(input) = bounds { | ||||
|                 builder.map_node( | ||||
|                     input.syntax().clone(), | ||||
|                     ast.type_bound_list().unwrap().syntax().clone(), | ||||
|                 ); | ||||
|             } | ||||
|             builder.finish(&mut mapping); | ||||
|         } | ||||
| 
 | ||||
|         ast | ||||
|     } | ||||
| 
 | ||||
|     pub fn ident_pat(&self, ref_: bool, mut_: bool, name: ast::Name) -> ast::IdentPat { | ||||
|         let ast = make::ident_pat(ref_, mut_, name.clone()).clone_for_update(); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 David Barsky
						David Barsky