From 36b1d20c1661877c0c5a55ccd07522bc97bfc254 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 28 Nov 2018 01:19:55 +0300 Subject: rename ModuleDescriptor -> Module --- crates/ra_analysis/src/completion/mod.rs | 6 ++-- .../src/completion/reference_completion.rs | 6 ++-- crates/ra_analysis/src/hir/mod.rs | 6 ++-- crates/ra_analysis/src/hir/module/mod.rs | 40 +++++++++++----------- crates/ra_analysis/src/imp.rs | 11 +++--- 5 files changed, 34 insertions(+), 35 deletions(-) (limited to 'crates') 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}; use crate::{ db::{self, SyntaxDatabase}, - hir:: - ModuleDescriptor - , + hir, Cancelable, FilePosition }; @@ -38,7 +36,7 @@ pub(crate) fn completions( original_file.reparse(&edit) }; - let module = ctry!(ModuleDescriptor::guess_from_position(db, position)?); + let module = ctry!(hir::Module::guess_from_position(db, position)?); let mut res = Vec::new(); 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::{ db::RootDatabase, completion::CompletionItem, hir::{ - ModuleDescriptor, + self, FnScopes, Def, Path, @@ -22,7 +22,7 @@ use crate::{ pub(super) fn completions( acc: &mut Vec, db: &RootDatabase, - module: &ModuleDescriptor, + module: &hir::Module, file: &SourceFileNode, name_ref: ast::NameRef, ) -> Cancelable<()> { @@ -150,7 +150,7 @@ fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec, db: &RootDatabase, - module: &ModuleDescriptor, + module: &hir::Module, mut path: Path, ) -> Cancelable<()> { 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::{ pub(crate) use self::{ path::{Path, PathKind}, - module::{ModuleDescriptor, ModuleId, Problem, nameres::FileItemId}, + module::{Module, ModuleId, Problem, nameres::FileItemId}, function::{FunctionDescriptor, FnScopes}, }; pub use self::function::FnSignatureInfo; pub(crate) enum Def { - Module(ModuleDescriptor), + Module(Module), Item, } @@ -35,7 +35,7 @@ impl DefId { let loc = db.id_maps().def_loc(self); let res = match loc { DefLoc::Module { id, source_root } => { - let descr = ModuleDescriptor::new(db, source_root, id)?; + let descr = Module::new(db, source_root, id)?; Def::Module(descr) } 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::{ pub(crate) use self::nameres::ModuleScope; -/// `ModuleDescriptor` is API entry point to get all the information +/// `Module` is API entry point to get all the information /// about a particular module. #[derive(Debug, Clone)] -pub(crate) struct ModuleDescriptor { +pub(crate) struct Module { tree: Arc, source_root_id: SourceRootId, module_id: ModuleId, } -impl ModuleDescriptor { - /// Lookup `ModuleDescriptor` by `FileId`. Note that this is inherently +impl Module { + /// Lookup `Module` by `FileId`. Note that this is inherently /// lossy transformation: in general, a single source might correspond to /// several modules. pub fn guess_from_file_id( db: &impl HirDatabase, file_id: FileId, - ) -> Cancelable> { - ModuleDescriptor::guess_from_source(db, file_id, ModuleSource::SourceFile(file_id)) + ) -> Cancelable> { + Module::guess_from_source(db, file_id, ModuleSource::SourceFile(file_id)) } - /// Lookup `ModuleDescriptor` by position in the source code. Note that this + /// Lookup `Module` by position in the source code. Note that this /// is inherently lossy transformation: in general, a single source might /// correspond to several modules. pub fn guess_from_position( db: &impl HirDatabase, position: FilePosition, - ) -> Cancelable> { + ) -> Cancelable> { let file = db.file_syntax(position.file_id); let module_source = match find_node_at_offset::(file.syntax(), position.offset) { Some(m) if !m.has_semi() => ModuleSource::new_inline(position.file_id, m), _ => ModuleSource::SourceFile(position.file_id), }; - ModuleDescriptor::guess_from_source(db, position.file_id, module_source) + Module::guess_from_source(db, position.file_id, module_source) } fn guess_from_source( db: &impl HirDatabase, file_id: FileId, module_source: ModuleSource, - ) -> Cancelable> { + ) -> Cancelable> { let source_root_id = db.file_source_root(file_id); let module_tree = db.module_tree(source_root_id)?; let res = match module_tree.any_module_for_source(module_source) { None => None, - Some(module_id) => Some(ModuleDescriptor { + Some(module_id) => Some(Module { tree: module_tree, source_root_id, module_id, @@ -81,9 +81,9 @@ impl ModuleDescriptor { db: &impl HirDatabase, source_root_id: SourceRootId, module_id: ModuleId, - ) -> Cancelable { + ) -> Cancelable { let module_tree = db.module_tree(source_root_id)?; - let res = ModuleDescriptor { + let res = Module { tree: module_tree, source_root_id, module_id, @@ -105,18 +105,18 @@ impl ModuleDescriptor { } /// Parent module. Returns `None` if this is a root module. - pub fn parent(&self) -> Option { + pub fn parent(&self) -> Option { let parent_id = self.module_id.parent(&self.tree)?; - Some(ModuleDescriptor { + Some(Module { module_id: parent_id, ..self.clone() }) } /// The root of the tree this module is part of - pub fn crate_root(&self) -> ModuleDescriptor { + pub fn crate_root(&self) -> Module { let root_id = self.module_id.crate_root(&self.tree); - ModuleDescriptor { + Module { module_id: root_id, ..self.clone() } @@ -138,9 +138,9 @@ impl ModuleDescriptor { } /// Finds a child module with the specified name. - pub fn child(&self, name: &str) -> Option { + pub fn child(&self, name: &str) -> Option { let child_id = self.module_id.child(&self.tree, name)?; - Some(ModuleDescriptor { + Some(Module { module_id: child_id, ..self.clone() }) @@ -168,7 +168,7 @@ impl ModuleDescriptor { let segments = path.segments; for name in segments.iter() { let module = match db.id_maps().def_loc(curr) { - DefLoc::Module { id, source_root } => ModuleDescriptor::new(db, source_root, id)?, + DefLoc::Module { id, source_root } => Module::new(db, source_root, id)?, _ => return Ok(None), }; 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::{ completion::{completions, CompletionItem}, db::{self, FileSyntaxQuery, SyntaxDatabase}, hir::{ - FunctionDescriptor, FnSignatureInfo, ModuleDescriptor, + self, + FunctionDescriptor, FnSignatureInfo, Problem, }, input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE}, @@ -226,7 +227,7 @@ impl AnalysisImpl { /// This return `Vec`: a module may be included from several places. We /// don't handle this case yet though, so the Vec has length at most one. pub fn parent_module(&self, position: FilePosition) -> Cancelable> { - let descr = match ModuleDescriptor::guess_from_position(&*self.db, position)? { + let descr = match hir::Module::guess_from_position(&*self.db, position)? { None => return Ok(Vec::new()), Some(it) => it, }; @@ -245,7 +246,7 @@ impl AnalysisImpl { } /// Returns `Vec` for the same reason as `parent_module` pub fn crate_for(&self, file_id: FileId) -> Cancelable> { - let descr = match ModuleDescriptor::guess_from_file_id(&*self.db, file_id)? { + let descr = match hir::Module::guess_from_file_id(&*self.db, file_id)? { None => return Ok(Vec::new()), Some(it) => it, }; @@ -298,7 +299,7 @@ impl AnalysisImpl { if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { if module.has_semi() { let parent_module = - ModuleDescriptor::guess_from_file_id(&*self.db, position.file_id)?; + hir::Module::guess_from_file_id(&*self.db, position.file_id)?; let child_name = module.name(); match (parent_module, child_name) { (Some(parent_module), Some(child_name)) => { @@ -380,7 +381,7 @@ impl AnalysisImpl { fix: None, }) .collect::>(); - if let Some(m) = ModuleDescriptor::guess_from_file_id(&*self.db, file_id)? { + if let Some(m) = hir::Module::guess_from_file_id(&*self.db, file_id)? { for (name_node, problem) in m.problems(&*self.db) { let diag = match problem { Problem::UnresolvedModule { candidate } => { -- cgit v1.2.3