diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-07 18:01:57 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-07 18:01:57 +0100 |
commit | e4fdfd15012c983e4555996aa466b57d787e4385 (patch) | |
tree | 33b5209f553bf29cc409d3d8e71107f841af89ba /crates/ra_analysis | |
parent | f53c8aee065fac2816b50964d4b7544c84d67837 (diff) | |
parent | ff1b2da50280ef40988ce79f8bb5e82aff7e68c5 (diff) |
Merge #98
98: WIP: Add resolve_local_name to resolve names in a function scope r=kjeremy a=kjeremy
First step to resolving #80
Co-authored-by: Jeremy A. Kolb <[email protected]>
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 90184a4b9..517867e86 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 | ||
11 | use relative_path::RelativePath; | 11 | use relative_path::RelativePath; |
12 | use ra_editor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit}; | 12 | use ra_editor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit, resolve_local_name}; |
13 | use ra_syntax::{ | 13 | use 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, range)) = resolve_local_name(&file, offset, name_ref) { | ||
203 | let mut vec = vec![]; | ||
204 | vec.push((file_id, FileSymbol { | ||
205 | name, | ||
206 | node_range: 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) { |