File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -207,25 +207,23 @@ fn get_syntactic_substs(impl_block: ast::ImplBlock) -> Option<Vec<ast::TypeRef>>
207
207
}
208
208
209
209
// FIXME: This should be a general utility (not even just for assists)
210
- fn substitute_type_params < N : AstNode > (
210
+ fn substitute_type_params < N : AstNode + Clone > (
211
211
db : & impl HirDatabase ,
212
212
node : hir:: InFile < N > ,
213
213
substs : & HashMap < hir:: TypeParam , ast:: TypeRef > ,
214
214
) -> N {
215
215
let type_param_replacements = node
216
- . value
217
- . syntax ( )
218
- . descendants ( )
219
- . filter_map ( ast:: TypeRef :: cast)
216
+ . clone ( )
217
+ . descendants :: < ast:: TypeRef > ( )
220
218
. filter_map ( |n| {
221
- let path = match & n {
219
+ let path = match & n. value {
222
220
ast:: TypeRef :: PathType ( path_type) => path_type. path ( ) ?,
223
221
_ => return None ,
224
222
} ;
225
- let analyzer = hir:: SourceAnalyzer :: new ( db, node . with_value ( n. syntax ( ) ) , None ) ;
223
+ let analyzer = hir:: SourceAnalyzer :: new ( db, n. syntax ( ) , None ) ;
226
224
let resolution = analyzer. resolve_path ( db, & path) ?;
227
225
match resolution {
228
- hir:: PathResolution :: TypeParam ( tp) => Some ( ( n, substs. get ( & tp) ?. clone ( ) ) ) ,
226
+ hir:: PathResolution :: TypeParam ( tp) => Some ( ( n. value , substs. get ( & tp) ?. clone ( ) ) ) ,
229
227
_ => None ,
230
228
}
231
229
} )
Original file line number Diff line number Diff line change @@ -322,3 +322,13 @@ impl InFile<SyntaxNode> {
322
322
} )
323
323
}
324
324
}
325
+
326
+ impl < N : AstNode > InFile < N > {
327
+ pub fn descendants < T : AstNode > ( self ) -> impl Iterator < Item = InFile < T > > {
328
+ self . value . syntax ( ) . descendants ( ) . filter_map ( T :: cast) . map ( move |n| self . with_value ( n) )
329
+ }
330
+
331
+ pub fn syntax ( & self ) -> InFile < & SyntaxNode > {
332
+ self . with_value ( self . value . syntax ( ) )
333
+ }
334
+ }
You can’t perform that action at this time.
0 commit comments