diff options
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index d344ab12e..cde9801f6 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -2793,6 +2793,10 @@ fn main() { | |||
2793 | } | 2793 | } |
2794 | "#), | 2794 | "#), |
2795 | @r###" | 2795 | @r###" |
2796 | ![0; 17) '{Foo(v...,2,])}': Foo | ||
2797 | ![1; 4) 'Foo': Foo({unknown}) -> Foo | ||
2798 | ![1; 16) 'Foo(vec![1,2,])': Foo | ||
2799 | ![5; 15) 'vec![1,2,]': {unknown} | ||
2796 | [156; 182) '{ ...,2); }': () | 2800 | [156; 182) '{ ...,2); }': () |
2797 | [166; 167) 'x': Foo | 2801 | [166; 167) 'x': Foo |
2798 | "### | 2802 | "### |
@@ -3566,7 +3570,6 @@ fn infer(content: &str) -> String { | |||
3566 | let source_file = db.parse(file_id).ok().unwrap(); | 3570 | let source_file = db.parse(file_id).ok().unwrap(); |
3567 | 3571 | ||
3568 | let mut acc = String::new(); | 3572 | let mut acc = String::new(); |
3569 | // acc.push_str("\n"); | ||
3570 | 3573 | ||
3571 | let mut infer_def = |inference_result: Arc<InferenceResult>, | 3574 | let mut infer_def = |inference_result: Arc<InferenceResult>, |
3572 | body_source_map: Arc<BodySourceMap>| { | 3575 | body_source_map: Arc<BodySourceMap>| { |
@@ -3574,7 +3577,9 @@ fn infer(content: &str) -> String { | |||
3574 | 3577 | ||
3575 | for (pat, ty) in inference_result.type_of_pat.iter() { | 3578 | for (pat, ty) in inference_result.type_of_pat.iter() { |
3576 | let syntax_ptr = match body_source_map.pat_syntax(pat) { | 3579 | let syntax_ptr = match body_source_map.pat_syntax(pat) { |
3577 | Some(sp) => sp.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()), | 3580 | Some(sp) => { |
3581 | sp.map(|ast| ast.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr())) | ||
3582 | } | ||
3578 | None => continue, | 3583 | None => continue, |
3579 | }; | 3584 | }; |
3580 | types.push((syntax_ptr, ty)); | 3585 | types.push((syntax_ptr, ty)); |
@@ -3582,22 +3587,34 @@ fn infer(content: &str) -> String { | |||
3582 | 3587 | ||
3583 | for (expr, ty) in inference_result.type_of_expr.iter() { | 3588 | for (expr, ty) in inference_result.type_of_expr.iter() { |
3584 | let syntax_ptr = match body_source_map.expr_syntax(expr) { | 3589 | let syntax_ptr = match body_source_map.expr_syntax(expr) { |
3585 | Some(sp) => sp.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()), | 3590 | Some(sp) => { |
3591 | sp.map(|ast| ast.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr())) | ||
3592 | } | ||
3586 | None => continue, | 3593 | None => continue, |
3587 | }; | 3594 | }; |
3588 | types.push((syntax_ptr, ty)); | 3595 | types.push((syntax_ptr, ty)); |
3589 | } | 3596 | } |
3590 | 3597 | ||
3591 | // sort ranges for consistency | 3598 | // sort ranges for consistency |
3592 | types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end())); | 3599 | types.sort_by_key(|(src_ptr, _)| (src_ptr.ast.range().start(), src_ptr.ast.range().end())); |
3593 | for (syntax_ptr, ty) in &types { | 3600 | for (src_ptr, ty) in &types { |
3594 | let node = syntax_ptr.to_node(source_file.syntax()); | 3601 | let node = src_ptr.ast.to_node(&src_ptr.file_syntax(&db)); |
3602 | |||
3595 | let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node.clone()) { | 3603 | let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node.clone()) { |
3596 | (self_param.self_kw_token().text_range(), "self".to_string()) | 3604 | (self_param.self_kw_token().text_range(), "self".to_string()) |
3597 | } else { | 3605 | } else { |
3598 | (syntax_ptr.range(), node.text().to_string().replace("\n", " ")) | 3606 | (src_ptr.ast.range(), node.text().to_string().replace("\n", " ")) |
3599 | }; | 3607 | }; |
3600 | write!(acc, "{} '{}': {}\n", range, ellipsize(text, 15), ty.display(&db)).unwrap(); | 3608 | let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; |
3609 | write!( | ||
3610 | acc, | ||
3611 | "{}{} '{}': {}\n", | ||
3612 | macro_prefix, | ||
3613 | range, | ||
3614 | ellipsize(text, 15), | ||
3615 | ty.display(&db) | ||
3616 | ) | ||
3617 | .unwrap(); | ||
3601 | } | 3618 | } |
3602 | }; | 3619 | }; |
3603 | 3620 | ||