aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/imp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r--crates/ra_analysis/src/imp.rs44
1 files changed, 16 insertions, 28 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 812fed32d..c0bed04bf 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -21,7 +21,7 @@ use crate::{
21 db::{self, FileSyntaxQuery, SyntaxDatabase}, 21 db::{self, FileSyntaxQuery, SyntaxDatabase},
22 descriptors::{ 22 descriptors::{
23 function::{FnDescriptor, FnId}, 23 function::{FnDescriptor, FnId},
24 module::{ModuleSource, ModuleTree, Problem}, 24 module::{ModuleDescriptor, ModuleSource, ModuleTree, Problem},
25 DeclarationDescriptor, DescriptorDatabase, 25 DeclarationDescriptor, DescriptorDatabase,
26 }, 26 },
27 input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE}, 27 input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE},
@@ -221,34 +221,22 @@ impl AnalysisImpl {
221 self.db.module_tree(source_root) 221 self.db.module_tree(source_root)
222 } 222 }
223 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { 223 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> {
224 let module_tree = self.module_tree(position.file_id)?; 224 let descr = match ModuleDescriptor::guess_from_position(&*self.db, position)? {
225 let file = self.db.file_syntax(position.file_id); 225 None => return Ok(Vec::new()),
226 let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) 226 Some(it) => it,
227 {
228 Some(m) if !m.has_semi() => ModuleSource::new_inline(position.file_id, m),
229 _ => ModuleSource::SourceFile(position.file_id),
230 }; 227 };
231 228 let (file_id, decl) = match descr.parent_link_source(&*self.db) {
232 let res = module_tree 229 None => return Ok(Vec::new()),
233 .modules_for_source(module_source) 230 Some(it) => it,
234 .into_iter() 231 };
235 .filter_map(|module_id| { 232 let decl = decl.borrowed();
236 let link = module_id.parent_link(&module_tree)?; 233 let decl_name = decl.name().unwrap();
237 let file_id = link.owner(&module_tree).source(&module_tree).file_id(); 234 let sym = FileSymbol {
238 let decl = link.bind_source(&module_tree, &*self.db); 235 name: decl_name.text(),
239 let decl = decl.borrowed(); 236 node_range: decl_name.syntax().range(),
240 237 kind: MODULE,
241 let decl_name = decl.name().unwrap(); 238 };
242 239 Ok(vec![(file_id, sym)])
243 let sym = FileSymbol {
244 name: decl_name.text(),
245 node_range: decl_name.syntax().range(),
246 kind: MODULE,
247 };
248 Some((file_id, sym))
249 })
250 .collect();
251 Ok(res)
252 } 240 }
253 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { 241 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
254 let module_tree = self.module_tree(file_id)?; 242 let module_tree = self.module_tree(file_id)?;