From d3df80dfe41e4e3ab7644ae576119a264ba0e7f1 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 27 Jan 2019 17:23:49 +0100 Subject: Cleanup --- crates/ra_hir/src/expr.rs | 8 ++------ crates/ra_hir/src/nameres.rs | 3 +-- crates/ra_hir/src/resolve.rs | 16 +++++++--------- crates/ra_hir/src/source_binder.rs | 8 ++------ crates/ra_ide_api/src/completion/complete_path.rs | 6 +++--- crates/ra_ide_api/src/completion/completion_context.rs | 2 +- crates/ra_ide_api/src/goto_definition.rs | 1 + 7 files changed, 17 insertions(+), 27 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index e78ba889e..f9f702ae2 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -76,11 +76,7 @@ impl Body { } // needs arbitrary_self_types to be a method... or maybe move to the def? -pub fn resolver_for_expr( - body: Arc, - db: &impl HirDatabase, - expr_id: ExprId, -) -> Resolver<'static> { +pub fn resolver_for_expr(body: Arc, db: &impl HirDatabase, expr_id: ExprId) -> Resolver { let scopes = db.expr_scopes(body.owner); resolver_for_scope(body, db, scopes.scope_for(expr_id)) } @@ -89,7 +85,7 @@ pub fn resolver_for_scope( body: Arc, db: &impl HirDatabase, scope_id: Option, -) -> Resolver<'static> { +) -> Resolver { let mut r = body.owner.resolver(db); let scopes = db.expr_scopes(body.owner); let scope_chain = scopes.scope_chain_for(scope_id).collect::>(); diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 9b020db81..7ec6512b6 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -25,8 +25,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; use crate::{ Module, ModuleDef, Path, PathKind, PersistentHirDatabase, - Crate, - Name, + Crate, Name, module_tree::{ModuleId, ModuleTree}, nameres::lower::{ImportId, LoweredModule, ImportData}, }; diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 871f7d8f7..3e0af3a43 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -109,8 +109,6 @@ impl Resolver { self.scopes.iter().rev().find_map(|scope| match scope { Scope::ModuleScope(m) => Some((&*m.item_map, m.module.clone())), - Scope::ModuleScopeRef(m) => Some((m.item_map, m.module.clone())), - _ => None, }) } @@ -197,13 +195,13 @@ impl Scope { fn collect_names(&self, f: &mut FnMut(Name, PerNs)) { match self { Scope::ModuleScope(m) => { - m.item_map[m.module.module_id] - .entries() - .for_each(|(name, res)| { - f(name.clone(), res.def.map(|def| Resolution::Def { def })); - }) - } - Scope::ModuleScopeRef(m) => { + // TODO: should we provide `self` here? + // f( + // Name::self_param(), + // PerNs::types(Resolution::Def { + // def: m.module.into(), + // }), + // ); m.item_map[m.module.module_id] .entries() .for_each(|(name, res)| { diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 621215bfb..ce929cf3e 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -203,7 +203,7 @@ pub fn macro_symbols(db: &impl HirDatabase, file_id: FileId) -> Vec<(SmolStr, Te res } -pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> Resolver<'static> { +pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> Resolver { let file = db.parse(position.file_id); find_leaf_at_offset(file.syntax(), position.offset) .find_map(|node| { @@ -230,11 +230,7 @@ pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> R .unwrap_or_default() } -pub fn resolver_for_node( - db: &impl HirDatabase, - file_id: FileId, - node: &SyntaxNode, -) -> Resolver<'static> { +pub fn resolver_for_node(db: &impl HirDatabase, file_id: FileId, node: &SyntaxNode) -> Resolver { node.ancestors() .find_map(|node| { if ast::Expr::cast(node).is_some() || ast::Block::cast(node).is_some() { diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 9e61c0212..5b89c64ad 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -1,11 +1,11 @@ use join_to_string::join; +use hir::{Docs, Resolution}; + use crate::{ completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}, }; -use hir::Docs; - pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { let path = match &ctx.path_prefix { Some(path) => path.clone(), @@ -15,7 +15,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { Some(Resolution::Def { def }) => def, _ => return, }; - match def_id { + match def { hir::ModuleDef::Module(module) => { let module_scope = module.scope(ctx.db); for (name, res) in module_scope.entries() { diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index aea32fce3..5d1851da6 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs @@ -16,7 +16,7 @@ pub(crate) struct CompletionContext<'a> { pub(super) db: &'a db::RootDatabase, pub(super) offset: TextUnit, pub(super) leaf: &'a SyntaxNode, - pub(super) resolver: Resolver<'static>, + pub(super) resolver: Resolver, pub(super) module: Option, pub(super) function: Option, pub(super) function_syntax: Option<&'a ast::FnDef>, diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index f7dd28c7c..48080b6e1 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -4,6 +4,7 @@ use ra_syntax::{ algo::find_node_at_offset, }; use test_utils::tested_by; +use hir::Resolution; use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo}; -- cgit v1.2.3