aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/src/imp.rs18
-rw-r--r--crates/ra_editor/src/lib.rs8
-rw-r--r--crates/ra_editor/src/scope/mod.rs2
3 files changed, 25 insertions, 3 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 90184a4b9..05c91fb83 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -9,7 +9,7 @@ use std::{
9}; 9};
10 10
11use relative_path::RelativePath; 11use relative_path::RelativePath;
12use ra_editor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit}; 12use ra_editor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit, resolve_local_name};
13use ra_syntax::{ 13use ra_syntax::{
14 TextUnit, TextRange, SmolStr, File, AstNode, 14 TextUnit, TextRange, SmolStr, File, AstNode,
15 SyntaxKind::*, 15 SyntaxKind::*,
@@ -197,7 +197,21 @@ impl AnalysisImpl {
197 let file = root.syntax(file_id); 197 let file = root.syntax(file_id);
198 let syntax = file.syntax(); 198 let syntax = file.syntax();
199 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) { 199 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) {
200 return self.index_resolve(name_ref, token); 200
201 // First try to resolve the symbol locally
202 if let Some(name) = resolve_local_name(&file, offset, name_ref) {
203 let vec: Vec<(FileId, FileSymbol)>::new();
204 vec.push((file_id, FileSymbol {
205 name: name.text(),
206 node_range: name.syntax().range(),
207 kind : NAME
208 }));
209
210 return vec;
211 } else {
212 // If that fails try the index based approach.
213 return self.index_resolve(name_ref, token);
214 }
201 } 215 }
202 if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) { 216 if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) {
203 if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { 217 if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) {
diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs
index a93924e00..fcb3e12e6 100644
--- a/crates/ra_editor/src/lib.rs
+++ b/crates/ra_editor/src/lib.rs
@@ -164,6 +164,14 @@ pub fn find_node_at_offset<'a, N: AstNode<'a>>(
164 .next() 164 .next()
165} 165}
166 166
167pub fn resolve_local_name<'a>(file: &'a File, offset: TextUnit, name_ref: ast::NameRef) -> Option<ast::Name<'a>> {
168 let fn_def = find_node_at_offset::<ast::FnDef>(file.syntax(), offset)?;
169 let scopes = scope::FnScopes::new(fn_def);
170
171 // TODO: This doesn't work because of scopes lifetime
172 scope::resolve_local_name(name_ref, &scopes)
173}
174
167#[cfg(test)] 175#[cfg(test)]
168mod tests { 176mod tests {
169 use super::*; 177 use super::*;
diff --git a/crates/ra_editor/src/scope/mod.rs b/crates/ra_editor/src/scope/mod.rs
index 2f25230f8..7d6d530f7 100644
--- a/crates/ra_editor/src/scope/mod.rs
+++ b/crates/ra_editor/src/scope/mod.rs
@@ -2,7 +2,7 @@ mod fn_scope;
2mod mod_scope; 2mod mod_scope;
3 3
4pub use self::{ 4pub use self::{
5 fn_scope::FnScopes, 5 fn_scope::{FnScopes, resolve_local_name},
6 mod_scope::ModuleScope, 6 mod_scope::ModuleScope,
7}; 7};
8 8