mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Move ScopeDef
This commit is contained in:
parent
061e6c77b5
commit
1312c57d34
4 changed files with 31 additions and 31 deletions
|
@ -10,6 +10,7 @@ use hir_def::{
|
||||||
adt::VariantData,
|
adt::VariantData,
|
||||||
body::scope::ExprScopes,
|
body::scope::ExprScopes,
|
||||||
builtin_type::BuiltinType,
|
builtin_type::BuiltinType,
|
||||||
|
nameres::per_ns::PerNs,
|
||||||
traits::TraitData,
|
traits::TraitData,
|
||||||
type_ref::{Mutability, TypeRef},
|
type_ref::{Mutability, TypeRef},
|
||||||
ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup,
|
ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup,
|
||||||
|
@ -32,7 +33,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
resolve::{HasResolver, TypeNs},
|
resolve::{HasResolver, TypeNs},
|
||||||
ty::{InferenceResult, Namespace, TraitRef},
|
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
|
/// hir::Crate describes a single crate. It's the main interface with which
|
||||||
|
@ -1064,3 +1065,26 @@ pub struct GenericParam {
|
||||||
pub struct ImplBlock {
|
pub struct ImplBlock {
|
||||||
pub(crate) id: ImplId,
|
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<PerNs> 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -61,14 +61,13 @@ pub use crate::{
|
||||||
src::{HasBodySource, HasSource},
|
src::{HasBodySource, HasSource},
|
||||||
Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
|
Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
|
||||||
EnumVariant, FieldSource, FnData, Function, GenericParam, HasBody, ImplBlock, Local,
|
EnumVariant, FieldSource, FnData, Function, GenericParam, HasBody, ImplBlock, Local,
|
||||||
MacroDef, Module, ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias,
|
MacroDef, Module, ModuleDef, ModuleSource, ScopeDef, Static, Struct, StructField, Trait,
|
||||||
Union, VariantDef,
|
TypeAlias, Union, VariantDef,
|
||||||
},
|
},
|
||||||
expr::ExprScopes,
|
expr::ExprScopes,
|
||||||
from_source::FromSource,
|
from_source::FromSource,
|
||||||
generics::GenericDef,
|
generics::GenericDef,
|
||||||
ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile},
|
ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile},
|
||||||
resolve::ScopeDef,
|
|
||||||
source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
|
source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
|
||||||
ty::{
|
ty::{
|
||||||
display::HirDisplay,
|
display::HirDisplay,
|
||||||
|
|
|
@ -19,7 +19,7 @@ use crate::{
|
||||||
code_model::Crate,
|
code_model::Crate,
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
expr::{ExprScopes, PatId, ScopeId},
|
expr::{ExprScopes, PatId, ScopeId},
|
||||||
Adt, DefWithBody, GenericDef, ImplBlock, Local, MacroDef, ModuleDef, PerNs,
|
DefWithBody, GenericDef, Local, MacroDef, PerNs, ScopeDef,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[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<PerNs> 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 {
|
impl Scope {
|
||||||
fn process_names(&self, db: &impl DefDatabase2, f: &mut dyn FnMut(Name, ScopeDef)) {
|
fn process_names(&self, db: &impl DefDatabase2, f: &mut dyn FnMut(Name, ScopeDef)) {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
@ -23,11 +23,11 @@ use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
expr::{BodySourceMap, ExprScopes, ScopeId},
|
expr::{BodySourceMap, ExprScopes, ScopeId},
|
||||||
ids::LocationCtx,
|
ids::LocationCtx,
|
||||||
resolve::{resolver_for_scope, HasResolver, ScopeDef, TypeNs, ValueNs},
|
resolve::{resolver_for_scope, HasResolver, TypeNs, ValueNs},
|
||||||
ty::method_resolution::{self, implements_trait},
|
ty::method_resolution::{self, implements_trait},
|
||||||
Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function,
|
Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function,
|
||||||
GenericParam, HasBody, HirFileId, Local, MacroDef, Module, Name, Path, Resolver, Static,
|
GenericParam, HasBody, HirFileId, Local, MacroDef, Module, Name, Path, Resolver, ScopeDef,
|
||||||
Struct, Trait, Ty, TypeAlias,
|
Static, Struct, Trait, Ty, TypeAlias,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> {
|
fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue