diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-23 14:37:57 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-23 14:37:57 +0000 |
commit | a583070b7d47852094b498c3191b4b5d87520fc3 (patch) | |
tree | dfe8364efeeaca6f8f32e1d922fb615119b8012b /crates/ra_hir/src/code_model_impl/function | |
parent | 81fcfc55d247bfe6090741f2e4ae9aa89947bf32 (diff) | |
parent | 7b901f86cd1d0198994e5a2ab7eea18f444dd148 (diff) |
Merge #610
610: move SyntaxPtr to ra_syntax r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model_impl/function')
-rw-r--r-- | crates/ra_hir/src/code_model_impl/function/scope.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/crates/ra_hir/src/code_model_impl/function/scope.rs b/crates/ra_hir/src/code_model_impl/function/scope.rs index 3a7d53a93..c5d1de5eb 100644 --- a/crates/ra_hir/src/code_model_impl/function/scope.rs +++ b/crates/ra_hir/src/code_model_impl/function/scope.rs | |||
@@ -3,12 +3,11 @@ use std::sync::Arc; | |||
3 | use rustc_hash::{FxHashMap, FxHashSet}; | 3 | use rustc_hash::{FxHashMap, FxHashSet}; |
4 | 4 | ||
5 | use ra_syntax::{ | 5 | use ra_syntax::{ |
6 | AstNode, SyntaxNode, TextUnit, TextRange, | 6 | AstNode, SyntaxNode, TextUnit, TextRange, SyntaxNodePtr, |
7 | algo::generate, | 7 | algo::generate, |
8 | ast, | 8 | ast, |
9 | }; | 9 | }; |
10 | use ra_arena::{Arena, RawId, impl_arena_id}; | 10 | use ra_arena::{Arena, RawId, impl_arena_id}; |
11 | use ra_db::LocalSyntaxPtr; | ||
12 | 11 | ||
13 | use crate::{Name, AsName, expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySyntaxMapping}}; | 12 | use crate::{Name, AsName, expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySyntaxMapping}}; |
14 | 13 | ||
@@ -126,7 +125,7 @@ pub struct ScopesWithSyntaxMapping { | |||
126 | #[derive(Debug, Clone, PartialEq, Eq)] | 125 | #[derive(Debug, Clone, PartialEq, Eq)] |
127 | pub struct ScopeEntryWithSyntax { | 126 | pub struct ScopeEntryWithSyntax { |
128 | name: Name, | 127 | name: Name, |
129 | ptr: LocalSyntaxPtr, | 128 | ptr: SyntaxNodePtr, |
130 | } | 129 | } |
131 | 130 | ||
132 | impl ScopeEntryWithSyntax { | 131 | impl ScopeEntryWithSyntax { |
@@ -134,7 +133,7 @@ impl ScopeEntryWithSyntax { | |||
134 | &self.name | 133 | &self.name |
135 | } | 134 | } |
136 | 135 | ||
137 | pub fn ptr(&self) -> LocalSyntaxPtr { | 136 | pub fn ptr(&self) -> SyntaxNodePtr { |
138 | self.ptr | 137 | self.ptr |
139 | } | 138 | } |
140 | } | 139 | } |
@@ -169,7 +168,7 @@ impl ScopesWithSyntaxMapping { | |||
169 | 168 | ||
170 | // XXX: during completion, cursor might be outside of any particular | 169 | // XXX: during completion, cursor might be outside of any particular |
171 | // expression. Try to figure out the correct scope... | 170 | // expression. Try to figure out the correct scope... |
172 | fn adjust(&self, ptr: LocalSyntaxPtr, original_scope: ScopeId, offset: TextUnit) -> ScopeId { | 171 | fn adjust(&self, ptr: SyntaxNodePtr, original_scope: ScopeId, offset: TextUnit) -> ScopeId { |
173 | let r = ptr.range(); | 172 | let r = ptr.range(); |
174 | let child_scopes = self | 173 | let child_scopes = self |
175 | .scopes | 174 | .scopes |
@@ -212,7 +211,7 @@ impl ScopesWithSyntaxMapping { | |||
212 | 211 | ||
213 | pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> { | 212 | pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> { |
214 | let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); | 213 | let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); |
215 | let name_ptr = LocalSyntaxPtr::new(pat.syntax()); | 214 | let name_ptr = SyntaxNodePtr::new(pat.syntax()); |
216 | fn_def | 215 | fn_def |
217 | .syntax() | 216 | .syntax() |
218 | .descendants() | 217 | .descendants() |
@@ -230,7 +229,7 @@ impl ScopesWithSyntaxMapping { | |||
230 | 229 | ||
231 | fn scope_for(&self, node: &SyntaxNode) -> Option<ScopeId> { | 230 | fn scope_for(&self, node: &SyntaxNode) -> Option<ScopeId> { |
232 | node.ancestors() | 231 | node.ancestors() |
233 | .map(LocalSyntaxPtr::new) | 232 | .map(SyntaxNodePtr::new) |
234 | .filter_map(|ptr| self.syntax_mapping.syntax_expr(ptr)) | 233 | .filter_map(|ptr| self.syntax_mapping.syntax_expr(ptr)) |
235 | .find_map(|it| self.scopes.scope_for(it)) | 234 | .find_map(|it| self.scopes.scope_for(it)) |
236 | } | 235 | } |