aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/from_source.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-20 15:00:01 +0000
committerAleksey Kladov <[email protected]>2019-11-20 15:41:23 +0000
commit111891dc2dc1d2c7ea87144e8e3ddefe23fc7b6d (patch)
tree7e96d773620a3b03254d00386711cdc7c909e3ee /crates/ra_hir/src/from_source.rs
parentee95a35664e6fe9153f6324cfc57872ca365887c (diff)
Move constants to new ID
This allows us to get rid of trait item index
Diffstat (limited to 'crates/ra_hir/src/from_source.rs')
-rw-r--r--crates/ra_hir/src/from_source.rs25
1 files changed, 22 insertions, 3 deletions
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index f5fdaafa3..b86307c58 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -79,8 +79,27 @@ impl FromSource for Function {
79impl FromSource for Const { 79impl FromSource for Const {
80 type Ast = ast::ConstDef; 80 type Ast = ast::ConstDef;
81 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 81 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
82 let id = from_source(db, src)?; 82 let items = match Container::find(db, src.as_ref().map(|it| it.syntax()))? {
83 Some(Const { id }) 83 Container::Trait(it) => it.items(db),
84 Container::ImplBlock(it) => it.items(db),
85 Container::Module(m) => {
86 return m
87 .declarations(db)
88 .into_iter()
89 .filter_map(|it| match it {
90 ModuleDef::Const(it) => Some(it),
91 _ => None,
92 })
93 .find(|it| same_source(&it.source(db), &src))
94 }
95 };
96 items
97 .into_iter()
98 .filter_map(|it| match it {
99 AssocItem::Const(it) => Some(it),
100 _ => None,
101 })
102 .find(|it| same_source(&it.source(db), &src))
84 } 103 }
85} 104}
86impl FromSource for Static { 105impl FromSource for Static {
@@ -292,7 +311,7 @@ impl Container {
292/// equal if they point to exactly the same object. 311/// equal if they point to exactly the same object.
293/// 312///
294/// In general, we do not guarantee that we have exactly one instance of a 313/// In general, we do not guarantee that we have exactly one instance of a
295/// syntax tree for each file. We probably should add such guanratree, but, for 314/// syntax tree for each file. We probably should add such guarantee, but, for
296/// the time being, we will use identity-less AstPtr comparison. 315/// the time being, we will use identity-less AstPtr comparison.
297fn same_source<N: AstNode>(s1: &Source<N>, s2: &Source<N>) -> bool { 316fn same_source<N: AstNode>(s1: &Source<N>, s2: &Source<N>) -> bool {
298 s1.as_ref().map(AstPtr::new) == s2.as_ref().map(AstPtr::new) 317 s1.as_ref().map(AstPtr::new) == s2.as_ref().map(AstPtr::new)