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_editor/src/lib.rs | |
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_editor/src/lib.rs')
-rw-r--r-- | crates/ra_editor/src/lib.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs index a93924e00..2a801f7da 100644 --- a/crates/ra_editor/src/lib.rs +++ b/crates/ra_editor/src/lib.rs | |||
@@ -19,7 +19,7 @@ mod scope; | |||
19 | mod test_utils; | 19 | mod test_utils; |
20 | 20 | ||
21 | use ra_syntax::{ | 21 | use ra_syntax::{ |
22 | File, TextUnit, TextRange, SyntaxNodeRef, | 22 | File, TextUnit, TextRange, SmolStr, SyntaxNodeRef, |
23 | ast::{self, AstNode, NameOwner}, | 23 | ast::{self, AstNode, NameOwner}, |
24 | algo::find_leaf_at_offset, | 24 | algo::find_leaf_at_offset, |
25 | SyntaxKind::{self, *}, | 25 | SyntaxKind::{self, *}, |
@@ -164,6 +164,14 @@ pub fn find_node_at_offset<'a, N: AstNode<'a>>( | |||
164 | .next() | 164 | .next() |
165 | } | 165 | } |
166 | 166 | ||
167 | pub fn resolve_local_name(file: &File, offset: TextUnit, name_ref: ast::NameRef) -> Option<(SmolStr, TextRange)> { | ||
168 | let fn_def = find_node_at_offset::<ast::FnDef>(file.syntax(), offset)?; | ||
169 | let scopes = scope::FnScopes::new(fn_def); | ||
170 | let scope_entry = scope::resolve_local_name(name_ref, &scopes)?; | ||
171 | let name = scope_entry.ast().name()?; | ||
172 | Some((scope_entry.name(), name.syntax().range())) | ||
173 | } | ||
174 | |||
167 | #[cfg(test)] | 175 | #[cfg(test)] |
168 | mod tests { | 176 | mod tests { |
169 | use super::*; | 177 | use super::*; |