diff options
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 4f337d163..704648b59 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -220,27 +220,32 @@ impl AnalysisImpl { | |||
220 | let source_root = self.db.file_source_root(file_id); | 220 | let source_root = self.db.file_source_root(file_id); |
221 | self.db.module_tree(source_root) | 221 | self.db.module_tree(source_root) |
222 | } | 222 | } |
223 | pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 223 | pub fn parent_module( |
224 | &self, | ||
225 | file_id: FileId, | ||
226 | offset: TextUnit, | ||
227 | ) -> Cancelable<Vec<(FileId, FileSymbol)>> { | ||
224 | let module_tree = self.module_tree(file_id)?; | 228 | let module_tree = self.module_tree(file_id)?; |
229 | let file = self.db.file_syntax(file_id); | ||
230 | let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), offset) { | ||
231 | Some(m) if !m.has_semi() => ModuleSource::new_inline(file_id, m), | ||
232 | _ => ModuleSource::File(file_id), | ||
233 | }; | ||
225 | 234 | ||
226 | let res = module_tree | 235 | let res = module_tree |
227 | .modules_for_file(file_id) | 236 | .modules_for_source(module_source) |
228 | .into_iter() | 237 | .into_iter() |
229 | .filter_map(|module_id| { | 238 | .filter_map(|module_id| { |
230 | let link = module_id.parent_link(&module_tree)?; | 239 | let link = module_id.parent_link(&module_tree)?; |
231 | let file_id = match link.owner(&module_tree).source(&module_tree) { | 240 | let file_id = link.owner(&module_tree).source(&module_tree).file_id(); |
232 | ModuleSource::File(file_id) => file_id, | ||
233 | ModuleSource::Inline(..) => { | ||
234 | //TODO: https://github.com/rust-analyzer/rust-analyzer/issues/181 | ||
235 | return None; | ||
236 | } | ||
237 | }; | ||
238 | let decl = link.bind_source(&module_tree, &*self.db); | 241 | let decl = link.bind_source(&module_tree, &*self.db); |
239 | let decl = decl.ast(); | 242 | let decl = decl.ast(); |
240 | 243 | ||
244 | let decl_name = decl.name().unwrap(); | ||
245 | |||
241 | let sym = FileSymbol { | 246 | let sym = FileSymbol { |
242 | name: decl.name().unwrap().text(), | 247 | name: decl_name.text(), |
243 | node_range: decl.syntax().range(), | 248 | node_range: decl_name.syntax().range(), |
244 | kind: MODULE, | 249 | kind: MODULE, |
245 | }; | 250 | }; |
246 | Some((file_id, sym)) | 251 | Some((file_id, sym)) |
@@ -252,7 +257,7 @@ impl AnalysisImpl { | |||
252 | let module_tree = self.module_tree(file_id)?; | 257 | let module_tree = self.module_tree(file_id)?; |
253 | let crate_graph = self.db.crate_graph(); | 258 | let crate_graph = self.db.crate_graph(); |
254 | let res = module_tree | 259 | let res = module_tree |
255 | .modules_for_file(file_id) | 260 | .modules_for_source(ModuleSource::File(file_id)) |
256 | .into_iter() | 261 | .into_iter() |
257 | .map(|it| it.root(&module_tree)) | 262 | .map(|it| it.root(&module_tree)) |
258 | .filter_map(|it| it.source(&module_tree).as_file()) | 263 | .filter_map(|it| it.source(&module_tree).as_file()) |
@@ -376,7 +381,7 @@ impl AnalysisImpl { | |||
376 | fix: None, | 381 | fix: None, |
377 | }) | 382 | }) |
378 | .collect::<Vec<_>>(); | 383 | .collect::<Vec<_>>(); |
379 | if let Some(m) = module_tree.any_module_for_file(file_id) { | 384 | if let Some(m) = module_tree.any_module_for_source(ModuleSource::File(file_id)) { |
380 | for (name_node, problem) in m.problems(&module_tree, &*self.db) { | 385 | for (name_node, problem) in m.problems(&module_tree, &*self.db) { |
381 | let diag = match problem { | 386 | let diag = match problem { |
382 | Problem::UnresolvedModule { candidate } => { | 387 | Problem::UnresolvedModule { candidate } => { |
@@ -539,7 +544,7 @@ impl AnalysisImpl { | |||
539 | Some(name) => name.text(), | 544 | Some(name) => name.text(), |
540 | None => return Vec::new(), | 545 | None => return Vec::new(), |
541 | }; | 546 | }; |
542 | let module_id = match module_tree.any_module_for_file(file_id) { | 547 | let module_id = match module_tree.any_module_for_source(ModuleSource::File(file_id)) { |
543 | Some(id) => id, | 548 | Some(id) => id, |
544 | None => return Vec::new(), | 549 | None => return Vec::new(), |
545 | }; | 550 | }; |