diff options
author | Ekaterina Babshukova <[email protected]> | 2019-10-15 20:50:28 +0100 |
---|---|---|
committer | Ekaterina Babshukova <[email protected]> | 2019-10-22 21:47:31 +0100 |
commit | 55e1910d006da7961687928542c1167cc556a39f (patch) | |
tree | 8440f4a2655ab06884d20180da10134f652d403b /crates/ra_ide_api/src/references | |
parent | 93c179531b31786bfd50644b5f0c879afc798f7d (diff) |
classify module from declaration
Diffstat (limited to 'crates/ra_ide_api/src/references')
-rw-r--r-- | crates/ra_ide_api/src/references/classify.rs | 13 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/search_scope.rs | 10 |
2 files changed, 16 insertions, 7 deletions
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs index 93e079ccc..ac9cf34eb 100644 --- a/crates/ra_ide_api/src/references/classify.rs +++ b/crates/ra_ide_api/src/references/classify.rs | |||
@@ -31,9 +31,16 @@ pub(crate) fn classify_name( | |||
31 | Some(from_struct_field(db, field)) | 31 | Some(from_struct_field(db, field)) |
32 | }, | 32 | }, |
33 | ast::Module(it) => { | 33 | ast::Module(it) => { |
34 | let ast = hir::ModuleSource::Module(it); | 34 | let def = { |
35 | let src = hir::Source { file_id, ast }; | 35 | if !it.has_semi() { |
36 | let def = hir::Module::from_definition(db, src)?; | 36 | let ast = hir::ModuleSource::Module(it); |
37 | let src = hir::Source { file_id, ast }; | ||
38 | hir::Module::from_definition(db, src) | ||
39 | } else { | ||
40 | let src = hir::Source { file_id, ast: it }; | ||
41 | hir::Module::from_declaration(db, src) | ||
42 | } | ||
43 | }?; | ||
37 | Some(from_module_def(db, def.into(), None)) | 44 | Some(from_module_def(db, def.into(), None)) |
38 | }, | 45 | }, |
39 | ast::StructDef(it) => { | 46 | ast::StructDef(it) => { |
diff --git a/crates/ra_ide_api/src/references/search_scope.rs b/crates/ra_ide_api/src/references/search_scope.rs index 680988a21..d2c966b4f 100644 --- a/crates/ra_ide_api/src/references/search_scope.rs +++ b/crates/ra_ide_api/src/references/search_scope.rs | |||
@@ -1,5 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use std::collections::HashSet; | ||
4 | |||
3 | use hir::{DefWithBody, HasSource, ModuleSource}; | 5 | use hir::{DefWithBody, HasSource, ModuleSource}; |
4 | use ra_db::{FileId, SourceDatabase, SourceDatabaseExt}; | 6 | use ra_db::{FileId, SourceDatabase, SourceDatabaseExt}; |
5 | use ra_syntax::{AstNode, TextRange}; | 7 | use ra_syntax::{AstNode, TextRange}; |
@@ -9,7 +11,7 @@ use crate::db::RootDatabase; | |||
9 | use super::{NameDefinition, NameKind}; | 11 | use super::{NameDefinition, NameKind}; |
10 | 12 | ||
11 | impl NameDefinition { | 13 | impl NameDefinition { |
12 | pub(crate) fn search_scope(&self, db: &RootDatabase) -> Vec<(FileId, Option<TextRange>)> { | 14 | pub(crate) fn search_scope(&self, db: &RootDatabase) -> HashSet<(FileId, Option<TextRange>)> { |
13 | let module_src = self.container.definition_source(db); | 15 | let module_src = self.container.definition_source(db); |
14 | let file_id = module_src.file_id.original_file(db); | 16 | let file_id = module_src.file_id.original_file(db); |
15 | 17 | ||
@@ -19,13 +21,13 @@ impl NameDefinition { | |||
19 | DefWithBody::Const(c) => c.source(db).ast.syntax().text_range(), | 21 | DefWithBody::Const(c) => c.source(db).ast.syntax().text_range(), |
20 | DefWithBody::Static(s) => s.source(db).ast.syntax().text_range(), | 22 | DefWithBody::Static(s) => s.source(db).ast.syntax().text_range(), |
21 | }; | 23 | }; |
22 | return vec![(file_id, Some(range))]; | 24 | return [(file_id, Some(range))].iter().cloned().collect(); |
23 | } | 25 | } |
24 | 26 | ||
25 | if let Some(ref vis) = self.visibility { | 27 | if let Some(ref vis) = self.visibility { |
26 | let source_root_id = db.file_source_root(file_id); | 28 | let source_root_id = db.file_source_root(file_id); |
27 | let source_root = db.source_root(source_root_id); | 29 | let source_root = db.source_root(source_root_id); |
28 | let mut files = source_root.walk().map(|id| (id.into(), None)).collect::<Vec<_>>(); | 30 | let mut files = source_root.walk().map(|id| (id.into(), None)).collect::<HashSet<_>>(); |
29 | 31 | ||
30 | if vis.syntax().to_string().as_str() == "pub(crate)" { | 32 | if vis.syntax().to_string().as_str() == "pub(crate)" { |
31 | return files; | 33 | return files; |
@@ -54,6 +56,6 @@ impl NameDefinition { | |||
54 | ModuleSource::Module(m) => Some(m.syntax().text_range()), | 56 | ModuleSource::Module(m) => Some(m.syntax().text_range()), |
55 | ModuleSource::SourceFile(_) => None, | 57 | ModuleSource::SourceFile(_) => None, |
56 | }; | 58 | }; |
57 | vec![(file_id, range)] | 59 | [(file_id, range)].iter().cloned().collect() |
58 | } | 60 | } |
59 | } | 61 | } |