2018-11-28 00:42:26 +00:00
|
|
|
use std::{
|
|
|
|
sync::Arc,
|
|
|
|
time::Instant,
|
|
|
|
};
|
|
|
|
|
|
|
|
use rustc_hash::FxHashMap;
|
|
|
|
use ra_syntax::{
|
2019-01-11 16:59:06 +00:00
|
|
|
AstNode, SyntaxNode, TreeArc,
|
2018-11-28 00:42:26 +00:00
|
|
|
};
|
2019-01-15 16:15:01 +00:00
|
|
|
use ra_db::SourceRootId;
|
2018-11-28 00:42:26 +00:00
|
|
|
|
|
|
|
use crate::{
|
2019-01-18 11:34:13 +00:00
|
|
|
SourceFileItems, SourceItemId, DefId, HirFileId,
|
|
|
|
FnScopes,
|
2018-12-04 20:44:00 +00:00
|
|
|
db::HirDatabase,
|
2019-01-18 11:34:13 +00:00
|
|
|
nameres::{ItemMap, Resolver},
|
2018-11-28 00:42:26 +00:00
|
|
|
};
|
|
|
|
|
2019-01-15 16:04:49 +00:00
|
|
|
pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Arc<FnScopes> {
|
2019-01-15 16:01:59 +00:00
|
|
|
let body = db.body_hir(def_id);
|
2019-01-05 21:37:59 +00:00
|
|
|
let res = FnScopes::new(body);
|
2019-01-15 16:04:49 +00:00
|
|
|
Arc::new(res)
|
2018-11-28 00:42:26 +00:00
|
|
|
}
|
|
|
|
|
2019-01-01 20:21:16 +00:00
|
|
|
pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> {
|
|
|
|
let source_file = db.hir_source_file(file_id);
|
2019-01-08 08:28:42 +00:00
|
|
|
let res = SourceFileItems::new(file_id, &source_file);
|
2018-11-28 00:42:26 +00:00
|
|
|
Arc::new(res)
|
|
|
|
}
|
|
|
|
|
2019-01-08 08:28:42 +00:00
|
|
|
pub(super) fn file_item(
|
|
|
|
db: &impl HirDatabase,
|
|
|
|
source_item_id: SourceItemId,
|
2019-01-11 16:59:06 +00:00
|
|
|
) -> TreeArc<SyntaxNode> {
|
2018-12-18 22:48:46 +00:00
|
|
|
match source_item_id.item_id {
|
2019-01-08 08:28:42 +00:00
|
|
|
Some(id) => db.file_items(source_item_id.file_id)[id].to_owned(),
|
|
|
|
None => db
|
|
|
|
.hir_source_file(source_item_id.file_id)
|
|
|
|
.syntax()
|
|
|
|
.to_owned(),
|
2018-12-18 22:48:46 +00:00
|
|
|
}
|
2018-11-28 00:42:26 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 16:15:01 +00:00
|
|
|
pub(super) fn item_map(db: &impl HirDatabase, source_root: SourceRootId) -> Arc<ItemMap> {
|
2018-11-28 00:42:26 +00:00
|
|
|
let start = Instant::now();
|
2019-01-15 14:55:15 +00:00
|
|
|
let module_tree = db.module_tree(source_root);
|
2018-11-28 00:42:26 +00:00
|
|
|
let input = module_tree
|
|
|
|
.modules()
|
2019-01-18 13:36:56 +00:00
|
|
|
.map(|id| (id, db.lower_module_module(source_root, id)))
|
2019-01-15 15:13:11 +00:00
|
|
|
.collect::<FxHashMap<_, _>>();
|
2018-12-09 09:24:52 +00:00
|
|
|
|
|
|
|
let resolver = Resolver::new(db, &input, source_root, module_tree);
|
2019-01-15 16:15:01 +00:00
|
|
|
let res = resolver.resolve();
|
2018-11-28 00:42:26 +00:00
|
|
|
let elapsed = start.elapsed();
|
|
|
|
log::info!("item_map: {:?}", elapsed);
|
2019-01-15 16:15:01 +00:00
|
|
|
Arc::new(res)
|
2018-11-28 00:42:26 +00:00
|
|
|
}
|