aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/auto_import.rs
diff options
context:
space:
mode:
authoruHOOCCOOHu <[email protected]>2019-09-11 19:01:07 +0100
committeruHOOCCOOHu <[email protected]>2019-09-15 12:40:32 +0100
commit4926bed42680d329f906be93450bec6b2ba0e99b (patch)
tree455c0bc9d839a18fffda6d018bf41d1c58ebfa52 /crates/ra_assists/src/auto_import.rs
parent2d79a1ad83cc39075c7c9e3230973013c8c58b17 (diff)
Support path starting with a type
Diffstat (limited to 'crates/ra_assists/src/auto_import.rs')
-rw-r--r--crates/ra_assists/src/auto_import.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/crates/ra_assists/src/auto_import.rs b/crates/ra_assists/src/auto_import.rs
index 1158adbbc..5ecda1ff5 100644
--- a/crates/ra_assists/src/auto_import.rs
+++ b/crates/ra_assists/src/auto_import.rs
@@ -504,7 +504,7 @@ fn apply_auto_import(
504 } 504 }
505} 505}
506 506
507pub fn collect_hir_path_segments(path: &hir::Path) -> Vec<SmolStr> { 507pub fn collect_hir_path_segments(path: &hir::Path) -> Option<Vec<SmolStr>> {
508 let mut ps = Vec::<SmolStr>::with_capacity(10); 508 let mut ps = Vec::<SmolStr>::with_capacity(10);
509 match path.kind { 509 match path.kind {
510 hir::PathKind::Abs => ps.push("".into()), 510 hir::PathKind::Abs => ps.push("".into()),
@@ -512,11 +512,12 @@ pub fn collect_hir_path_segments(path: &hir::Path) -> Vec<SmolStr> {
512 hir::PathKind::Plain => {} 512 hir::PathKind::Plain => {}
513 hir::PathKind::Self_ => ps.push("self".into()), 513 hir::PathKind::Self_ => ps.push("self".into()),
514 hir::PathKind::Super => ps.push("super".into()), 514 hir::PathKind::Super => ps.push("super".into()),
515 hir::PathKind::Type => return None,
515 } 516 }
516 for s in path.segments.iter() { 517 for s in path.segments.iter() {
517 ps.push(s.name.to_string().into()); 518 ps.push(s.name.to_string().into());
518 } 519 }
519 ps 520 Some(ps)
520} 521}
521 522
522// This function produces sequence of text edits into edit 523// This function produces sequence of text edits into edit
@@ -552,7 +553,7 @@ pub(crate) fn auto_import(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist
552 } 553 }
553 554
554 let hir_path = hir::Path::from_ast(path.clone())?; 555 let hir_path = hir::Path::from_ast(path.clone())?;
555 let segments = collect_hir_path_segments(&hir_path); 556 let segments = collect_hir_path_segments(&hir_path)?;
556 if segments.len() < 2 { 557 if segments.len() < 2 {
557 return None; 558 return None;
558 } 559 }