diff options
Diffstat (limited to 'crates/ra_assists/src/auto_import.rs')
-rw-r--r-- | crates/ra_assists/src/auto_import.rs | 13 |
1 files changed, 6 insertions, 7 deletions
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>( | |||
21 | ) -> Option<usize> { | 21 | ) -> Option<usize> { |
22 | let oldlen = segments.len(); | 22 | let oldlen = segments.len(); |
23 | loop { | 23 | loop { |
24 | let mut children = path.syntax().children(); | 24 | let mut children = path.syntax().children_with_tokens(); |
25 | let (first, second, third) = ( | 25 | let (first, second, third) = ( |
26 | children.next().map(|n| (n, n.kind())), | 26 | children.next().map(|n| (n, n.kind())), |
27 | children.next().map(|n| (n, n.kind())), | 27 | children.next().map(|n| (n, n.kind())), |
@@ -29,11 +29,11 @@ fn collect_path_segments_raw<'a>( | |||
29 | ); | 29 | ); |
30 | match (first, second, third) { | 30 | match (first, second, third) { |
31 | (Some((subpath, PATH)), Some((_, COLONCOLON)), Some((segment, PATH_SEGMENT))) => { | 31 | (Some((subpath, PATH)), Some((_, COLONCOLON)), Some((segment, PATH_SEGMENT))) => { |
32 | path = ast::Path::cast(subpath)?; | 32 | path = ast::Path::cast(subpath.as_node()?)?; |
33 | segments.push(ast::PathSegment::cast(segment)?); | 33 | segments.push(ast::PathSegment::cast(segment.as_node()?)?); |
34 | } | 34 | } |
35 | (Some((segment, PATH_SEGMENT)), _, _) => { | 35 | (Some((segment, PATH_SEGMENT)), _, _) => { |
36 | segments.push(ast::PathSegment::cast(segment)?); | 36 | segments.push(ast::PathSegment::cast(segment.as_node()?)?); |
37 | break; | 37 | break; |
38 | } | 38 | } |
39 | (_, _, _) => return None, | 39 | (_, _, _) => return None, |
@@ -514,8 +514,7 @@ fn apply_auto_import<'a>( | |||
514 | } | 514 | } |
515 | 515 | ||
516 | pub(crate) fn auto_import(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 516 | pub(crate) fn auto_import(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
517 | let node = ctx.covering_node(); | 517 | let path: &ast::Path = ctx.node_at_offset()?; |
518 | let path = node.ancestors().find_map(ast::Path::cast)?; | ||
519 | // We don't want to mess with use statements | 518 | // We don't want to mess with use statements |
520 | if path.syntax().ancestors().find_map(ast::UseItem::cast).is_some() { | 519 | if path.syntax().ancestors().find_map(ast::UseItem::cast).is_some() { |
521 | return None; | 520 | return None; |
@@ -537,7 +536,7 @@ pub(crate) fn auto_import(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist | |||
537 | ); | 536 | ); |
538 | } | 537 | } |
539 | } else { | 538 | } else { |
540 | let current_file = node.ancestors().find_map(ast::SourceFile::cast)?; | 539 | let current_file = path.syntax().ancestors().find_map(ast::SourceFile::cast)?; |
541 | ctx.add_action( | 540 | ctx.add_action( |
542 | AssistId("auto_import"), | 541 | AssistId("auto_import"), |
543 | format!("import {} in the current file", fmt_segments(&segments)), | 542 | format!("import {} in the current file", fmt_segments(&segments)), |