]> git.lizzy.rs Git - rust.git/commitdiff
Make `Attrs::from_attrs_owner` private
authorJonas Schievink <jonasschievink@gmail.com>
Thu, 17 Dec 2020 14:45:26 +0000 (15:45 +0100)
committerJonas Schievink <jonasschievink@gmail.com>
Thu, 17 Dec 2020 14:45:26 +0000 (15:45 +0100)
crates/hir/src/code_model.rs
crates/hir_def/src/attr.rs
crates/ide/src/display/navigation_target.rs
crates/ide/src/runnables.rs

index 84e8c8047bdeea7379795af96d9b1873d974a3ae..2c0e0eae04e026a156ac4a46e358c0dd95dc28bd 100644 (file)
@@ -1325,6 +1325,7 @@ pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option<InFile<ast::Attr>
         let item = src.file_id.is_builtin_derive(db.upcast())?;
         let hygenic = hir_expand::hygiene::Hygiene::new(db.upcast(), item.file_id);
 
+        // FIXME: handle `cfg_attr`
         let attr = item
             .value
             .attrs()
index c64b78445cc229824e2d7a7d8da3fd046a3f80ca..45313f3355933065be2cb00544538ef1aa72855c 100644 (file)
@@ -104,7 +104,7 @@ pub(crate) fn attrs_query(db: &dyn DefDatabase, def: AttrDefId) -> Attrs {
         }
     }
 
-    pub fn from_attrs_owner(db: &dyn DefDatabase, owner: InFile<&dyn AttrsOwner>) -> Attrs {
+    fn from_attrs_owner(db: &dyn DefDatabase, owner: InFile<&dyn AttrsOwner>) -> Attrs {
         let hygiene = Hygiene::new(db.upcast(), owner.file_id);
         Attrs::new(owner.value, &hygiene)
     }
index 54b33a98eacb99ee2c75ecc7b8b38ba3b7a7dc2e..8410bf5a25863f40334eaf8e54140b746ef24578 100644 (file)
@@ -1,9 +1,7 @@
 //! FIXME: write short doc here
 
 use either::Either;
-use hir::{
-    AssocItem, Documentation, FieldSource, HasAttrs, HasSource, HirFileId, InFile, ModuleSource,
-};
+use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource};
 use ide_db::base_db::{FileId, SourceDatabase};
 use ide_db::{defs::Definition, RootDatabase};
 use syntax::{
@@ -168,7 +166,7 @@ fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
             focus_range: self.name_range,
             container_name: self.container_name.clone(),
             description: description_from_symbol(db, self),
-            docs: docs_from_symbol(db, self),
+            docs: None,
         }
     }
 }
@@ -394,30 +392,6 @@ fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
     }
 }
 
-pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<Documentation> {
-    let parse = db.parse(symbol.file_id);
-    let node = symbol.ptr.to_node(parse.tree().syntax());
-    let file_id = HirFileId::from(symbol.file_id);
-
-    let it = match_ast! {
-        match node {
-            ast::Fn(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
-            ast::Struct(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
-            ast::Enum(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
-            ast::Trait(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
-            ast::Module(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
-            ast::TypeAlias(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
-            ast::Const(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
-            ast::Static(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
-            ast::RecordField(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
-            ast::Variant(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
-            ast::MacroCall(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
-            _ => return None,
-        }
-    };
-    it.docs()
-}
-
 /// Get a description of a symbol.
 ///
 /// e.g. `struct Name`, `enum Name`, `fn Name`
index 96462a7b0aa81c0490dbced973fae2da099ec475..a2a0ad43d36ca18cc1d9105f0f53f3256d510611 100644 (file)
@@ -2,7 +2,7 @@
 
 use assists::utils::test_related_attribute;
 use cfg::CfgExpr;
-use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics};
+use hir::{AsAssocItem, HasAttrs, InFile, Semantics};
 use ide_db::RootDatabase;
 use itertools::Itertools;
 use syntax::{
@@ -105,7 +105,7 @@ pub(crate) fn runnable(
         match item {
             ast::Struct(it) => runnable_struct(sema, it, file_id),
             ast::Fn(it) => runnable_fn(sema, it, file_id),
-            ast::Module(it) => runnable_mod(sema, it, file_id),
+            ast::Module(it) => runnable_mod(sema, it),
             _ => None,
         }
     }
@@ -116,9 +116,10 @@ fn runnable_fn(
     fn_def: ast::Fn,
     file_id: FileId,
 ) -> Option<Runnable> {
+    let def = sema.to_def(&fn_def)?;
     let name_string = fn_def.name()?.text().to_string();
 
-    let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &fn_def));
+    let attrs = def.attrs(sema.db);
     let kind = if name_string == "main" {
         RunnableKind::Bin
     } else {
@@ -189,10 +190,10 @@ fn runnable_struct(
     struct_def: ast::Struct,
     file_id: FileId,
 ) -> Option<Runnable> {
+    let def = sema.to_def(&struct_def)?;
     let name_string = struct_def.name()?.text().to_string();
 
-    let attrs =
-        Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &struct_def));
+    let attrs = def.attrs(sema.db);
     if !has_runnable_doc_test(&attrs) {
         return None;
     }
@@ -262,11 +263,7 @@ fn has_runnable_doc_test(attrs: &hir::Attrs) -> bool {
     })
 }
 
-fn runnable_mod(
-    sema: &Semantics<RootDatabase>,
-    module: ast::Module,
-    file_id: FileId,
-) -> Option<Runnable> {
+fn runnable_mod(sema: &Semantics<RootDatabase>, module: ast::Module) -> Option<Runnable> {
     if !has_test_function_or_multiple_test_submodules(&module) {
         return None;
     }
@@ -279,7 +276,8 @@ fn runnable_mod(
         .filter_map(|it| it.name(sema.db))
         .join("::");
 
-    let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &module));
+    let def = sema.to_def(&module)?;
+    let attrs = def.attrs(sema.db);
     let cfg = attrs.cfg();
     let nav = module_def.to_nav(sema.db);
     Some(Runnable { nav, kind: RunnableKind::TestMod { path }, cfg })