aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/expr
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/expr')
-rw-r--r--crates/ra_hir/src/expr/scope.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs
index ed005c9f7..48283907b 100644
--- a/crates/ra_hir/src/expr/scope.rs
+++ b/crates/ra_hir/src/expr/scope.rs
@@ -10,7 +10,7 @@ use ra_syntax::{
10use ra_arena::{Arena, RawId, impl_arena_id}; 10use ra_arena::{Arena, RawId, impl_arena_id};
11 11
12use crate::{ 12use crate::{
13 Name, AsName, Function, 13 Name, AsName,DefWithBody,
14 expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySourceMap}, 14 expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySourceMap},
15 HirDatabase, 15 HirDatabase,
16}; 16};
@@ -40,8 +40,8 @@ pub struct ScopeData {
40 40
41impl ExprScopes { 41impl ExprScopes {
42 // FIXME: This should take something more general than Function 42 // FIXME: This should take something more general than Function
43 pub(crate) fn expr_scopes_query(db: &impl HirDatabase, function: Function) -> Arc<ExprScopes> { 43 pub(crate) fn expr_scopes_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<ExprScopes> {
44 let body = db.body_hir(function); 44 let body = db.body_hir(def);
45 let res = ExprScopes::new(body); 45 let res = ExprScopes::new(body);
46 Arc::new(res) 46 Arc::new(res)
47 } 47 }
@@ -297,8 +297,9 @@ mod tests {
297 use ra_syntax::{SourceFile, algo::find_node_at_offset}; 297 use ra_syntax::{SourceFile, algo::find_node_at_offset};
298 use test_utils::{extract_offset, assert_eq_text}; 298 use test_utils::{extract_offset, assert_eq_text};
299 use ra_arena::ArenaId; 299 use ra_arena::ArenaId;
300 use crate::Function;
300 301
301 use crate::expr; 302 use crate::expr::{ExprCollector};
302 303
303 use super::*; 304 use super::*;
304 305
@@ -316,7 +317,7 @@ mod tests {
316 let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); 317 let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap();
317 let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap(); 318 let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
318 let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) }; 319 let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) };
319 let (body, source_map) = expr::collect_fn_body_syntax(irrelevant_function, fn_def); 320 let (body, source_map) = collect_fn_body_syntax(irrelevant_function, fn_def);
320 let scopes = ExprScopes::new(Arc::new(body)); 321 let scopes = ExprScopes::new(Arc::new(body));
321 let scopes = 322 let scopes =
322 ScopesWithSourceMap { scopes: Arc::new(scopes), source_map: Arc::new(source_map) }; 323 ScopesWithSourceMap { scopes: Arc::new(scopes), source_map: Arc::new(source_map) };
@@ -405,6 +406,12 @@ mod tests {
405 ); 406 );
406 } 407 }
407 408
409 fn collect_fn_body_syntax(function: Function, node: &ast::FnDef) -> (Body, BodySourceMap) {
410 let mut collector = ExprCollector::new(DefWithBody::Function(function));
411 collector.collect_fn_body(node);
412 collector.finish()
413 }
414
408 fn do_check_local_name(code: &str, expected_offset: u32) { 415 fn do_check_local_name(code: &str, expected_offset: u32) {
409 let (off, code) = extract_offset(code); 416 let (off, code) = extract_offset(code);
410 let file = SourceFile::parse(&code); 417 let file = SourceFile::parse(&code);
@@ -415,7 +422,7 @@ mod tests {
415 let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); 422 let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap();
416 423
417 let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) }; 424 let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) };
418 let (body, source_map) = expr::collect_fn_body_syntax(irrelevant_function, fn_def); 425 let (body, source_map) = collect_fn_body_syntax(irrelevant_function, fn_def);
419 let scopes = ExprScopes::new(Arc::new(body)); 426 let scopes = ExprScopes::new(Arc::new(body));
420 let scopes = 427 let scopes =
421 ScopesWithSourceMap { scopes: Arc::new(scopes), source_map: Arc::new(source_map) }; 428 ScopesWithSourceMap { scopes: Arc::new(scopes), source_map: Arc::new(source_map) };