aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorLenard Pratt <[email protected]>2019-04-02 19:21:08 +0100
committerLenard Pratt <[email protected]>2019-04-02 19:22:06 +0100
commitb9d2c2c21fe8880fe1ca29b70b03db1d3faac554 (patch)
treebda21b49cbaa67d26216c1f53d3fef72abcb11a5 /crates/ra_hir/src
parent88e22e9d70ac3a35989ad1d45386f86697877c4c (diff)
made ExprCollector pub(crate) and moved
collect_fn_body_syntax
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/expr.rs11
-rw-r--r--crates/ra_hir/src/expr/scope.rs14
2 files changed, 11 insertions, 14 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index bc4c63d3c..51366de0a 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -462,7 +462,7 @@ impl Pat {
462 462
463// Queries 463// Queries
464 464
465struct ExprCollector { 465pub(crate) struct ExprCollector {
466 owner: DefWithBody, 466 owner: DefWithBody,
467 exprs: Arena<ExprId, Expr>, 467 exprs: Arena<ExprId, Expr>,
468 pats: Arena<PatId, Pat>, 468 pats: Arena<PatId, Pat>,
@@ -943,12 +943,3 @@ pub(crate) fn body_with_source_map_query(
943pub(crate) fn body_hir_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<Body> { 943pub(crate) fn body_hir_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<Body> {
944 db.body_with_source_map(def).0 944 db.body_with_source_map(def).0
945} 945}
946
947#[cfg(test)]
948use crate::{Function};
949#[cfg(test)]
950fn collect_fn_body_syntax(function: Function, node: &ast::FnDef) -> (Body, BodySourceMap) {
951 let mut collector = ExprCollector::new(DefWithBody::Function(function));
952 collector.collect_fn_body(node);
953 collector.finish()
954}
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs
index 9d6b1eb2b..48283907b 100644
--- a/crates/ra_hir/src/expr/scope.rs
+++ b/crates/ra_hir/src/expr/scope.rs
@@ -297,9 +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 use crate::Function;
301 301
302 use crate::expr; 302 use crate::expr::{ExprCollector};
303 303
304 use super::*; 304 use super::*;
305 305
@@ -317,7 +317,7 @@ mod tests {
317 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();
318 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();
319 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()) };
320 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);
321 let scopes = ExprScopes::new(Arc::new(body)); 321 let scopes = ExprScopes::new(Arc::new(body));
322 let scopes = 322 let scopes =
323 ScopesWithSourceMap { scopes: Arc::new(scopes), source_map: Arc::new(source_map) }; 323 ScopesWithSourceMap { scopes: Arc::new(scopes), source_map: Arc::new(source_map) };
@@ -406,6 +406,12 @@ mod tests {
406 ); 406 );
407 } 407 }
408 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
409 fn do_check_local_name(code: &str, expected_offset: u32) { 415 fn do_check_local_name(code: &str, expected_offset: u32) {
410 let (off, code) = extract_offset(code); 416 let (off, code) = extract_offset(code);
411 let file = SourceFile::parse(&code); 417 let file = SourceFile::parse(&code);
@@ -416,7 +422,7 @@ mod tests {
416 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();
417 423
418 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()) };
419 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);
420 let scopes = ExprScopes::new(Arc::new(body)); 426 let scopes = ExprScopes::new(Arc::new(body));
421 let scopes = 427 let scopes =
422 ScopesWithSourceMap { scopes: Arc::new(scopes), source_map: Arc::new(source_map) }; 428 ScopesWithSourceMap { scopes: Arc::new(scopes), source_map: Arc::new(source_map) };