mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Move scope tests to hir_def
This commit is contained in:
parent
9167da66ac
commit
2f6c0c314b
5 changed files with 233 additions and 211 deletions
|
@ -19,7 +19,6 @@ use ra_syntax::{
|
|||
SyntaxKind::*,
|
||||
SyntaxNode, SyntaxNodePtr, TextRange, TextUnit,
|
||||
};
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
use crate::{
|
||||
db::HirDatabase,
|
||||
|
@ -286,22 +285,14 @@ impl SourceAnalyzer {
|
|||
}
|
||||
|
||||
fn resolve_local_name(&self, name_ref: &ast::NameRef) -> Option<ScopeEntryWithSyntax> {
|
||||
let mut shadowed = FxHashSet::default();
|
||||
let name = name_ref.as_name();
|
||||
let source_map = self.body_source_map.as_ref()?;
|
||||
let scopes = self.scopes.as_ref()?;
|
||||
let scope = scope_for(scopes, source_map, self.file_id.into(), name_ref.syntax());
|
||||
let ret = scopes
|
||||
.scope_chain(scope)
|
||||
.flat_map(|scope| scopes.entries(scope).iter())
|
||||
.filter(|entry| shadowed.insert(entry.name()))
|
||||
.filter(|entry| entry.name() == &name)
|
||||
.nth(0);
|
||||
ret.and_then(|entry| {
|
||||
Some(ScopeEntryWithSyntax {
|
||||
name: entry.name().clone(),
|
||||
ptr: source_map.pat_syntax(entry.pat())?.ast,
|
||||
})
|
||||
let scope = scope_for(scopes, source_map, self.file_id.into(), name_ref.syntax())?;
|
||||
let entry = scopes.resolve_name_in_scope(scope, &name)?;
|
||||
Some(ScopeEntryWithSyntax {
|
||||
name: entry.name().clone(),
|
||||
ptr: source_map.pat_syntax(entry.pat())?.ast,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -413,11 +404,6 @@ impl SourceAnalyzer {
|
|||
pub(crate) fn inference_result(&self) -> Arc<crate::ty::InferenceResult> {
|
||||
self.infer.clone().unwrap()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn scopes(&self) -> Arc<ExprScopes> {
|
||||
self.scopes.clone().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
fn scope_for(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue