aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-11-27 22:19:55 +0000
committerAleksey Kladov <[email protected]>2018-11-27 22:19:55 +0000
commit36b1d20c1661877c0c5a55ccd07522bc97bfc254 (patch)
treedf84b92b2a05fa9cf1306b3a26bb4f5969fd0784 /crates/ra_analysis/src
parent16f67ee384d5b49358de167069535af727b87dba (diff)
rename ModuleDescriptor -> Module
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/completion/mod.rs6
-rw-r--r--crates/ra_analysis/src/completion/reference_completion.rs6
-rw-r--r--crates/ra_analysis/src/hir/mod.rs6
-rw-r--r--crates/ra_analysis/src/hir/module/mod.rs40
-rw-r--r--crates/ra_analysis/src/imp.rs11
5 files changed, 34 insertions, 35 deletions
diff --git a/crates/ra_analysis/src/completion/mod.rs b/crates/ra_analysis/src/completion/mod.rs
index 08fb149af..67ec9a735 100644
--- a/crates/ra_analysis/src/completion/mod.rs
+++ b/crates/ra_analysis/src/completion/mod.rs
@@ -11,9 +11,7 @@ use rustc_hash::{FxHashMap};
11 11
12use crate::{ 12use crate::{
13 db::{self, SyntaxDatabase}, 13 db::{self, SyntaxDatabase},
14 hir:: 14 hir,
15 ModuleDescriptor
16 ,
17 Cancelable, FilePosition 15 Cancelable, FilePosition
18}; 16};
19 17
@@ -38,7 +36,7 @@ pub(crate) fn completions(
38 original_file.reparse(&edit) 36 original_file.reparse(&edit)
39 }; 37 };
40 38
41 let module = ctry!(ModuleDescriptor::guess_from_position(db, position)?); 39 let module = ctry!(hir::Module::guess_from_position(db, position)?);
42 40
43 let mut res = Vec::new(); 41 let mut res = Vec::new();
44 let mut has_completions = false; 42 let mut has_completions = false;
diff --git a/crates/ra_analysis/src/completion/reference_completion.rs b/crates/ra_analysis/src/completion/reference_completion.rs
index 5bf8c3725..881d29916 100644
--- a/crates/ra_analysis/src/completion/reference_completion.rs
+++ b/crates/ra_analysis/src/completion/reference_completion.rs
@@ -11,7 +11,7 @@ use crate::{
11 db::RootDatabase, 11 db::RootDatabase,
12 completion::CompletionItem, 12 completion::CompletionItem,
13 hir::{ 13 hir::{
14 ModuleDescriptor, 14 self,
15 FnScopes, 15 FnScopes,
16 Def, 16 Def,
17 Path, 17 Path,
@@ -22,7 +22,7 @@ use crate::{
22pub(super) fn completions( 22pub(super) fn completions(
23 acc: &mut Vec<CompletionItem>, 23 acc: &mut Vec<CompletionItem>,
24 db: &RootDatabase, 24 db: &RootDatabase,
25 module: &ModuleDescriptor, 25 module: &hir::Module,
26 file: &SourceFileNode, 26 file: &SourceFileNode,
27 name_ref: ast::NameRef, 27 name_ref: ast::NameRef,
28) -> Cancelable<()> { 28) -> Cancelable<()> {
@@ -150,7 +150,7 @@ fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<Completi
150fn complete_path( 150fn complete_path(
151 acc: &mut Vec<CompletionItem>, 151 acc: &mut Vec<CompletionItem>,
152 db: &RootDatabase, 152 db: &RootDatabase,
153 module: &ModuleDescriptor, 153 module: &hir::Module,
154 mut path: Path, 154 mut path: Path,
155) -> Cancelable<()> { 155) -> Cancelable<()> {
156 if path.segments.is_empty() { 156 if path.segments.is_empty() {
diff --git a/crates/ra_analysis/src/hir/mod.rs b/crates/ra_analysis/src/hir/mod.rs
index e234173a9..1de8fadcf 100644
--- a/crates/ra_analysis/src/hir/mod.rs
+++ b/crates/ra_analysis/src/hir/mod.rs
@@ -19,14 +19,14 @@ use crate::{
19 19
20pub(crate) use self::{ 20pub(crate) use self::{
21 path::{Path, PathKind}, 21 path::{Path, PathKind},
22 module::{ModuleDescriptor, ModuleId, Problem, nameres::FileItemId}, 22 module::{Module, ModuleId, Problem, nameres::FileItemId},
23 function::{FunctionDescriptor, FnScopes}, 23 function::{FunctionDescriptor, FnScopes},
24}; 24};
25 25
26pub use self::function::FnSignatureInfo; 26pub use self::function::FnSignatureInfo;
27 27
28pub(crate) enum Def { 28pub(crate) enum Def {
29 Module(ModuleDescriptor), 29 Module(Module),
30 Item, 30 Item,
31} 31}
32 32
@@ -35,7 +35,7 @@ impl DefId {
35 let loc = db.id_maps().def_loc(self); 35 let loc = db.id_maps().def_loc(self);
36 let res = match loc { 36 let res = match loc {
37 DefLoc::Module { id, source_root } => { 37 DefLoc::Module { id, source_root } => {
38 let descr = ModuleDescriptor::new(db, source_root, id)?; 38 let descr = Module::new(db, source_root, id)?;
39 Def::Module(descr) 39 Def::Module(descr)
40 } 40 }
41 DefLoc::Item { .. } => Def::Item, 41 DefLoc::Item { .. } => Def::Item,
diff --git a/crates/ra_analysis/src/hir/module/mod.rs b/crates/ra_analysis/src/hir/module/mod.rs
index 4d5945b1a..33d2b95ab 100644
--- a/crates/ra_analysis/src/hir/module/mod.rs
+++ b/crates/ra_analysis/src/hir/module/mod.rs
@@ -22,53 +22,53 @@ use crate::{
22 22
23pub(crate) use self::nameres::ModuleScope; 23pub(crate) use self::nameres::ModuleScope;
24 24
25/// `ModuleDescriptor` is API entry point to get all the information 25/// `Module` is API entry point to get all the information
26/// about a particular module. 26/// about a particular module.
27#[derive(Debug, Clone)] 27#[derive(Debug, Clone)]
28pub(crate) struct ModuleDescriptor { 28pub(crate) struct Module {
29 tree: Arc<ModuleTree>, 29 tree: Arc<ModuleTree>,
30 source_root_id: SourceRootId, 30 source_root_id: SourceRootId,
31 module_id: ModuleId, 31 module_id: ModuleId,
32} 32}
33 33
34impl ModuleDescriptor { 34impl Module {
35 /// Lookup `ModuleDescriptor` by `FileId`. Note that this is inherently 35 /// Lookup `Module` by `FileId`. Note that this is inherently
36 /// lossy transformation: in general, a single source might correspond to 36 /// lossy transformation: in general, a single source might correspond to
37 /// several modules. 37 /// several modules.
38 pub fn guess_from_file_id( 38 pub fn guess_from_file_id(
39 db: &impl HirDatabase, 39 db: &impl HirDatabase,
40 file_id: FileId, 40 file_id: FileId,
41 ) -> Cancelable<Option<ModuleDescriptor>> { 41 ) -> Cancelable<Option<Module>> {
42 ModuleDescriptor::guess_from_source(db, file_id, ModuleSource::SourceFile(file_id)) 42 Module::guess_from_source(db, file_id, ModuleSource::SourceFile(file_id))
43 } 43 }
44 44
45 /// Lookup `ModuleDescriptor` by position in the source code. Note that this 45 /// Lookup `Module` by position in the source code. Note that this
46 /// is inherently lossy transformation: in general, a single source might 46 /// is inherently lossy transformation: in general, a single source might
47 /// correspond to several modules. 47 /// correspond to several modules.
48 pub fn guess_from_position( 48 pub fn guess_from_position(
49 db: &impl HirDatabase, 49 db: &impl HirDatabase,
50 position: FilePosition, 50 position: FilePosition,
51 ) -> Cancelable<Option<ModuleDescriptor>> { 51 ) -> Cancelable<Option<Module>> {
52 let file = db.file_syntax(position.file_id); 52 let file = db.file_syntax(position.file_id);
53 let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) 53 let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), position.offset)
54 { 54 {
55 Some(m) if !m.has_semi() => ModuleSource::new_inline(position.file_id, m), 55 Some(m) if !m.has_semi() => ModuleSource::new_inline(position.file_id, m),
56 _ => ModuleSource::SourceFile(position.file_id), 56 _ => ModuleSource::SourceFile(position.file_id),
57 }; 57 };
58 ModuleDescriptor::guess_from_source(db, position.file_id, module_source) 58 Module::guess_from_source(db, position.file_id, module_source)
59 } 59 }
60 60
61 fn guess_from_source( 61 fn guess_from_source(
62 db: &impl HirDatabase, 62 db: &impl HirDatabase,
63 file_id: FileId, 63 file_id: FileId,
64 module_source: ModuleSource, 64 module_source: ModuleSource,
65 ) -> Cancelable<Option<ModuleDescriptor>> { 65 ) -> Cancelable<Option<Module>> {
66 let source_root_id = db.file_source_root(file_id); 66 let source_root_id = db.file_source_root(file_id);
67 let module_tree = db.module_tree(source_root_id)?; 67 let module_tree = db.module_tree(source_root_id)?;
68 68
69 let res = match module_tree.any_module_for_source(module_source) { 69 let res = match module_tree.any_module_for_source(module_source) {
70 None => None, 70 None => None,
71 Some(module_id) => Some(ModuleDescriptor { 71 Some(module_id) => Some(Module {
72 tree: module_tree, 72 tree: module_tree,
73 source_root_id, 73 source_root_id,
74 module_id, 74 module_id,
@@ -81,9 +81,9 @@ impl ModuleDescriptor {
81 db: &impl HirDatabase, 81 db: &impl HirDatabase,
82 source_root_id: SourceRootId, 82 source_root_id: SourceRootId,
83 module_id: ModuleId, 83 module_id: ModuleId,
84 ) -> Cancelable<ModuleDescriptor> { 84 ) -> Cancelable<Module> {
85 let module_tree = db.module_tree(source_root_id)?; 85 let module_tree = db.module_tree(source_root_id)?;
86 let res = ModuleDescriptor { 86 let res = Module {
87 tree: module_tree, 87 tree: module_tree,
88 source_root_id, 88 source_root_id,
89 module_id, 89 module_id,
@@ -105,18 +105,18 @@ impl ModuleDescriptor {
105 } 105 }
106 106
107 /// Parent module. Returns `None` if this is a root module. 107 /// Parent module. Returns `None` if this is a root module.
108 pub fn parent(&self) -> Option<ModuleDescriptor> { 108 pub fn parent(&self) -> Option<Module> {
109 let parent_id = self.module_id.parent(&self.tree)?; 109 let parent_id = self.module_id.parent(&self.tree)?;
110 Some(ModuleDescriptor { 110 Some(Module {
111 module_id: parent_id, 111 module_id: parent_id,
112 ..self.clone() 112 ..self.clone()
113 }) 113 })
114 } 114 }
115 115
116 /// The root of the tree this module is part of 116 /// The root of the tree this module is part of
117 pub fn crate_root(&self) -> ModuleDescriptor { 117 pub fn crate_root(&self) -> Module {
118 let root_id = self.module_id.crate_root(&self.tree); 118 let root_id = self.module_id.crate_root(&self.tree);
119 ModuleDescriptor { 119 Module {
120 module_id: root_id, 120 module_id: root_id,
121 ..self.clone() 121 ..self.clone()
122 } 122 }
@@ -138,9 +138,9 @@ impl ModuleDescriptor {
138 } 138 }
139 139
140 /// Finds a child module with the specified name. 140 /// Finds a child module with the specified name.
141 pub fn child(&self, name: &str) -> Option<ModuleDescriptor> { 141 pub fn child(&self, name: &str) -> Option<Module> {
142 let child_id = self.module_id.child(&self.tree, name)?; 142 let child_id = self.module_id.child(&self.tree, name)?;
143 Some(ModuleDescriptor { 143 Some(Module {
144 module_id: child_id, 144 module_id: child_id,
145 ..self.clone() 145 ..self.clone()
146 }) 146 })
@@ -168,7 +168,7 @@ impl ModuleDescriptor {
168 let segments = path.segments; 168 let segments = path.segments;
169 for name in segments.iter() { 169 for name in segments.iter() {
170 let module = match db.id_maps().def_loc(curr) { 170 let module = match db.id_maps().def_loc(curr) {
171 DefLoc::Module { id, source_root } => ModuleDescriptor::new(db, source_root, id)?, 171 DefLoc::Module { id, source_root } => Module::new(db, source_root, id)?,
172 _ => return Ok(None), 172 _ => return Ok(None),
173 }; 173 };
174 let scope = module.scope(db)?; 174 let scope = module.scope(db)?;
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 377f7420f..9118ed7d4 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -20,7 +20,8 @@ use crate::{
20 completion::{completions, CompletionItem}, 20 completion::{completions, CompletionItem},
21 db::{self, FileSyntaxQuery, SyntaxDatabase}, 21 db::{self, FileSyntaxQuery, SyntaxDatabase},
22 hir::{ 22 hir::{
23 FunctionDescriptor, FnSignatureInfo, ModuleDescriptor, 23 self,
24 FunctionDescriptor, FnSignatureInfo,
24 Problem, 25 Problem,
25 }, 26 },
26 input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE}, 27 input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE},
@@ -226,7 +227,7 @@ impl AnalysisImpl {
226 /// This return `Vec`: a module may be included from several places. We 227 /// This return `Vec`: a module may be included from several places. We
227 /// don't handle this case yet though, so the Vec has length at most one. 228 /// don't handle this case yet though, so the Vec has length at most one.
228 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { 229 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> {
229 let descr = match ModuleDescriptor::guess_from_position(&*self.db, position)? { 230 let descr = match hir::Module::guess_from_position(&*self.db, position)? {
230 None => return Ok(Vec::new()), 231 None => return Ok(Vec::new()),
231 Some(it) => it, 232 Some(it) => it,
232 }; 233 };
@@ -245,7 +246,7 @@ impl AnalysisImpl {
245 } 246 }
246 /// Returns `Vec` for the same reason as `parent_module` 247 /// Returns `Vec` for the same reason as `parent_module`
247 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { 248 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
248 let descr = match ModuleDescriptor::guess_from_file_id(&*self.db, file_id)? { 249 let descr = match hir::Module::guess_from_file_id(&*self.db, file_id)? {
249 None => return Ok(Vec::new()), 250 None => return Ok(Vec::new()),
250 Some(it) => it, 251 Some(it) => it,
251 }; 252 };
@@ -298,7 +299,7 @@ impl AnalysisImpl {
298 if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { 299 if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
299 if module.has_semi() { 300 if module.has_semi() {
300 let parent_module = 301 let parent_module =
301 ModuleDescriptor::guess_from_file_id(&*self.db, position.file_id)?; 302 hir::Module::guess_from_file_id(&*self.db, position.file_id)?;
302 let child_name = module.name(); 303 let child_name = module.name();
303 match (parent_module, child_name) { 304 match (parent_module, child_name) {
304 (Some(parent_module), Some(child_name)) => { 305 (Some(parent_module), Some(child_name)) => {
@@ -380,7 +381,7 @@ impl AnalysisImpl {
380 fix: None, 381 fix: None,
381 }) 382 })
382 .collect::<Vec<_>>(); 383 .collect::<Vec<_>>();
383 if let Some(m) = ModuleDescriptor::guess_from_file_id(&*self.db, file_id)? { 384 if let Some(m) = hir::Module::guess_from_file_id(&*self.db, file_id)? {
384 for (name_node, problem) in m.problems(&*self.db) { 385 for (name_node, problem) in m.problems(&*self.db) {
385 let diag = match problem { 386 let diag = match problem {
386 Problem::UnresolvedModule { candidate } => { 387 Problem::UnresolvedModule { candidate } => {