diff options
Diffstat (limited to 'crates/ra_hir/src/from_source.rs')
-rw-r--r-- | crates/ra_hir/src/from_source.rs | 25 |
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 { | |||
79 | impl FromSource for Const { | 79 | impl 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 | } |
86 | impl FromSource for Static { | 105 | impl 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. |
297 | fn same_source<N: AstNode>(s1: &Source<N>, s2: &Source<N>) -> bool { | 316 | fn 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) |