aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cli
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-08-30 19:16:28 +0100
committerFlorian Diebold <[email protected]>2019-09-02 13:56:38 +0100
commitf92177cfb5088809892455262841e24cf1ecf5b6 (patch)
tree789f733506520663e6cb5f99eec7d56c1a443831 /crates/ra_cli
parenta7858bb7bf0a784d56b2b9ef97785a4fa78f7853 (diff)
Add an expr_source method analogous to the source methods in the code model
... and use that instead of exposing the source map.
Diffstat (limited to 'crates/ra_cli')
-rw-r--r--crates/ra_cli/src/analysis_stats.rs53
1 files changed, 26 insertions, 27 deletions
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs
index 77fa1d26e..d355fa2e8 100644
--- a/crates/ra_cli/src/analysis_stats.rs
+++ b/crates/ra_cli/src/analysis_stats.rs
@@ -1,7 +1,7 @@
1use std::{collections::HashSet, fmt::Write, path::Path, time::Instant}; 1use std::{collections::HashSet, fmt::Write, path::Path, time::Instant};
2 2
3use ra_db::SourceDatabase; 3use ra_db::SourceDatabase;
4use ra_hir::{Crate, HasSource, HirDisplay, ImplItem, ModuleDef, Ty}; 4use ra_hir::{Crate, HasBodySource, HasSource, HirDisplay, ImplItem, ModuleDef, Ty};
5use ra_syntax::AstNode; 5use ra_syntax::AstNode;
6 6
7use crate::Result; 7use crate::Result;
@@ -104,35 +104,34 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -
104 if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr_id) { 104 if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr_id) {
105 num_type_mismatches += 1; 105 num_type_mismatches += 1;
106 if verbose { 106 if verbose {
107 let src = f.source(db); 107 let src = f.expr_source(db, expr_id);
108 let original_file = src.file_id.original_file(db); 108 if let Some(src) = src {
109 let path = db.file_relative_path(original_file); 109 // FIXME: it might be nice to have a function (on Analysis?) that goes from Source<T> -> (LineCol, LineCol) directly
110 let line_index = host.analysis().file_line_index(original_file).unwrap(); 110 let original_file = src.file_id.original_file(db);
111 let body_source_map = f.body_source_map(db); 111 let path = db.file_relative_path(original_file);
112 let syntax_node = body_source_map.expr_syntax(expr_id); 112 let line_index = host.analysis().file_line_index(original_file).unwrap();
113 let line_col = syntax_node.map(|syntax_node| { 113 let (start, end) = (
114 ( 114 line_index.line_col(src.ast.syntax().text_range().start()),
115 line_index.line_col(syntax_node.range().start()), 115 line_index.line_col(src.ast.syntax().text_range().end()),
116 line_index.line_col(syntax_node.range().end()), 116 );
117 ) 117 bar.println(format!(
118 }); 118 "{} {}:{}-{}:{}: Expected {}, got {}",
119 let line_col = match line_col { 119 path.display(),
120 Some((start, end)) => format!(
121 "{}:{}-{}:{}",
122 start.line + 1, 120 start.line + 1,
123 start.col_utf16, 121 start.col_utf16,
124 end.line + 1, 122 end.line + 1,
125 end.col_utf16 123 end.col_utf16,
126 ), 124 mismatch.expected.display(db),
127 None => "?:?".to_string(), 125 mismatch.actual.display(db)
128 }; 126 ));
129 bar.println(format!( 127 } else {
130 "{} {}: Expected {}, got {}", 128 bar.println(format!(
131 path.display(), 129 "{}: Expected {}, got {}",
132 line_col, 130 name,
133 mismatch.expected.display(db), 131 mismatch.expected.display(db),
134 mismatch.actual.display(db) 132 mismatch.actual.display(db)
135 )); 133 ));
134 }
136 } 135 }
137 } 136 }
138 } 137 }