]> git.lizzy.rs Git - rust.git/commitdiff
Clean up implementation
authorBrandon <brandondong604@hotmail.com>
Wed, 24 Mar 2021 07:47:55 +0000 (00:47 -0700)
committerBrandon <brandondong604@hotmail.com>
Wed, 24 Mar 2021 07:47:55 +0000 (00:47 -0700)
crates/hir_expand/src/lib.rs
crates/ide/src/annotations.rs

index d7391ebadeb7ca148ef6eda4a9bcdfe5f4dcac3b..b8045fda95cb53016c7b4a16ec6b0fcb27a048b4 100644 (file)
@@ -207,13 +207,6 @@ pub fn is_include_macro(&self, db: &dyn db::AstDatabase) -> bool {
         }
         false
     }
-
-    pub fn is_macro_file(&self) -> bool {
-        match self.0 {
-            HirFileIdRepr::MacroFile(_) => true,
-            HirFileIdRepr::FileId(_) => false,
-        }
-    }
 }
 
 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
index 9e78ed6a0eecc273f804953d56328565fa5127e9..64bc926f1c612b2ea53d612d4e827a0578e4a853 100644 (file)
@@ -80,19 +80,19 @@ pub(crate) fn annotations(
         Either::Left(def) => {
             let node = match def {
                 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_) => {
-                    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)) => {
-                    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_)) => {
-                    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)) => {
-                    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,
             };
@@ -122,9 +122,10 @@ pub(crate) fn annotations(
 
             fn range_and_position_of<T: NameOwner>(
                 node: &InFile<T>,
+                file_id: FileId,
             ) -> Option<(TextSize, TextRange)> {
-                if node.file_id.is_macro_file() {
-                    // Macro generated files should not contain annotations.
+                if node.file_id != file_id.into() {
+                    // Node is outside the file we are adding annotations to (e.g. macros).
                     None
                 } else {
                     Some((