Less eager parsing for module sources

This commit is contained in:
Lukas Wirth 2023-06-17 10:58:52 +02:00
parent b5e0452c71
commit 58ac823864
7 changed files with 37 additions and 12 deletions

View file

@ -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()