mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
Auto merge of #15070 - Veykril:analysis-stat-stuff, r=Veykril
internal: Report metric timings for file item trees and crate def map creation
This commit is contained in:
commit
bc26e81cd5
7 changed files with 67 additions and 16 deletions
|
@ -1,12 +1,13 @@
|
|||
//! Provides set of implementation for hir's objects that allows get back location in file.
|
||||
|
||||
use base_db::FileId;
|
||||
use either::Either;
|
||||
use hir_def::{
|
||||
nameres::{ModuleOrigin, ModuleSource},
|
||||
src::{HasChildSource, HasSource as _},
|
||||
Lookup, MacroId, VariantId,
|
||||
};
|
||||
use hir_expand::InFile;
|
||||
use hir_expand::{HirFileId, InFile};
|
||||
use syntax::ast;
|
||||
|
||||
use crate::{
|
||||
|
@ -32,6 +33,11 @@ impl Module {
|
|||
def_map[self.id.local_id].definition_source(db.upcast())
|
||||
}
|
||||
|
||||
pub fn definition_source_file_id(self, db: &dyn HirDatabase) -> HirFileId {
|
||||
let def_map = self.id.def_map(db.upcast());
|
||||
def_map[self.id.local_id].definition_source_file_id()
|
||||
}
|
||||
|
||||
pub fn is_mod_rs(self, db: &dyn HirDatabase) -> bool {
|
||||
let def_map = self.id.def_map(db.upcast());
|
||||
match def_map[self.id.local_id].origin {
|
||||
|
@ -40,6 +46,16 @@ impl Module {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn as_source_file_id(self, db: &dyn HirDatabase) -> Option<FileId> {
|
||||
let def_map = self.id.def_map(db.upcast());
|
||||
match def_map[self.id.local_id].origin {
|
||||
ModuleOrigin::File { definition, .. } | ModuleOrigin::CrateRoot { definition, .. } => {
|
||||
Some(definition)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_inline(self, db: &dyn HirDatabase) -> bool {
|
||||
let def_map = self.id.def_map(db.upcast());
|
||||
def_map[self.id.local_id].origin.is_inline()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue