aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/function
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-08 09:05:55 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-08 09:05:55 +0000
commit3f4be819125ce4a22edd86721fa56b5caba99c2e (patch)
treebe93895ddc08c911585d9f7bc64623a3741f32c6 /crates/ra_hir/src/function
parent4e444d2bc24d16284401444fd2154f63e0f96070 (diff)
parent122410d7aa34a32d468a3173858cbc8a2bbc68f5 (diff)
Merge #449
449: switch to new rowan API r=matklad a=matklad closes https://github.com/rust-analyzer/rust-analyzer/issues/448 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/function')
-rw-r--r--crates/ra_hir/src/function/scope.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/crates/ra_hir/src/function/scope.rs b/crates/ra_hir/src/function/scope.rs
index 0a12f0b35..699784f71 100644
--- a/crates/ra_hir/src/function/scope.rs
+++ b/crates/ra_hir/src/function/scope.rs
@@ -3,7 +3,7 @@ use std::sync::Arc;
3use rustc_hash::{FxHashMap, FxHashSet}; 3use rustc_hash::{FxHashMap, FxHashSet};
4 4
5use ra_syntax::{ 5use ra_syntax::{
6 AstNode, SyntaxNodeRef, TextUnit, TextRange, 6 AstNode, SyntaxNode, TextUnit, TextRange,
7 algo::generate, 7 algo::generate,
8 ast, 8 ast,
9}; 9};
@@ -127,7 +127,7 @@ impl ScopeEntryWithSyntax {
127} 127}
128 128
129impl ScopesWithSyntaxMapping { 129impl ScopesWithSyntaxMapping {
130 pub fn scope_chain<'a>(&'a self, node: SyntaxNodeRef) -> impl Iterator<Item = ScopeId> + 'a { 130 pub fn scope_chain<'a>(&'a self, node: &SyntaxNode) -> impl Iterator<Item = ScopeId> + 'a {
131 generate(self.scope_for(node), move |&scope| { 131 generate(self.scope_for(node), move |&scope| {
132 self.scopes.scopes[scope].parent 132 self.scopes.scopes[scope].parent
133 }) 133 })
@@ -178,7 +178,7 @@ impl ScopesWithSyntaxMapping {
178 .unwrap_or(original_scope) 178 .unwrap_or(original_scope)
179 } 179 }
180 180
181 pub fn resolve_local_name(&self, name_ref: ast::NameRef) -> Option<ScopeEntryWithSyntax> { 181 pub fn resolve_local_name(&self, name_ref: &ast::NameRef) -> Option<ScopeEntryWithSyntax> {
182 let mut shadowed = FxHashSet::default(); 182 let mut shadowed = FxHashSet::default();
183 let name = name_ref.as_name(); 183 let name = name_ref.as_name();
184 let ret = self 184 let ret = self
@@ -195,7 +195,7 @@ impl ScopesWithSyntaxMapping {
195 }) 195 })
196 } 196 }
197 197
198 pub fn find_all_refs(&self, pat: ast::BindPat) -> Vec<ReferenceDescriptor> { 198 pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> {
199 let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap(); 199 let fn_def = pat.syntax().ancestors().find_map(ast::FnDef::cast).unwrap();
200 let name_ptr = LocalSyntaxPtr::new(pat.syntax()); 200 let name_ptr = LocalSyntaxPtr::new(pat.syntax());
201 fn_def 201 fn_def
@@ -213,7 +213,7 @@ impl ScopesWithSyntaxMapping {
213 .collect() 213 .collect()
214 } 214 }
215 215
216 fn scope_for(&self, node: SyntaxNodeRef) -> Option<ScopeId> { 216 fn scope_for(&self, node: &SyntaxNode) -> Option<ScopeId> {
217 node.ancestors() 217 node.ancestors()
218 .map(LocalSyntaxPtr::new) 218 .map(LocalSyntaxPtr::new)
219 .filter_map(|ptr| self.syntax_mapping.syntax_expr(ptr)) 219 .filter_map(|ptr| self.syntax_mapping.syntax_expr(ptr))
@@ -309,7 +309,7 @@ pub struct ReferenceDescriptor {
309#[cfg(test)] 309#[cfg(test)]
310mod tests { 310mod tests {
311 use ra_editor::find_node_at_offset; 311 use ra_editor::find_node_at_offset;
312 use ra_syntax::SourceFileNode; 312 use ra_syntax::SourceFile;
313 use test_utils::{extract_offset, assert_eq_text}; 313 use test_utils::{extract_offset, assert_eq_text};
314 314
315 use crate::expr; 315 use crate::expr;
@@ -326,9 +326,9 @@ mod tests {
326 buf.push_str(&code[off..]); 326 buf.push_str(&code[off..]);
327 buf 327 buf
328 }; 328 };
329 let file = SourceFileNode::parse(&code); 329 let file = SourceFile::parse(&code);
330 let marker: ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); 330 let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap();
331 let fn_def: ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); 331 let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
332 let body_hir = expr::collect_fn_body_syntax(fn_def); 332 let body_hir = expr::collect_fn_body_syntax(fn_def);
333 let scopes = FnScopes::new(Arc::clone(body_hir.body())); 333 let scopes = FnScopes::new(Arc::clone(body_hir.body()));
334 let scopes = ScopesWithSyntaxMapping { 334 let scopes = ScopesWithSyntaxMapping {
@@ -422,9 +422,9 @@ mod tests {
422 422
423 fn do_check_local_name(code: &str, expected_offset: u32) { 423 fn do_check_local_name(code: &str, expected_offset: u32) {
424 let (off, code) = extract_offset(code); 424 let (off, code) = extract_offset(code);
425 let file = SourceFileNode::parse(&code); 425 let file = SourceFile::parse(&code);
426 let fn_def: ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); 426 let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
427 let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); 427 let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap();
428 428
429 let body_hir = expr::collect_fn_body_syntax(fn_def); 429 let body_hir = expr::collect_fn_body_syntax(fn_def);
430 let scopes = FnScopes::new(Arc::clone(body_hir.body())); 430 let scopes = FnScopes::new(Arc::clone(body_hir.body()));