aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/resolve.rs3
-rw-r--r--crates/ra_hir/src/source_binder.rs21
2 files changed, 18 insertions, 6 deletions
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index 7929e8b7c..6c87d0df7 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -46,7 +46,6 @@ pub(crate) enum Scope {
46 46
47#[derive(Debug, Clone, PartialEq, Eq)] 47#[derive(Debug, Clone, PartialEq, Eq)]
48pub enum Resolution { 48pub enum Resolution {
49 // FIXME make these tuple variants
50 /// An item 49 /// An item
51 Def(ModuleDef), 50 Def(ModuleDef),
52 /// A local binding (only value namespace) 51 /// A local binding (only value namespace)
@@ -85,7 +84,7 @@ impl Resolver {
85 84
86 pub fn all_names(&self) -> FxHashMap<Name, PerNs<Resolution>> { 85 pub fn all_names(&self) -> FxHashMap<Name, PerNs<Resolution>> {
87 let mut names = FxHashMap::default(); 86 let mut names = FxHashMap::default();
88 for scope in &self.scopes { 87 for scope in self.scopes.iter().rev() {
89 scope.collect_names(&mut |name, res| { 88 scope.collect_names(&mut |name, res| {
90 let current: &mut PerNs<Resolution> = names.entry(name).or_default(); 89 let current: &mut PerNs<Resolution> = names.entry(name).or_default();
91 if current.types.is_none() { 90 if current.types.is_none() {
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index ce929cf3e..59f782277 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -204,12 +204,13 @@ pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, Te
204} 204}
205 205
206pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> Resolver { 206pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> Resolver {
207 let file = db.parse(position.file_id); 207 let file_id = position.file_id;
208 let file = db.parse(file_id);
208 find_leaf_at_offset(file.syntax(), position.offset) 209 find_leaf_at_offset(file.syntax(), position.offset)
209 .find_map(|node| { 210 .find_map(|node| {
210 node.ancestors().find_map(|node| { 211 node.ancestors().find_map(|node| {
211 if ast::Expr::cast(node).is_some() || ast::Block::cast(node).is_some() { 212 if ast::Expr::cast(node).is_some() || ast::Block::cast(node).is_some() {
212 if let Some(func) = function_from_child_node(db, position.file_id, node) { 213 if let Some(func) = function_from_child_node(db, file_id, node) {
213 let scopes = func.scopes(db); 214 let scopes = func.scopes(db);
214 let scope = scopes.scope_for_offset(position.offset); 215 let scope = scopes.scope_for_offset(position.offset);
215 Some(expr::resolver_for_scope(func.body(db), db, scope)) 216 Some(expr::resolver_for_scope(func.body(db), db, scope))
@@ -218,9 +219,15 @@ pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> R
218 None 219 None
219 } 220 }
220 } else if let Some(module) = ast::Module::cast(node) { 221 } else if let Some(module) = ast::Module::cast(node) {
221 Some(module_from_declaration(db, position.file_id, module)?.resolver(db)) 222 Some(module_from_declaration(db, file_id, module)?.resolver(db))
222 } else if let Some(_) = ast::SourceFile::cast(node) { 223 } else if let Some(_) = ast::SourceFile::cast(node) {
223 Some(module_from_source(db, position.file_id.into(), None)?.resolver(db)) 224 Some(module_from_source(db, file_id.into(), None)?.resolver(db))
225 } else if let Some(s) = ast::StructDef::cast(node) {
226 let module = module_from_child_node(db, file_id, s.syntax())?;
227 Some(struct_from_module(db, module, s).resolver(db))
228 } else if let Some(e) = ast::EnumDef::cast(node) {
229 let module = module_from_child_node(db, file_id, e.syntax())?;
230 Some(enum_from_module(db, module, e).resolver(db))
224 } else { 231 } else {
225 // TODO add missing cases 232 // TODO add missing cases
226 None 233 None
@@ -246,6 +253,12 @@ pub fn resolver_for_node(db: &impl HirDatabase, file_id: FileId, node: &SyntaxNo
246 Some(module_from_declaration(db, file_id, module)?.resolver(db)) 253 Some(module_from_declaration(db, file_id, module)?.resolver(db))
247 } else if let Some(_) = ast::SourceFile::cast(node) { 254 } else if let Some(_) = ast::SourceFile::cast(node) {
248 Some(module_from_source(db, file_id.into(), None)?.resolver(db)) 255 Some(module_from_source(db, file_id.into(), None)?.resolver(db))
256 } else if let Some(s) = ast::StructDef::cast(node) {
257 let module = module_from_child_node(db, file_id, s.syntax())?;
258 Some(struct_from_module(db, module, s).resolver(db))
259 } else if let Some(e) = ast::EnumDef::cast(node) {
260 let module = module_from_child_node(db, file_id, e.syntax())?;
261 Some(enum_from_module(db, module, e).resolver(db))
249 } else { 262 } else {
250 // TODO add missing cases 263 // TODO add missing cases
251 None 264 None