Clean up implementation

This commit is contained in:
Brandon 2021-03-24 00:47:55 -07:00
parent 0d063b8d21
commit 903a2e98f9
2 changed files with 8 additions and 14 deletions

View file

@ -207,13 +207,6 @@ impl HirFileId {
} }
false false
} }
pub fn is_macro_file(&self) -> bool {
match self.0 {
HirFileIdRepr::MacroFile(_) => true,
HirFileIdRepr::FileId(_) => false,
}
}
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

View file

@ -80,19 +80,19 @@ pub(crate) fn annotations(
Either::Left(def) => { Either::Left(def) => {
let node = match def { let node = match def {
hir::ModuleDef::Const(konst) => { hir::ModuleDef::Const(konst) => {
konst.source(db).and_then(|node| range_and_position_of(&node)) konst.source(db).and_then(|node| range_and_position_of(&node, file_id))
} }
hir::ModuleDef::Trait(trait_) => { hir::ModuleDef::Trait(trait_) => {
trait_.source(db).and_then(|node| range_and_position_of(&node)) trait_.source(db).and_then(|node| range_and_position_of(&node, file_id))
} }
hir::ModuleDef::Adt(hir::Adt::Struct(strukt)) => { hir::ModuleDef::Adt(hir::Adt::Struct(strukt)) => {
strukt.source(db).and_then(|node| range_and_position_of(&node)) strukt.source(db).and_then(|node| range_and_position_of(&node, file_id))
} }
hir::ModuleDef::Adt(hir::Adt::Enum(enum_)) => { hir::ModuleDef::Adt(hir::Adt::Enum(enum_)) => {
enum_.source(db).and_then(|node| range_and_position_of(&node)) enum_.source(db).and_then(|node| range_and_position_of(&node, file_id))
} }
hir::ModuleDef::Adt(hir::Adt::Union(union)) => { hir::ModuleDef::Adt(hir::Adt::Union(union)) => {
union.source(db).and_then(|node| range_and_position_of(&node)) union.source(db).and_then(|node| range_and_position_of(&node, file_id))
} }
_ => None, _ => None,
}; };
@ -122,9 +122,10 @@ pub(crate) fn annotations(
fn range_and_position_of<T: NameOwner>( fn range_and_position_of<T: NameOwner>(
node: &InFile<T>, node: &InFile<T>,
file_id: FileId,
) -> Option<(TextSize, TextRange)> { ) -> Option<(TextSize, TextRange)> {
if node.file_id.is_macro_file() { if node.file_id != file_id.into() {
// Macro generated files should not contain annotations. // Node is outside the file we are adding annotations to (e.g. macros).
None None
} else { } else {
Some(( Some((