diff options
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 23 |
2 files changed, 12 insertions, 17 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 8e1f29019..0d2746ac0 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -89,12 +89,6 @@ fn module_from_source( | |||
89 | ) | 89 | ) |
90 | } | 90 | } |
91 | 91 | ||
92 | pub fn function_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Function> { | ||
93 | let file = db.parse(position.file_id); | ||
94 | let fn_def = find_node_at_offset::<ast::FnDef>(file.syntax(), position.offset)?; | ||
95 | function_from_source(db, position.file_id, fn_def) | ||
96 | } | ||
97 | |||
98 | fn function_from_source( | 92 | fn function_from_source( |
99 | db: &impl HirDatabase, | 93 | db: &impl HirDatabase, |
100 | file_id: FileId, | 94 | file_id: FileId, |
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 87d6bcaec..d7c2ca132 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -8,7 +8,6 @@ use ra_syntax::{algo, ast::{self, AstNode}, SyntaxKind::*}; | |||
8 | use test_utils::covers; | 8 | use test_utils::covers; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | source_binder, | ||
12 | mock::MockDatabase, | 11 | mock::MockDatabase, |
13 | ty::display::HirDisplay, | 12 | ty::display::HirDisplay, |
14 | ty::InferenceResult, | 13 | ty::InferenceResult, |
@@ -2303,13 +2302,10 @@ fn test() -> u64 { | |||
2303 | } | 2302 | } |
2304 | 2303 | ||
2305 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { | 2304 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { |
2306 | let func = source_binder::function_from_position(db, pos).unwrap(); | 2305 | let file = db.parse(pos.file_id); |
2307 | let body_source_map = func.body_source_map(db); | 2306 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); |
2308 | let inference_result = func.infer(db); | 2307 | let analyzer = SourceAnalyzer::new(db, pos.file_id, expr.syntax(), Some(pos.offset)); |
2309 | let (_, syntax) = func.source(db); | 2308 | let ty = analyzer.type_of(db, expr).unwrap(); |
2310 | let node = algo::find_node_at_offset::<ast::Expr>(syntax.syntax(), pos.offset).unwrap(); | ||
2311 | let expr = body_source_map.node_expr(node).unwrap(); | ||
2312 | let ty = &inference_result[expr]; | ||
2313 | ty.display(db).to_string() | 2309 | ty.display(db).to_string() |
2314 | } | 2310 | } |
2315 | 2311 | ||
@@ -2390,10 +2386,12 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() { | |||
2390 | } | 2386 | } |
2391 | ", | 2387 | ", |
2392 | ); | 2388 | ); |
2393 | let func = source_binder::function_from_position(&db, pos).unwrap(); | ||
2394 | { | 2389 | { |
2390 | let file = db.parse(pos.file_id); | ||
2391 | let node = | ||
2392 | algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent(); | ||
2395 | let events = db.log_executed(|| { | 2393 | let events = db.log_executed(|| { |
2396 | func.infer(&db); | 2394 | SourceAnalyzer::new(&db, pos.file_id, node, None); |
2397 | }); | 2395 | }); |
2398 | assert!(format!("{:?}", events).contains("infer")) | 2396 | assert!(format!("{:?}", events).contains("infer")) |
2399 | } | 2397 | } |
@@ -2410,8 +2408,11 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() { | |||
2410 | db.query_mut(ra_db::FileTextQuery).set(pos.file_id, Arc::new(new_text)); | 2408 | db.query_mut(ra_db::FileTextQuery).set(pos.file_id, Arc::new(new_text)); |
2411 | 2409 | ||
2412 | { | 2410 | { |
2411 | let file = db.parse(pos.file_id); | ||
2412 | let node = | ||
2413 | algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent(); | ||
2413 | let events = db.log_executed(|| { | 2414 | let events = db.log_executed(|| { |
2414 | func.infer(&db); | 2415 | SourceAnalyzer::new(&db, pos.file_id, node, None); |
2415 | }); | 2416 | }); |
2416 | assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events) | 2417 | assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events) |
2417 | } | 2418 | } |