aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/completion/reference_completion.rs2
-rw-r--r--crates/ra_analysis/src/hir/function/mod.rs2
-rw-r--r--crates/ra_analysis/src/hir/function/scope.rs29
-rw-r--r--crates/ra_analysis/src/hir/mod.rs14
-rw-r--r--crates/ra_analysis/src/imp.rs5
-rw-r--r--crates/ra_analysis/src/lib.rs2
6 files changed, 27 insertions, 27 deletions
diff --git a/crates/ra_analysis/src/completion/reference_completion.rs b/crates/ra_analysis/src/completion/reference_completion.rs
index 1bf210685..5bf8c3725 100644
--- a/crates/ra_analysis/src/completion/reference_completion.rs
+++ b/crates/ra_analysis/src/completion/reference_completion.rs
@@ -12,7 +12,7 @@ use crate::{
12 completion::CompletionItem, 12 completion::CompletionItem,
13 hir::{ 13 hir::{
14 ModuleDescriptor, 14 ModuleDescriptor,
15 function::FnScopes, 15 FnScopes,
16 Def, 16 Def,
17 Path, 17 Path,
18 }, 18 },
diff --git a/crates/ra_analysis/src/hir/function/mod.rs b/crates/ra_analysis/src/hir/function/mod.rs
index 5de9806e3..8161a604f 100644
--- a/crates/ra_analysis/src/hir/function/mod.rs
+++ b/crates/ra_analysis/src/hir/function/mod.rs
@@ -15,7 +15,7 @@ use crate::{
15 syntax_ptr::SyntaxPtr, FileId, 15 syntax_ptr::SyntaxPtr, FileId,
16}; 16};
17 17
18pub(crate) use self::scope::{resolve_local_name, FnScopes}; 18pub(crate) use self::scope::FnScopes;
19pub(crate) use crate::loc2id::FnId; 19pub(crate) use crate::loc2id::FnId;
20 20
21impl FnId { 21impl FnId {
diff --git a/crates/ra_analysis/src/hir/function/scope.rs b/crates/ra_analysis/src/hir/function/scope.rs
index 5307a0a8e..b8bdebe47 100644
--- a/crates/ra_analysis/src/hir/function/scope.rs
+++ b/crates/ra_analysis/src/hir/function/scope.rs
@@ -57,6 +57,19 @@ impl FnScopes {
57 self.scopes[scope].parent 57 self.scopes[scope].parent
58 }) 58 })
59 } 59 }
60 pub(crate) fn resolve_local_name<'a>(
61 &'a self,
62 name_ref: ast::NameRef,
63 ) -> Option<&'a ScopeEntry> {
64 let mut shadowed = FxHashSet::default();
65 let ret = self
66 .scope_chain(name_ref.syntax())
67 .flat_map(|scope| self.entries(scope).iter())
68 .filter(|entry| shadowed.insert(entry.name()))
69 .filter(|entry| entry.name() == &name_ref.text())
70 .nth(0);
71 ret
72 }
60 fn root_scope(&mut self) -> ScopeId { 73 fn root_scope(&mut self) -> ScopeId {
61 self.scopes.alloc(ScopeData { 74 self.scopes.alloc(ScopeData {
62 parent: None, 75 parent: None,
@@ -249,20 +262,6 @@ fn compute_expr_scopes(expr: ast::Expr, scopes: &mut FnScopes, scope: ScopeId) {
249 } 262 }
250} 263}
251 264
252pub fn resolve_local_name<'a>(
253 name_ref: ast::NameRef,
254 scopes: &'a FnScopes,
255) -> Option<&'a ScopeEntry> {
256 let mut shadowed = FxHashSet::default();
257 let ret = scopes
258 .scope_chain(name_ref.syntax())
259 .flat_map(|scope| scopes.entries(scope).iter())
260 .filter(|entry| shadowed.insert(entry.name()))
261 .filter(|entry| entry.name() == &name_ref.text())
262 .nth(0);
263 ret
264}
265
266#[cfg(test)] 265#[cfg(test)]
267mod tests { 266mod tests {
268 use ra_editor::find_node_at_offset; 267 use ra_editor::find_node_at_offset;
@@ -376,7 +375,7 @@ mod tests {
376 375
377 let scopes = FnScopes::new(fn_def); 376 let scopes = FnScopes::new(fn_def);
378 377
379 let local_name_entry = resolve_local_name(name_ref, &scopes).unwrap(); 378 let local_name_entry = scopes.resolve_local_name(name_ref).unwrap();
380 let local_name = local_name_entry.ptr().resolve(&file); 379 let local_name = local_name_entry.ptr().resolve(&file);
381 let expected_name = 380 let expected_name =
382 find_node_at_offset::<ast::Name>(file.syntax(), expected_offset.into()).unwrap(); 381 find_node_at_offset::<ast::Name>(file.syntax(), expected_offset.into()).unwrap();
diff --git a/crates/ra_analysis/src/hir/mod.rs b/crates/ra_analysis/src/hir/mod.rs
index 2035c2d23..1d37fae32 100644
--- a/crates/ra_analysis/src/hir/mod.rs
+++ b/crates/ra_analysis/src/hir/mod.rs
@@ -5,11 +5,11 @@
5//! to a particular crate instance. That is, it has cfg flags and features 5//! to a particular crate instance. That is, it has cfg flags and features
6//! applied. So, there relation between syntax and HIR is many-to-one. 6//! applied. So, there relation between syntax and HIR is many-to-one.
7 7
8pub(crate) mod function;
9mod module;
10pub(crate) mod db; 8pub(crate) mod db;
11mod path;
12mod query_definitions; 9mod query_definitions;
10mod function;
11mod module;
12mod path;
13 13
14use ra_syntax::{ 14use ra_syntax::{
15 ast::{self, AstNode}, 15 ast::{self, AstNode},
@@ -18,7 +18,6 @@ use ra_syntax::{
18 18
19use crate::{ 19use crate::{
20 hir::db::HirDatabase, 20 hir::db::HirDatabase,
21 hir::function::{resolve_local_name, FnScopes},
22 loc2id::{DefId, DefLoc}, 21 loc2id::{DefId, DefLoc},
23 syntax_ptr::LocalSyntaxPtr, 22 syntax_ptr::LocalSyntaxPtr,
24 Cancelable, 23 Cancelable,
@@ -27,9 +26,12 @@ use crate::{
27pub(crate) use self::{ 26pub(crate) use self::{
28 path::{Path, PathKind}, 27 path::{Path, PathKind},
29 module::{ModuleDescriptor, ModuleId, Problem, nameres::FileItemId}, 28 module::{ModuleDescriptor, ModuleId, Problem, nameres::FileItemId},
30 function::FunctionDescriptor, 29 function::{FunctionDescriptor, FnScopes},
31}; 30};
32 31
32//TODO: FIXME
33pub use self::function::FnDescriptor;
34
33pub(crate) enum Def { 35pub(crate) enum Def {
34 Module(ModuleDescriptor), 36 Module(ModuleDescriptor),
35 Item, 37 Item,
@@ -82,7 +84,7 @@ impl<'a> DeclarationDescriptor<'a> {
82 .syntax() 84 .syntax()
83 .descendants() 85 .descendants()
84 .filter_map(ast::NameRef::cast) 86 .filter_map(ast::NameRef::cast)
85 .filter(|name_ref| match resolve_local_name(*name_ref, &fn_scopes) { 87 .filter(|name_ref| match fn_scopes.resolve_local_name(*name_ref) {
86 None => false, 88 None => false,
87 Some(entry) => entry.ptr() == name_ptr, 89 Some(entry) => entry.ptr() == name_ptr,
88 }) 90 })
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 1b7e16ff4..347d44638 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -20,8 +20,7 @@ use crate::{
20 completion::{completions, CompletionItem}, 20 completion::{completions, CompletionItem},
21 db::{self, FileSyntaxQuery, SyntaxDatabase}, 21 db::{self, FileSyntaxQuery, SyntaxDatabase},
22 hir::{ 22 hir::{
23 FunctionDescriptor, ModuleDescriptor, 23 FnDescriptor, FunctionDescriptor, ModuleDescriptor,
24 function::FnDescriptor,
25 Problem, 24 Problem,
26 DeclarationDescriptor, 25 DeclarationDescriptor,
27 }, 26 },
@@ -590,7 +589,7 @@ fn resolve_local_name(
590 let fn_def = name_ref.syntax().ancestors().find_map(ast::FnDef::cast)?; 589 let fn_def = name_ref.syntax().ancestors().find_map(ast::FnDef::cast)?;
591 let function = FunctionDescriptor::guess_from_source(db, file_id, fn_def); 590 let function = FunctionDescriptor::guess_from_source(db, file_id, fn_def);
592 let scopes = function.scope(db); 591 let scopes = function.scope(db);
593 let scope_entry = crate::hir::function::resolve_local_name(name_ref, &scopes)?; 592 let scope_entry = scopes.resolve_local_name(name_ref)?;
594 let syntax = db.resolve_syntax_ptr(scope_entry.ptr().into_global(file_id)); 593 let syntax = db.resolve_syntax_ptr(scope_entry.ptr().into_global(file_id));
595 Some((scope_entry.name().clone(), syntax.range())) 594 Some((scope_entry.name().clone(), syntax.range()))
596} 595}
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 4659eb523..a3088c5ad 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -42,7 +42,7 @@ use crate::{
42 42
43pub use crate::{ 43pub use crate::{
44 completion::CompletionItem, 44 completion::CompletionItem,
45 hir::function::FnDescriptor, 45 hir::FnDescriptor,
46 input::{CrateGraph, CrateId, FileId, FileResolver}, 46 input::{CrateGraph, CrateId, FileId, FileResolver},
47}; 47};
48pub use ra_editor::{ 48pub use ra_editor::{