From 9e213385c9d06db3c8ca20812779e2b8f8ad2c71 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 30 Mar 2019 13:25:53 +0300 Subject: switch to new rowan --- crates/ra_assists/src/auto_import.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'crates/ra_assists/src/auto_import.rs') diff --git a/crates/ra_assists/src/auto_import.rs b/crates/ra_assists/src/auto_import.rs index 685dbed06..3fdf6b0d9 100644 --- a/crates/ra_assists/src/auto_import.rs +++ b/crates/ra_assists/src/auto_import.rs @@ -21,7 +21,7 @@ fn collect_path_segments_raw<'a>( ) -> Option { let oldlen = segments.len(); loop { - let mut children = path.syntax().children(); + let mut children = path.syntax().children_with_tokens(); let (first, second, third) = ( children.next().map(|n| (n, n.kind())), children.next().map(|n| (n, n.kind())), @@ -29,11 +29,11 @@ fn collect_path_segments_raw<'a>( ); match (first, second, third) { (Some((subpath, PATH)), Some((_, COLONCOLON)), Some((segment, PATH_SEGMENT))) => { - path = ast::Path::cast(subpath)?; - segments.push(ast::PathSegment::cast(segment)?); + path = ast::Path::cast(subpath.as_node()?)?; + segments.push(ast::PathSegment::cast(segment.as_node()?)?); } (Some((segment, PATH_SEGMENT)), _, _) => { - segments.push(ast::PathSegment::cast(segment)?); + segments.push(ast::PathSegment::cast(segment.as_node()?)?); break; } (_, _, _) => return None, @@ -514,8 +514,7 @@ fn apply_auto_import<'a>( } pub(crate) fn auto_import(mut ctx: AssistCtx) -> Option { - let node = ctx.covering_node(); - let path = node.ancestors().find_map(ast::Path::cast)?; + let path: &ast::Path = ctx.node_at_offset()?; // We don't want to mess with use statements if path.syntax().ancestors().find_map(ast::UseItem::cast).is_some() { return None; @@ -537,7 +536,7 @@ pub(crate) fn auto_import(mut ctx: AssistCtx) -> Option