made ExprCollector pub(crate) and moved

collect_fn_body_syntax
This commit is contained in:
Lenard Pratt 2019-04-02 19:21:08 +01:00
parent 88e22e9d70
commit b9d2c2c21f
2 changed files with 11 additions and 14 deletions

View File

@ -462,7 +462,7 @@ impl Pat {
// Queries
struct ExprCollector {
pub(crate) struct ExprCollector {
owner: DefWithBody,
exprs: Arena<ExprId, Expr>,
pats: Arena<PatId, Pat>,
@ -943,12 +943,3 @@ pub(crate) fn body_with_source_map_query(
pub(crate) fn body_hir_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<Body> {
db.body_with_source_map(def).0
}
#[cfg(test)]
use crate::{Function};
#[cfg(test)]
fn collect_fn_body_syntax(function: Function, node: &ast::FnDef) -> (Body, BodySourceMap) {
let mut collector = ExprCollector::new(DefWithBody::Function(function));
collector.collect_fn_body(node);
collector.finish()
}

View File

@ -297,9 +297,9 @@ mod tests {
use ra_syntax::{SourceFile, algo::find_node_at_offset};
use test_utils::{extract_offset, assert_eq_text};
use ra_arena::ArenaId;
use crate::{Function};
use crate::Function;
use crate::expr;
use crate::expr::{ExprCollector};
use super::*;
@ -317,7 +317,7 @@ mod tests {
let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap();
let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) };
let (body, source_map) = expr::collect_fn_body_syntax(irrelevant_function, fn_def);
let (body, source_map) = collect_fn_body_syntax(irrelevant_function, fn_def);
let scopes = ExprScopes::new(Arc::new(body));
let scopes =
ScopesWithSourceMap { scopes: Arc::new(scopes), source_map: Arc::new(source_map) };
@ -406,6 +406,12 @@ mod tests {
);
}
fn collect_fn_body_syntax(function: Function, node: &ast::FnDef) -> (Body, BodySourceMap) {
let mut collector = ExprCollector::new(DefWithBody::Function(function));
collector.collect_fn_body(node);
collector.finish()
}
fn do_check_local_name(code: &str, expected_offset: u32) {
let (off, code) = extract_offset(code);
let file = SourceFile::parse(&code);
@ -416,7 +422,7 @@ mod tests {
let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap();
let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) };
let (body, source_map) = expr::collect_fn_body_syntax(irrelevant_function, fn_def);
let (body, source_map) = collect_fn_body_syntax(irrelevant_function, fn_def);
let scopes = ExprScopes::new(Arc::new(body));
let scopes =
ScopesWithSourceMap { scopes: Arc::new(scopes), source_map: Arc::new(source_map) };