internal: Improve rooted upmapping

This commit is contained in:
Lukas Wirth 2024-03-12 13:24:52 +01:00
parent 03d2d9016d
commit 9ba4493918
24 changed files with 231 additions and 153 deletions

View file

@ -9,6 +9,7 @@ use hir_def::{
};
use hir_expand::{HirFileId, InFile};
use syntax::ast;
use tt::TextRange;
use crate::{
db::HirDatabase, Adt, Const, Enum, ExternCrateDecl, Field, FieldSource, Function, Impl,
@ -37,6 +38,12 @@ impl Module {
def_map[self.id.local_id].definition_source(db.upcast())
}
/// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
pub fn definition_source_range(self, db: &dyn HirDatabase) -> InFile<TextRange> {
let def_map = self.id.def_map(db.upcast());
def_map[self.id.local_id].definition_source_range(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()
@ -71,6 +78,13 @@ impl Module {
let def_map = self.id.def_map(db.upcast());
def_map[self.id.local_id].declaration_source(db.upcast())
}
/// Returns a text range which declares this module, either a `mod foo;` or a `mod foo {}`.
/// `None` for the crate root.
pub fn declaration_source_range(self, db: &dyn HirDatabase) -> Option<InFile<TextRange>> {
let def_map = self.id.def_map(db.upcast());
def_map[self.id.local_id].declaration_source_range(db.upcast())
}
}
impl HasSource for Field {