aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/completion')
-rw-r--r--crates/ra_analysis/src/completion/mod.rs14
-rw-r--r--crates/ra_analysis/src/completion/reference_completion.rs23
2 files changed, 21 insertions, 16 deletions
diff --git a/crates/ra_analysis/src/completion/mod.rs b/crates/ra_analysis/src/completion/mod.rs
index a8a752fc7..8034060de 100644
--- a/crates/ra_analysis/src/completion/mod.rs
+++ b/crates/ra_analysis/src/completion/mod.rs
@@ -221,6 +221,20 @@ mod tests {
221 } 221 }
222 222
223 #[test] 223 #[test]
224 fn test_completion_self_path() {
225 check_scope_completion(
226 r"
227 use self::m::B<|>;
228
229 mod m {
230 struct Bar;
231 }
232 ",
233 r#"[CompletionItem { label: "Bar", lookup: None, snippet: None }]"#,
234 );
235 }
236
237 #[test]
224 fn test_completion_mod_scope_nested() { 238 fn test_completion_mod_scope_nested() {
225 check_scope_completion( 239 check_scope_completion(
226 r" 240 r"
diff --git a/crates/ra_analysis/src/completion/reference_completion.rs b/crates/ra_analysis/src/completion/reference_completion.rs
index a96570415..d301a3c02 100644
--- a/crates/ra_analysis/src/completion/reference_completion.rs
+++ b/crates/ra_analysis/src/completion/reference_completion.rs
@@ -13,7 +13,7 @@ use crate::{
13 descriptors::{ 13 descriptors::{
14 module::{ModuleDescriptor}, 14 module::{ModuleDescriptor},
15 function::FnScopes, 15 function::FnScopes,
16 Path, PathKind, 16 Path,
17 }, 17 },
18 Cancelable 18 Cancelable
19}; 19};
@@ -148,9 +148,13 @@ fn complete_path(
148 acc: &mut Vec<CompletionItem>, 148 acc: &mut Vec<CompletionItem>,
149 db: &RootDatabase, 149 db: &RootDatabase,
150 module: &ModuleDescriptor, 150 module: &ModuleDescriptor,
151 path: Path, 151 mut path: Path,
152) -> Cancelable<()> { 152) -> Cancelable<()> {
153 let target_module = match find_target_module(module, path) { 153 if path.segments.is_empty() {
154 return Ok(());
155 }
156 path.segments.pop();
157 let target_module = match module.resolve_path(path) {
154 None => return Ok(()), 158 None => return Ok(()),
155 Some(it) => it, 159 Some(it) => it,
156 }; 160 };
@@ -167,19 +171,6 @@ fn complete_path(
167 Ok(()) 171 Ok(())
168} 172}
169 173
170fn find_target_module(module: &ModuleDescriptor, path: Path) -> Option<ModuleDescriptor> {
171 if path.kind != PathKind::Crate {
172 return None;
173 }
174 let mut segments = path.segments;
175 segments.pop();
176 let mut target_module = module.crate_root();
177 for name in segments {
178 target_module = target_module.child(&name)?;
179 }
180 Some(target_module)
181}
182
183fn complete_mod_item_snippets(acc: &mut Vec<CompletionItem>) { 174fn complete_mod_item_snippets(acc: &mut Vec<CompletionItem>) {
184 acc.push(CompletionItem { 175 acc.push(CompletionItem {
185 label: "tfn".to_string(), 176 label: "tfn".to_string(),