mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
make resolver private
This commit is contained in:
parent
62d01dd4df
commit
a2cc76ce63
6 changed files with 23 additions and 26 deletions
|
@ -189,7 +189,7 @@ impl Module {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
||||||
let def_map = db.crate_def_map(self.krate);
|
let def_map = db.crate_def_map(self.krate);
|
||||||
Resolver::default().push_module_scope(def_map, self.module_id)
|
Resolver::default().push_module_scope(def_map, self.module_id)
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,7 @@ impl Struct {
|
||||||
|
|
||||||
// FIXME move to a more general type
|
// FIXME move to a more general type
|
||||||
/// Builds a resolver for type references inside this struct.
|
/// Builds a resolver for type references inside this struct.
|
||||||
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
||||||
// take the outer scope...
|
// take the outer scope...
|
||||||
let r = self.module(db).resolver(db);
|
let r = self.module(db).resolver(db);
|
||||||
// ...and add generic params, if present
|
// ...and add generic params, if present
|
||||||
|
@ -373,7 +373,7 @@ impl Enum {
|
||||||
|
|
||||||
// FIXME: move to a more general type
|
// FIXME: move to a more general type
|
||||||
/// Builds a resolver for type references inside this struct.
|
/// Builds a resolver for type references inside this struct.
|
||||||
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
||||||
// take the outer scope...
|
// take the outer scope...
|
||||||
let r = self.module(db).resolver(db);
|
let r = self.module(db).resolver(db);
|
||||||
// ...and add generic params, if present
|
// ...and add generic params, if present
|
||||||
|
@ -459,7 +459,7 @@ impl DefWithBody {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds a resolver for code inside this item.
|
/// Builds a resolver for code inside this item.
|
||||||
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
||||||
match *self {
|
match *self {
|
||||||
DefWithBody::Const(ref c) => c.resolver(db),
|
DefWithBody::Const(ref c) => c.resolver(db),
|
||||||
DefWithBody::Function(ref f) => f.resolver(db),
|
DefWithBody::Function(ref f) => f.resolver(db),
|
||||||
|
@ -549,7 +549,7 @@ impl Function {
|
||||||
|
|
||||||
// FIXME: move to a more general type for 'body-having' items
|
// FIXME: move to a more general type for 'body-having' items
|
||||||
/// Builds a resolver for code inside this item.
|
/// Builds a resolver for code inside this item.
|
||||||
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
||||||
// take the outer scope...
|
// take the outer scope...
|
||||||
let r = self
|
let r = self
|
||||||
.impl_block(db)
|
.impl_block(db)
|
||||||
|
@ -602,7 +602,7 @@ impl Const {
|
||||||
|
|
||||||
// FIXME: move to a more general type for 'body-having' items
|
// FIXME: move to a more general type for 'body-having' items
|
||||||
/// Builds a resolver for code inside this item.
|
/// Builds a resolver for code inside this item.
|
||||||
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
||||||
// take the outer scope...
|
// take the outer scope...
|
||||||
let r = self
|
let r = self
|
||||||
.impl_block(db)
|
.impl_block(db)
|
||||||
|
@ -654,7 +654,7 @@ impl Static {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds a resolver for code inside this item.
|
/// Builds a resolver for code inside this item.
|
||||||
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
||||||
// take the outer scope...
|
// take the outer scope...
|
||||||
self.module(db).resolver(db)
|
self.module(db).resolver(db)
|
||||||
}
|
}
|
||||||
|
@ -736,7 +736,7 @@ impl TypeAlias {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds a resolver for the type references in this type alias.
|
/// Builds a resolver for the type references in this type alias.
|
||||||
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
||||||
// take the outer scope...
|
// take the outer scope...
|
||||||
let r = self
|
let r = self
|
||||||
.impl_block(db)
|
.impl_block(db)
|
||||||
|
|
|
@ -81,12 +81,16 @@ impl Body {
|
||||||
}
|
}
|
||||||
|
|
||||||
// needs arbitrary_self_types to be a method... or maybe move to the def?
|
// needs arbitrary_self_types to be a method... or maybe move to the def?
|
||||||
pub fn resolver_for_expr(body: Arc<Body>, db: &impl HirDatabase, expr_id: ExprId) -> Resolver {
|
pub(crate) fn resolver_for_expr(
|
||||||
|
body: Arc<Body>,
|
||||||
|
db: &impl HirDatabase,
|
||||||
|
expr_id: ExprId,
|
||||||
|
) -> Resolver {
|
||||||
let scopes = db.expr_scopes(body.owner);
|
let scopes = db.expr_scopes(body.owner);
|
||||||
resolver_for_scope(body, db, scopes.scope_for(expr_id))
|
resolver_for_scope(body, db, scopes.scope_for(expr_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolver_for_scope(
|
pub(crate) fn resolver_for_scope(
|
||||||
body: Arc<Body>,
|
body: Arc<Body>,
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
scope_id: Option<scope::ScopeId>,
|
scope_id: Option<scope::ScopeId>,
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl ImplBlock {
|
||||||
db.generic_params((*self).into())
|
db.generic_params((*self).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
||||||
let r = self.module().resolver(db);
|
let r = self.module().resolver(db);
|
||||||
// add generic params, if present
|
// add generic params, if present
|
||||||
let p = self.generic_params(db);
|
let p = self.generic_params(db);
|
||||||
|
|
|
@ -51,6 +51,7 @@ use crate::{
|
||||||
db::{HirDatabase, DefDatabase},
|
db::{HirDatabase, DefDatabase},
|
||||||
name::{AsName, KnownName},
|
name::{AsName, KnownName},
|
||||||
source_id::{FileAstId, AstId},
|
source_id::{FileAstId, AstId},
|
||||||
|
resolve::Resolver,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
|
@ -65,7 +66,7 @@ pub use self::{
|
||||||
docs::{Docs, Documentation},
|
docs::{Docs, Documentation},
|
||||||
adt::AdtDef,
|
adt::AdtDef,
|
||||||
expr::{ExprScopes, ScopeEntryWithSyntax},
|
expr::{ExprScopes, ScopeEntryWithSyntax},
|
||||||
resolve::{Resolver, Resolution},
|
resolve::Resolution,
|
||||||
source_binder::{SourceAnalyzer, PathResolution},
|
source_binder::{SourceAnalyzer, PathResolution},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,13 +9,13 @@ use crate::{
|
||||||
name::{Name, KnownName},
|
name::{Name, KnownName},
|
||||||
nameres::{PerNs, CrateDefMap, CrateModuleId},
|
nameres::{PerNs, CrateDefMap, CrateModuleId},
|
||||||
generics::GenericParams,
|
generics::GenericParams,
|
||||||
expr::{scope::{ExprScopes, ScopeId}, PatId, Body},
|
expr::{scope::{ExprScopes, ScopeId}, PatId},
|
||||||
impl_block::ImplBlock,
|
impl_block::ImplBlock,
|
||||||
path::Path, Trait
|
path::Path, Trait
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Resolver {
|
pub(crate) struct Resolver {
|
||||||
scopes: Vec<Scope>,
|
scopes: Vec<Scope>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ pub enum Resolution {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Resolver {
|
impl Resolver {
|
||||||
pub fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs<Resolution> {
|
pub(crate) fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs<Resolution> {
|
||||||
let mut resolution = PerNs::none();
|
let mut resolution = PerNs::none();
|
||||||
for scope in self.scopes.iter().rev() {
|
for scope in self.scopes.iter().rev() {
|
||||||
resolution = resolution.or(scope.resolve_name(db, name));
|
resolution = resolution.or(scope.resolve_name(db, name));
|
||||||
|
@ -154,12 +154,12 @@ impl Resolver {
|
||||||
|
|
||||||
/// Returns the fully resolved path if we were able to resolve it.
|
/// Returns the fully resolved path if we were able to resolve it.
|
||||||
/// otherwise returns `PerNs::none`
|
/// otherwise returns `PerNs::none`
|
||||||
pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs<Resolution> {
|
pub(crate) fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs<Resolution> {
|
||||||
// into_fully_resolved() returns the fully resolved path or PerNs::none() otherwise
|
// into_fully_resolved() returns the fully resolved path or PerNs::none() otherwise
|
||||||
self.resolve_path_segments(db, path).into_fully_resolved()
|
self.resolve_path_segments(db, path).into_fully_resolved()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn all_names(&self, db: &impl HirDatabase) -> FxHashMap<Name, PerNs<Resolution>> {
|
pub(crate) fn all_names(&self, db: &impl HirDatabase) -> FxHashMap<Name, PerNs<Resolution>> {
|
||||||
let mut names = FxHashMap::default();
|
let mut names = FxHashMap::default();
|
||||||
for scope in self.scopes.iter().rev() {
|
for scope in self.scopes.iter().rev() {
|
||||||
scope.collect_names(db, &mut |name, res| {
|
scope.collect_names(db, &mut |name, res| {
|
||||||
|
@ -197,14 +197,6 @@ impl Resolver {
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The body from which any `LocalBinding` resolutions in this resolver come.
|
|
||||||
pub fn body(&self) -> Option<Arc<Body>> {
|
|
||||||
self.scopes.iter().rev().find_map(|scope| match scope {
|
|
||||||
Scope::ExprScope(expr_scope) => Some(expr_scope.expr_scopes.body()),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Resolver {
|
impl Resolver {
|
||||||
|
|
|
@ -135,7 +135,7 @@ fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Option<Crate> {
|
||||||
impl Ty {
|
impl Ty {
|
||||||
/// Look up the method with the given name, returning the actual autoderefed
|
/// Look up the method with the given name, returning the actual autoderefed
|
||||||
/// receiver type (but without autoref applied yet).
|
/// receiver type (but without autoref applied yet).
|
||||||
pub fn lookup_method(
|
pub(crate) fn lookup_method(
|
||||||
self,
|
self,
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
name: &Name,
|
name: &Name,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue