rename ModuleDescriptor -> Module
This commit is contained in:
parent
16f67ee384
commit
36b1d20c16
@ -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;
|
||||
|
@ -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<CompletionItem>,
|
||||
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<Completi
|
||||
fn complete_path(
|
||||
acc: &mut Vec<CompletionItem>,
|
||||
db: &RootDatabase,
|
||||
module: &ModuleDescriptor,
|
||||
module: &hir::Module,
|
||||
mut path: Path,
|
||||
) -> Cancelable<()> {
|
||||
if path.segments.is_empty() {
|
||||
|
@ -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,
|
||||
|
@ -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<ModuleTree>,
|
||||
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<Option<ModuleDescriptor>> {
|
||||
ModuleDescriptor::guess_from_source(db, file_id, ModuleSource::SourceFile(file_id))
|
||||
) -> Cancelable<Option<Module>> {
|
||||
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<Option<ModuleDescriptor>> {
|
||||
) -> Cancelable<Option<Module>> {
|
||||
let file = db.file_syntax(position.file_id);
|
||||
let module_source = match find_node_at_offset::<ast::Module>(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<Option<ModuleDescriptor>> {
|
||||
) -> Cancelable<Option<Module>> {
|
||||
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<ModuleDescriptor> {
|
||||
) -> Cancelable<Module> {
|
||||
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<ModuleDescriptor> {
|
||||
pub fn parent(&self) -> Option<Module> {
|
||||
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<ModuleDescriptor> {
|
||||
pub fn child(&self, name: &str) -> Option<Module> {
|
||||
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)?;
|
||||
|
@ -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<Vec<(FileId, FileSymbol)>> {
|
||||
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<Vec<CrateId>> {
|
||||
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::<Vec<_>>();
|
||||
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 } => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user