mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
rename ModuleDescriptor -> Module
This commit is contained in:
parent
16f67ee384
commit
36b1d20c16
5 changed files with 34 additions and 35 deletions
|
@ -11,9 +11,7 @@ use rustc_hash::{FxHashMap};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::{self, SyntaxDatabase},
|
db::{self, SyntaxDatabase},
|
||||||
hir::
|
hir,
|
||||||
ModuleDescriptor
|
|
||||||
,
|
|
||||||
Cancelable, FilePosition
|
Cancelable, FilePosition
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,7 +36,7 @@ pub(crate) fn completions(
|
||||||
original_file.reparse(&edit)
|
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 res = Vec::new();
|
||||||
let mut has_completions = false;
|
let mut has_completions = false;
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
db::RootDatabase,
|
db::RootDatabase,
|
||||||
completion::CompletionItem,
|
completion::CompletionItem,
|
||||||
hir::{
|
hir::{
|
||||||
ModuleDescriptor,
|
self,
|
||||||
FnScopes,
|
FnScopes,
|
||||||
Def,
|
Def,
|
||||||
Path,
|
Path,
|
||||||
|
@ -22,7 +22,7 @@ use crate::{
|
||||||
pub(super) fn completions(
|
pub(super) fn completions(
|
||||||
acc: &mut Vec<CompletionItem>,
|
acc: &mut Vec<CompletionItem>,
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
module: &ModuleDescriptor,
|
module: &hir::Module,
|
||||||
file: &SourceFileNode,
|
file: &SourceFileNode,
|
||||||
name_ref: ast::NameRef,
|
name_ref: ast::NameRef,
|
||||||
) -> Cancelable<()> {
|
) -> Cancelable<()> {
|
||||||
|
@ -150,7 +150,7 @@ fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<Completi
|
||||||
fn complete_path(
|
fn complete_path(
|
||||||
acc: &mut Vec<CompletionItem>,
|
acc: &mut Vec<CompletionItem>,
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
module: &ModuleDescriptor,
|
module: &hir::Module,
|
||||||
mut path: Path,
|
mut path: Path,
|
||||||
) -> Cancelable<()> {
|
) -> Cancelable<()> {
|
||||||
if path.segments.is_empty() {
|
if path.segments.is_empty() {
|
||||||
|
|
|
@ -19,14 +19,14 @@ use crate::{
|
||||||
|
|
||||||
pub(crate) use self::{
|
pub(crate) use self::{
|
||||||
path::{Path, PathKind},
|
path::{Path, PathKind},
|
||||||
module::{ModuleDescriptor, ModuleId, Problem, nameres::FileItemId},
|
module::{Module, ModuleId, Problem, nameres::FileItemId},
|
||||||
function::{FunctionDescriptor, FnScopes},
|
function::{FunctionDescriptor, FnScopes},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use self::function::FnSignatureInfo;
|
pub use self::function::FnSignatureInfo;
|
||||||
|
|
||||||
pub(crate) enum Def {
|
pub(crate) enum Def {
|
||||||
Module(ModuleDescriptor),
|
Module(Module),
|
||||||
Item,
|
Item,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ impl DefId {
|
||||||
let loc = db.id_maps().def_loc(self);
|
let loc = db.id_maps().def_loc(self);
|
||||||
let res = match loc {
|
let res = match loc {
|
||||||
DefLoc::Module { id, source_root } => {
|
DefLoc::Module { id, source_root } => {
|
||||||
let descr = ModuleDescriptor::new(db, source_root, id)?;
|
let descr = Module::new(db, source_root, id)?;
|
||||||
Def::Module(descr)
|
Def::Module(descr)
|
||||||
}
|
}
|
||||||
DefLoc::Item { .. } => Def::Item,
|
DefLoc::Item { .. } => Def::Item,
|
||||||
|
|
|
@ -22,53 +22,53 @@ use crate::{
|
||||||
|
|
||||||
pub(crate) use self::nameres::ModuleScope;
|
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.
|
/// about a particular module.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct ModuleDescriptor {
|
pub(crate) struct Module {
|
||||||
tree: Arc<ModuleTree>,
|
tree: Arc<ModuleTree>,
|
||||||
source_root_id: SourceRootId,
|
source_root_id: SourceRootId,
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleDescriptor {
|
impl Module {
|
||||||
/// Lookup `ModuleDescriptor` by `FileId`. Note that this is inherently
|
/// Lookup `Module` by `FileId`. Note that this is inherently
|
||||||
/// lossy transformation: in general, a single source might correspond to
|
/// lossy transformation: in general, a single source might correspond to
|
||||||
/// several modules.
|
/// several modules.
|
||||||
pub fn guess_from_file_id(
|
pub fn guess_from_file_id(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
) -> Cancelable<Option<ModuleDescriptor>> {
|
) -> Cancelable<Option<Module>> {
|
||||||
ModuleDescriptor::guess_from_source(db, file_id, ModuleSource::SourceFile(file_id))
|
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
|
/// is inherently lossy transformation: in general, a single source might
|
||||||
/// correspond to several modules.
|
/// correspond to several modules.
|
||||||
pub fn guess_from_position(
|
pub fn guess_from_position(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
position: FilePosition,
|
position: FilePosition,
|
||||||
) -> Cancelable<Option<ModuleDescriptor>> {
|
) -> Cancelable<Option<Module>> {
|
||||||
let file = db.file_syntax(position.file_id);
|
let file = db.file_syntax(position.file_id);
|
||||||
let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), position.offset)
|
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),
|
Some(m) if !m.has_semi() => ModuleSource::new_inline(position.file_id, m),
|
||||||
_ => ModuleSource::SourceFile(position.file_id),
|
_ => 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(
|
fn guess_from_source(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
module_source: ModuleSource,
|
module_source: ModuleSource,
|
||||||
) -> Cancelable<Option<ModuleDescriptor>> {
|
) -> Cancelable<Option<Module>> {
|
||||||
let source_root_id = db.file_source_root(file_id);
|
let source_root_id = db.file_source_root(file_id);
|
||||||
let module_tree = db.module_tree(source_root_id)?;
|
let module_tree = db.module_tree(source_root_id)?;
|
||||||
|
|
||||||
let res = match module_tree.any_module_for_source(module_source) {
|
let res = match module_tree.any_module_for_source(module_source) {
|
||||||
None => None,
|
None => None,
|
||||||
Some(module_id) => Some(ModuleDescriptor {
|
Some(module_id) => Some(Module {
|
||||||
tree: module_tree,
|
tree: module_tree,
|
||||||
source_root_id,
|
source_root_id,
|
||||||
module_id,
|
module_id,
|
||||||
|
@ -81,9 +81,9 @@ impl ModuleDescriptor {
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
source_root_id: SourceRootId,
|
source_root_id: SourceRootId,
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
) -> Cancelable<ModuleDescriptor> {
|
) -> Cancelable<Module> {
|
||||||
let module_tree = db.module_tree(source_root_id)?;
|
let module_tree = db.module_tree(source_root_id)?;
|
||||||
let res = ModuleDescriptor {
|
let res = Module {
|
||||||
tree: module_tree,
|
tree: module_tree,
|
||||||
source_root_id,
|
source_root_id,
|
||||||
module_id,
|
module_id,
|
||||||
|
@ -105,18 +105,18 @@ impl ModuleDescriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parent module. Returns `None` if this is a root module.
|
/// 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)?;
|
let parent_id = self.module_id.parent(&self.tree)?;
|
||||||
Some(ModuleDescriptor {
|
Some(Module {
|
||||||
module_id: parent_id,
|
module_id: parent_id,
|
||||||
..self.clone()
|
..self.clone()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The root of the tree this module is part of
|
/// 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);
|
let root_id = self.module_id.crate_root(&self.tree);
|
||||||
ModuleDescriptor {
|
Module {
|
||||||
module_id: root_id,
|
module_id: root_id,
|
||||||
..self.clone()
|
..self.clone()
|
||||||
}
|
}
|
||||||
|
@ -138,9 +138,9 @@ impl ModuleDescriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds a child module with the specified name.
|
/// 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)?;
|
let child_id = self.module_id.child(&self.tree, name)?;
|
||||||
Some(ModuleDescriptor {
|
Some(Module {
|
||||||
module_id: child_id,
|
module_id: child_id,
|
||||||
..self.clone()
|
..self.clone()
|
||||||
})
|
})
|
||||||
|
@ -168,7 +168,7 @@ impl ModuleDescriptor {
|
||||||
let segments = path.segments;
|
let segments = path.segments;
|
||||||
for name in segments.iter() {
|
for name in segments.iter() {
|
||||||
let module = match db.id_maps().def_loc(curr) {
|
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),
|
_ => return Ok(None),
|
||||||
};
|
};
|
||||||
let scope = module.scope(db)?;
|
let scope = module.scope(db)?;
|
||||||
|
|
|
@ -20,7 +20,8 @@ use crate::{
|
||||||
completion::{completions, CompletionItem},
|
completion::{completions, CompletionItem},
|
||||||
db::{self, FileSyntaxQuery, SyntaxDatabase},
|
db::{self, FileSyntaxQuery, SyntaxDatabase},
|
||||||
hir::{
|
hir::{
|
||||||
FunctionDescriptor, FnSignatureInfo, ModuleDescriptor,
|
self,
|
||||||
|
FunctionDescriptor, FnSignatureInfo,
|
||||||
Problem,
|
Problem,
|
||||||
},
|
},
|
||||||
input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE},
|
input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE},
|
||||||
|
@ -226,7 +227,7 @@ impl AnalysisImpl {
|
||||||
/// This return `Vec`: a module may be included from several places. We
|
/// 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.
|
/// 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)>> {
|
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()),
|
None => return Ok(Vec::new()),
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
};
|
};
|
||||||
|
@ -245,7 +246,7 @@ impl AnalysisImpl {
|
||||||
}
|
}
|
||||||
/// Returns `Vec` for the same reason as `parent_module`
|
/// Returns `Vec` for the same reason as `parent_module`
|
||||||
pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
|
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()),
|
None => return Ok(Vec::new()),
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
};
|
};
|
||||||
|
@ -298,7 +299,7 @@ impl AnalysisImpl {
|
||||||
if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
|
if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
|
||||||
if module.has_semi() {
|
if module.has_semi() {
|
||||||
let parent_module =
|
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();
|
let child_name = module.name();
|
||||||
match (parent_module, child_name) {
|
match (parent_module, child_name) {
|
||||||
(Some(parent_module), Some(child_name)) => {
|
(Some(parent_module), Some(child_name)) => {
|
||||||
|
@ -380,7 +381,7 @@ impl AnalysisImpl {
|
||||||
fix: None,
|
fix: None,
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.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) {
|
for (name_node, problem) in m.problems(&*self.db) {
|
||||||
let diag = match problem {
|
let diag = match problem {
|
||||||
Problem::UnresolvedModule { candidate } => {
|
Problem::UnresolvedModule { candidate } => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue