From 1312c57d342730690a0181c53f82bb3e281114ff Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 Nov 2019 14:21:26 +0300 Subject: Move ScopeDef --- crates/ra_hir/src/code_model.rs | 26 +++++++++++++++++++++++++- crates/ra_hir/src/lib.rs | 5 ++--- crates/ra_hir/src/resolve.rs | 25 +------------------------ crates/ra_hir/src/source_binder.rs | 6 +++--- 4 files changed, 31 insertions(+), 31 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index c4935c0d7..39b01d510 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -10,6 +10,7 @@ use hir_def::{ adt::VariantData, body::scope::ExprScopes, builtin_type::BuiltinType, + nameres::per_ns::PerNs, traits::TraitData, type_ref::{Mutability, TypeRef}, ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup, @@ -32,7 +33,7 @@ use crate::{ }, resolve::{HasResolver, TypeNs}, ty::{InferenceResult, Namespace, TraitRef}, - Either, HasSource, ImportId, Name, ScopeDef, Source, Ty, + Either, HasSource, ImportId, Name, Source, Ty, }; /// hir::Crate describes a single crate. It's the main interface with which @@ -1064,3 +1065,26 @@ pub struct GenericParam { pub struct ImplBlock { pub(crate) id: ImplId, } + +/// For IDE only +pub enum ScopeDef { + ModuleDef(ModuleDef), + MacroDef(MacroDef), + GenericParam(u32), + ImplSelfType(ImplBlock), + AdtSelfType(Adt), + Local(Local), + Unknown, +} + +impl From for ScopeDef { + fn from(def: PerNs) -> Self { + def.take_types() + .or_else(|| def.take_values()) + .map(|module_def_id| ScopeDef::ModuleDef(module_def_id.into())) + .or_else(|| { + def.get_macros().map(|macro_def_id| ScopeDef::MacroDef(macro_def_id.into())) + }) + .unwrap_or(ScopeDef::Unknown) + } +} diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 31da74d2f..095d4964f 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -61,14 +61,13 @@ pub use crate::{ src::{HasBodySource, HasSource}, Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, EnumVariant, FieldSource, FnData, Function, GenericParam, HasBody, ImplBlock, Local, - MacroDef, Module, ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, - Union, VariantDef, + MacroDef, Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, Trait, + TypeAlias, Union, VariantDef, }, expr::ExprScopes, from_source::FromSource, generics::GenericDef, ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, - resolve::ScopeDef, source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, ty::{ display::HirDisplay, diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index ed9fa0491..5e04ca9b6 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -19,7 +19,7 @@ use crate::{ code_model::Crate, db::HirDatabase, expr::{ExprScopes, PatId, ScopeId}, - Adt, DefWithBody, GenericDef, ImplBlock, Local, MacroDef, ModuleDef, PerNs, + DefWithBody, GenericDef, Local, MacroDef, PerNs, ScopeDef, }; #[derive(Debug, Clone, Default)] @@ -420,29 +420,6 @@ impl Resolver { } } -/// For IDE only -pub enum ScopeDef { - ModuleDef(ModuleDef), - MacroDef(MacroDef), - GenericParam(u32), - ImplSelfType(ImplBlock), - AdtSelfType(Adt), - Local(Local), - Unknown, -} - -impl From for ScopeDef { - fn from(def: PerNs) -> Self { - def.take_types() - .or_else(|| def.take_values()) - .map(|module_def_id| ScopeDef::ModuleDef(module_def_id.into())) - .or_else(|| { - def.get_macros().map(|macro_def_id| ScopeDef::MacroDef(macro_def_id.into())) - }) - .unwrap_or(ScopeDef::Unknown) - } -} - impl Scope { fn process_names(&self, db: &impl DefDatabase2, f: &mut dyn FnMut(Name, ScopeDef)) { match self { diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 8e379498a..467e46d8c 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -23,11 +23,11 @@ use crate::{ db::HirDatabase, expr::{BodySourceMap, ExprScopes, ScopeId}, ids::LocationCtx, - resolve::{resolver_for_scope, HasResolver, ScopeDef, TypeNs, ValueNs}, + resolve::{resolver_for_scope, HasResolver, TypeNs, ValueNs}, ty::method_resolution::{self, implements_trait}, Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function, - GenericParam, HasBody, HirFileId, Local, MacroDef, Module, Name, Path, Resolver, Static, - Struct, Trait, Ty, TypeAlias, + GenericParam, HasBody, HirFileId, Local, MacroDef, Module, Name, Path, Resolver, ScopeDef, + Static, Struct, Trait, Ty, TypeAlias, }; fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option { -- cgit v1.2.3