aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model.rs2
-rw-r--r--crates/ra_hir/src/code_model/src.rs2
-rw-r--r--crates/ra_hir/src/from_source.rs19
-rw-r--r--crates/ra_hir/src/source_binder.rs12
-rw-r--r--crates/ra_hir/src/ty/tests.rs2
5 files changed, 22 insertions, 15 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 36ea8d8bf..905bb5bcb 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -734,7 +734,7 @@ pub struct Static {
734 734
735impl Static { 735impl Static {
736 pub fn module(self, db: &impl DefDatabase) -> Module { 736 pub fn module(self, db: &impl DefDatabase) -> Module {
737 Module { id: self.id.module(db) } 737 Module { id: self.id.lookup(db).module(db) }
738 } 738 }
739 739
740 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { 740 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index 59cda2e89..b9d21bdd7 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -88,7 +88,7 @@ impl HasSource for Const {
88impl HasSource for Static { 88impl HasSource for Static {
89 type Ast = ast::StaticDef; 89 type Ast = ast::StaticDef;
90 fn source(self, db: &impl DefDatabase) -> Source<ast::StaticDef> { 90 fn source(self, db: &impl DefDatabase) -> Source<ast::StaticDef> {
91 self.id.source(db) 91 self.id.lookup(db).source(db)
92 } 92 }
93} 93}
94impl HasSource for Trait { 94impl HasSource for Trait {
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index c3c3b05ed..f506bba70 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -104,10 +104,21 @@ impl FromSource for Const {
104impl FromSource for Static { 104impl FromSource for Static {
105 type Ast = ast::StaticDef; 105 type Ast = ast::StaticDef;
106 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 106 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
107 let id = from_source(db, src)?; 107 let module = match Container::find(db, src.as_ref().map(|it| it.syntax()))? {
108 Some(Static { id }) 108 Container::Module(it) => it,
109 Container::Trait(_) | Container::ImplBlock(_) => return None,
110 };
111 module
112 .declarations(db)
113 .into_iter()
114 .filter_map(|it| match it {
115 ModuleDef::Static(it) => Some(it),
116 _ => None,
117 })
118 .find(|it| same_source(&it.source(db), &src))
109 } 119 }
110} 120}
121
111impl FromSource for TypeAlias { 122impl FromSource for TypeAlias {
112 type Ast = ast::TypeAliasDef; 123 type Ast = ast::TypeAliasDef;
113 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 124 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
@@ -271,7 +282,9 @@ where
271 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); 282 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
272 let module = Module::from_definition(db, Source::new(src.file_id, module_src))?; 283 let module = Module::from_definition(db, Source::new(src.file_id, module_src))?;
273 let ctx = LocationCtx::new(db, module.id, src.file_id); 284 let ctx = LocationCtx::new(db, module.id, src.file_id);
274 Some(DEF::from_ast(ctx, &src.value)) 285 let items = db.ast_id_map(src.file_id);
286 let item_id = items.ast_id(&src.value);
287 Some(DEF::from_ast_id(ctx, item_id))
275} 288}
276 289
277enum Container { 290enum Container {
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 0a836c913..cfc4bd326 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -11,7 +11,7 @@ use hir_def::{
11 expr::{ExprId, PatId}, 11 expr::{ExprId, PatId},
12 path::known, 12 path::known,
13 resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs}, 13 resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs},
14 DefWithBodyId, LocationCtx, 14 DefWithBodyId,
15}; 15};
16use hir_expand::{ 16use hir_expand::{
17 name::AsName, AstId, HirFileId, MacroCallId, MacroCallLoc, MacroFileKind, Source, 17 name::AsName, AstId, HirFileId, MacroCallId, MacroCallLoc, MacroFileKind, Source,
@@ -28,8 +28,8 @@ use crate::{
28 expr::{BodySourceMap, ExprScopes, ScopeId}, 28 expr::{BodySourceMap, ExprScopes, ScopeId},
29 ty::method_resolution::{self, implements_trait}, 29 ty::method_resolution::{self, implements_trait},
30 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function, 30 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function,
31 GenericParam, HasBody, Local, MacroDef, Module, Name, Path, ScopeDef, Static, Struct, Trait, 31 GenericParam, HasBody, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Ty,
32 Ty, TypeAlias, 32 TypeAlias,
33}; 33};
34 34
35fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> { 35fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> {
@@ -68,16 +68,12 @@ fn def_with_body_from_child_node(
68 db: &impl HirDatabase, 68 db: &impl HirDatabase,
69 child: Source<&SyntaxNode>, 69 child: Source<&SyntaxNode>,
70) -> Option<DefWithBody> { 70) -> Option<DefWithBody> {
71 let module_source = crate::ModuleSource::from_child_node(db, child);
72 let module = Module::from_definition(db, Source::new(child.file_id, module_source))?;
73 let ctx = LocationCtx::new(db, module.id, child.file_id);
74
75 child.value.ancestors().find_map(|node| { 71 child.value.ancestors().find_map(|node| {
76 match_ast! { 72 match_ast! {
77 match node { 73 match node {
78 ast::FnDef(def) => { return Function::from_source(db, child.with_value(def)).map(DefWithBody::from); }, 74 ast::FnDef(def) => { return Function::from_source(db, child.with_value(def)).map(DefWithBody::from); },
79 ast::ConstDef(def) => { return Const::from_source(db, child.with_value(def)).map(DefWithBody::from); }, 75 ast::ConstDef(def) => { return Const::from_source(db, child.with_value(def)).map(DefWithBody::from); },
80 ast::StaticDef(def) => { Some(Static { id: ctx.to_def(&def) }.into()) }, 76 ast::StaticDef(def) => { return Static::from_source(db, child.with_value(def)).map(DefWithBody::from); },
81 _ => { None }, 77 _ => { None },
82 } 78 }
83 } 79 }
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 17a50cf74..3209c66bd 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -2550,8 +2550,6 @@ fn test() {
2550 [233; 246) 'GLOBAL_STATIC': u32 2550 [233; 246) 'GLOBAL_STATIC': u32
2551 [256; 257) 'w': u32 2551 [256; 257) 'w': u32
2552 [260; 277) 'GLOBAL...IC_MUT': u32 2552 [260; 277) 'GLOBAL...IC_MUT': u32
2553 [118; 120) '99': u32
2554 [161; 163) '99': u32
2555 "### 2553 "###
2556 ); 2554 );
2557} 2555}