mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 19:53:46 +00:00
move submodule computationt to module_tree
This commit is contained in:
parent
17b2994b99
commit
733383446f
@ -1,2 +1,2 @@
|
||||
mod krate; // `crate` is invalid ident :(
|
||||
pub(crate) mod module;
|
||||
mod module;
|
||||
|
@ -73,7 +73,7 @@ pub trait HirDatabase: SyntaxDatabase
|
||||
|
||||
fn submodules(source: ModuleSource) -> Cancelable<Arc<Vec<crate::module_tree::Submodule>>> {
|
||||
type SubmodulesQuery;
|
||||
use fn query_definitions::submodules;
|
||||
use fn crate::module_tree::Submodule::submodules_query;
|
||||
}
|
||||
|
||||
fn input_module_items(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable<Arc<InputModuleItems>> {
|
||||
|
@ -20,6 +20,40 @@ pub enum Submodule {
|
||||
}
|
||||
|
||||
impl Submodule {
|
||||
pub(crate) fn submodules_query(
|
||||
db: &impl HirDatabase,
|
||||
source: ModuleSource,
|
||||
) -> Cancelable<Arc<Vec<Submodule>>> {
|
||||
db.check_canceled()?;
|
||||
let file_id = source.file_id();
|
||||
let submodules = match source.resolve(db) {
|
||||
ModuleSourceNode::SourceFile(it) => collect_submodules(db, file_id, it.borrowed()),
|
||||
ModuleSourceNode::Module(it) => it
|
||||
.borrowed()
|
||||
.item_list()
|
||||
.map(|it| collect_submodules(db, file_id, it))
|
||||
.unwrap_or_else(Vec::new),
|
||||
};
|
||||
return Ok(Arc::new(submodules));
|
||||
|
||||
fn collect_submodules<'a>(
|
||||
db: &impl HirDatabase,
|
||||
file_id: HirFileId,
|
||||
root: impl ast::ModuleItemOwner<'a>,
|
||||
) -> Vec<Submodule> {
|
||||
modules(root)
|
||||
.map(|(name, m)| {
|
||||
if m.has_semi() {
|
||||
Submodule::Declaration(name)
|
||||
} else {
|
||||
let src = ModuleSource::new_inline(db, file_id, m);
|
||||
Submodule::Definition(name, src)
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
fn name(&self) -> &Name {
|
||||
match self {
|
||||
Submodule::Declaration(name) => name,
|
||||
|
@ -6,16 +6,16 @@ use std::{
|
||||
use rustc_hash::FxHashMap;
|
||||
use ra_syntax::{
|
||||
AstNode, SyntaxNode,
|
||||
ast::{self, NameOwner, ModuleItemOwner}
|
||||
ast::{self, ModuleItemOwner}
|
||||
};
|
||||
use ra_db::{SourceRootId, Cancelable,};
|
||||
|
||||
use crate::{
|
||||
SourceFileItems, SourceItemId, DefKind, DefId, Name, AsName, HirFileId,
|
||||
SourceFileItems, SourceItemId, DefKind, DefId, HirFileId,
|
||||
MacroCallLoc,
|
||||
db::HirDatabase,
|
||||
function::FnScopes,
|
||||
module_tree::{ModuleId, Submodule, ModuleSource, ModuleSourceNode},
|
||||
module_tree::{ModuleId, ModuleSourceNode},
|
||||
nameres::{InputModuleItems, ItemMap, Resolver},
|
||||
adt::{StructData, EnumData},
|
||||
};
|
||||
@ -58,54 +58,6 @@ pub(super) fn file_item(db: &impl HirDatabase, source_item_id: SourceItemId) ->
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn submodules(
|
||||
db: &impl HirDatabase,
|
||||
source: ModuleSource,
|
||||
) -> Cancelable<Arc<Vec<Submodule>>> {
|
||||
db.check_canceled()?;
|
||||
let file_id = source.file_id();
|
||||
let submodules = match source.resolve(db) {
|
||||
ModuleSourceNode::SourceFile(it) => collect_submodules(db, file_id, it.borrowed()),
|
||||
ModuleSourceNode::Module(it) => it
|
||||
.borrowed()
|
||||
.item_list()
|
||||
.map(|it| collect_submodules(db, file_id, it))
|
||||
.unwrap_or_else(Vec::new),
|
||||
};
|
||||
return Ok(Arc::new(submodules));
|
||||
|
||||
fn collect_submodules<'a>(
|
||||
db: &impl HirDatabase,
|
||||
file_id: HirFileId,
|
||||
root: impl ast::ModuleItemOwner<'a>,
|
||||
) -> Vec<Submodule> {
|
||||
modules(root)
|
||||
.map(|(name, m)| {
|
||||
if m.has_semi() {
|
||||
Submodule::Declaration(name)
|
||||
} else {
|
||||
let src = ModuleSource::new_inline(db, file_id, m);
|
||||
Submodule::Definition(name, src)
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn modules<'a>(
|
||||
root: impl ast::ModuleItemOwner<'a>,
|
||||
) -> impl Iterator<Item = (Name, ast::Module<'a>)> {
|
||||
root.items()
|
||||
.filter_map(|item| match item {
|
||||
ast::ModuleItem::Module(m) => Some(m),
|
||||
_ => None,
|
||||
})
|
||||
.filter_map(|module| {
|
||||
let name = module.name()?.as_name();
|
||||
Some((name, module))
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn input_module_items(
|
||||
db: &impl HirDatabase,
|
||||
source_root_id: SourceRootId,
|
||||
|
Loading…
Reference in New Issue
Block a user