aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers
diff options
context:
space:
mode:
authorunexge <[email protected]>2020-08-03 11:04:20 +0100
committerunexge <[email protected]>2020-08-03 11:04:20 +0100
commitbdb97756ca4c2710061fc49a5e2c2c10f5cc1eb6 (patch)
tree8027f06894f54b51817f487ad6721e58567dbcf8 /crates/ra_assists/src/handlers
parent544322e66aacb763f8c824b5a572f8d7b93c9a6f (diff)
Simplify `find_mod_path` with use of `node.ancestors`
Diffstat (limited to 'crates/ra_assists/src/handlers')
-rw-r--r--crates/ra_assists/src/handlers/expand_glob_import.rs21
1 files changed, 1 insertions, 20 deletions
diff --git a/crates/ra_assists/src/handlers/expand_glob_import.rs b/crates/ra_assists/src/handlers/expand_glob_import.rs
index 963c1353f..1eb8070ad 100644
--- a/crates/ra_assists/src/handlers/expand_glob_import.rs
+++ b/crates/ra_assists/src/handlers/expand_glob_import.rs
@@ -59,26 +59,7 @@ pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext) -> Opti
59} 59}
60 60
61fn find_mod_path(star: &SyntaxToken) -> Option<ast::Path> { 61fn find_mod_path(star: &SyntaxToken) -> Option<ast::Path> {
62 let mut node = star.parent(); 62 star.ancestors().find_map(|n| ast::UseTree::cast(n).and_then(|u| u.path()))
63
64 loop {
65 match_ast! {
66 match node {
67 ast::UseTree(use_tree) => {
68 if let Some(path) = use_tree.path() {
69 return Some(path);
70 }
71 },
72 ast::UseTreeList(_use_tree_list) => {},
73 _ => return None,
74 }
75 }
76
77 node = match node.parent() {
78 Some(node) => node,
79 None => return None,
80 }
81 }
82} 63}
83 64
84#[derive(PartialEq)] 65#[derive(PartialEq)]