aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/code_model/attrs.rs25
-rw-r--r--crates/ra_hir/src/db.rs4
-rw-r--r--crates/ra_hir/src/lib.rs2
3 files changed, 15 insertions, 16 deletions
diff --git a/crates/ra_hir/src/code_model/attrs.rs b/crates/ra_hir/src/code_model/attrs.rs
index 9e304217c..96da8c88c 100644
--- a/crates/ra_hir/src/code_model/attrs.rs
+++ b/crates/ra_hir/src/code_model/attrs.rs
@@ -5,10 +5,9 @@ use crate::{
5 Adt, Const, Enum, EnumVariant, FieldSource, Function, HasSource, MacroDef, Module, Static, 5 Adt, Const, Enum, EnumVariant, FieldSource, Function, HasSource, MacroDef, Module, Static,
6 Struct, StructField, Trait, TypeAlias, Union, 6 Struct, StructField, Trait, TypeAlias, Union,
7}; 7};
8use hir_def::attr::Attr; 8use hir_def::attr::{Attr, Attrs};
9use hir_expand::hygiene::Hygiene; 9use hir_expand::hygiene::Hygiene;
10use ra_syntax::ast; 10use ra_syntax::ast;
11use std::sync::Arc;
12 11
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 12#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
14pub enum AttrDef { 13pub enum AttrDef {
@@ -37,17 +36,17 @@ impl_froms!(
37 MacroDef 36 MacroDef
38); 37);
39 38
40pub trait Attrs { 39pub trait HasAttrs {
41 fn attrs(&self, db: &impl HirDatabase) -> Option<Arc<[Attr]>>; 40 fn attrs(&self, db: &impl HirDatabase) -> Attrs;
42} 41}
43 42
44pub(crate) fn attributes_query( 43pub(crate) fn attributes_query(db: &(impl DefDatabase + AstDatabase), def: AttrDef) -> Attrs {
45 db: &(impl DefDatabase + AstDatabase),
46 def: AttrDef,
47) -> Option<Arc<[Attr]>> {
48 match def { 44 match def {
49 AttrDef::Module(it) => { 45 AttrDef::Module(it) => {
50 let src = it.declaration_source(db)?; 46 let src = match it.declaration_source(db) {
47 Some(it) => it,
48 None => return Attrs::default(),
49 };
51 let hygiene = Hygiene::new(db, src.file_id); 50 let hygiene = Hygiene::new(db, src.file_id);
52 Attr::from_attrs_owner(&src.value, &hygiene) 51 Attr::from_attrs_owner(&src.value, &hygiene)
53 } 52 }
@@ -57,7 +56,7 @@ pub(crate) fn attributes_query(
57 let hygiene = Hygiene::new(db, src.file_id); 56 let hygiene = Hygiene::new(db, src.file_id);
58 Attr::from_attrs_owner(&named, &hygiene) 57 Attr::from_attrs_owner(&named, &hygiene)
59 } 58 }
60 FieldSource::Pos(..) => None, 59 FieldSource::Pos(..) => Attrs::default(),
61 }, 60 },
62 AttrDef::Adt(it) => match it { 61 AttrDef::Adt(it) => match it {
63 Adt::Struct(it) => attrs_from_ast(it, db), 62 Adt::Struct(it) => attrs_from_ast(it, db),
@@ -74,7 +73,7 @@ pub(crate) fn attributes_query(
74 } 73 }
75} 74}
76 75
77fn attrs_from_ast<T, D>(node: T, db: &D) -> Option<Arc<[Attr]>> 76fn attrs_from_ast<T, D>(node: T, db: &D) -> Attrs
78where 77where
79 T: HasSource, 78 T: HasSource,
80 T::Ast: ast::AttrsOwner, 79 T::Ast: ast::AttrsOwner,
@@ -85,8 +84,8 @@ where
85 Attr::from_attrs_owner(&src.value, &hygiene) 84 Attr::from_attrs_owner(&src.value, &hygiene)
86} 85}
87 86
88impl<T: Into<AttrDef> + Copy> Attrs for T { 87impl<T: Into<AttrDef> + Copy> HasAttrs for T {
89 fn attrs(&self, db: &impl HirDatabase) -> Option<Arc<[Attr]>> { 88 fn attrs(&self, db: &impl HirDatabase) -> Attrs {
90 db.attrs((*self).into()) 89 db.attrs((*self).into())
91 } 90 }
92} 91}
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 689874331..1cfcb2fd2 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -2,7 +2,7 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_def::attr::Attr; 5use hir_def::attr::Attrs;
6use ra_db::salsa; 6use ra_db::salsa;
7use ra_syntax::SmolStr; 7use ra_syntax::SmolStr;
8 8
@@ -57,7 +57,7 @@ pub trait DefDatabase: HirDebugDatabase + DefDatabase2 {
57 fn documentation(&self, def: crate::DocDef) -> Option<crate::Documentation>; 57 fn documentation(&self, def: crate::DocDef) -> Option<crate::Documentation>;
58 58
59 #[salsa::invoke(crate::code_model::attrs::attributes_query)] 59 #[salsa::invoke(crate::code_model::attrs::attributes_query)]
60 fn attrs(&self, def: crate::AttrDef) -> Option<Arc<[Attr]>>; 60 fn attrs(&self, def: crate::AttrDef) -> Attrs;
61} 61}
62 62
63#[salsa::query_group(HirDatabaseStorage)] 63#[salsa::query_group(HirDatabaseStorage)]
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 8e532c36c..8535629ca 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -51,7 +51,7 @@ mod marks;
51 51
52pub use crate::{ 52pub use crate::{
53 code_model::{ 53 code_model::{
54 attrs::{AttrDef, Attrs}, 54 attrs::{AttrDef, HasAttrs},
55 docs::{DocDef, Docs, Documentation}, 55 docs::{DocDef, Docs, Documentation},
56 src::{HasBodySource, HasSource}, 56 src::{HasBodySource, HasSource},
57 Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, 57 Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,