aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-07-27 20:46:25 +0100
committerKirill Bulatov <[email protected]>2020-08-11 13:09:08 +0100
commitee1586c1ed058ff0f090b552d52fe6bbe2dd7f7f (patch)
tree8cb1dc2bb49f8607b6346eee6ab2d27b7e0f5654 /crates/ra_hir_ty/src
parenta61f2445cba2a48bb7ea6c8477e3198b297f3c67 (diff)
Better naming
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs55
1 files changed, 25 insertions, 30 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs
index 73d241434..a4cede81d 100644
--- a/crates/ra_hir_ty/src/diagnostics.rs
+++ b/crates/ra_hir_ty/src/diagnostics.rs
@@ -37,7 +37,7 @@ impl Diagnostic for NoSuchField {
37 "no such field".to_string() 37 "no such field".to_string()
38 } 38 }
39 39
40 fn source(&self) -> InFile<SyntaxNodePtr> { 40 fn fix_source(&self) -> InFile<SyntaxNodePtr> {
41 InFile::new(self.file, self.field.clone().into()) 41 InFile::new(self.file, self.field.clone().into())
42 } 42 }
43 43
@@ -50,9 +50,8 @@ impl AstDiagnostic for NoSuchField {
50 type AST = ast::RecordExprField; 50 type AST = ast::RecordExprField;
51 51
52 fn ast(&self, db: &dyn AstDatabase) -> Self::AST { 52 fn ast(&self, db: &dyn AstDatabase) -> Self::AST {
53 let root = db.parse_or_expand(self.source().file_id).unwrap(); 53 let root = db.parse_or_expand(self.file).unwrap();
54 let node = self.source().value.to_node(&root); 54 self.field.to_node(&root)
55 ast::RecordExprField::cast(node).unwrap()
56 } 55 }
57} 56}
58 57
@@ -72,19 +71,19 @@ impl Diagnostic for MissingFields {
72 } 71 }
73 buf 72 buf
74 } 73 }
75 fn source(&self) -> InFile<SyntaxNodePtr> { 74 fn fix_source(&self) -> InFile<SyntaxNodePtr> {
76 InFile { file_id: self.file, value: self.field_list.clone().into() } 75 InFile { file_id: self.file, value: self.field_list.clone().into() }
77 } 76 }
78 77
79 fn as_any(&self) -> &(dyn Any + Send + 'static) { 78 fn source(&self) -> InFile<SyntaxNodePtr> {
80 self
81 }
82
83 fn highlighting_source(&self) -> InFile<SyntaxNodePtr> {
84 self.list_parent_path 79 self.list_parent_path
85 .clone() 80 .clone()
86 .map(|path| InFile { file_id: self.file, value: path.into() }) 81 .map(|path| InFile { file_id: self.file, value: path.into() })
87 .unwrap_or_else(|| self.source()) 82 .unwrap_or_else(|| self.fix_source())
83 }
84
85 fn as_any(&self) -> &(dyn Any + Send + 'static) {
86 self
88 } 87 }
89} 88}
90 89
@@ -112,7 +111,7 @@ impl Diagnostic for MissingPatFields {
112 } 111 }
113 buf 112 buf
114 } 113 }
115 fn source(&self) -> InFile<SyntaxNodePtr> { 114 fn fix_source(&self) -> InFile<SyntaxNodePtr> {
116 InFile { file_id: self.file, value: self.field_list.clone().into() } 115 InFile { file_id: self.file, value: self.field_list.clone().into() }
117 } 116 }
118 fn as_any(&self) -> &(dyn Any + Send + 'static) { 117 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -131,7 +130,7 @@ impl Diagnostic for MissingMatchArms {
131 fn message(&self) -> String { 130 fn message(&self) -> String {
132 String::from("Missing match arm") 131 String::from("Missing match arm")
133 } 132 }
134 fn source(&self) -> InFile<SyntaxNodePtr> { 133 fn fix_source(&self) -> InFile<SyntaxNodePtr> {
135 InFile { file_id: self.file, value: self.match_expr.clone().into() } 134 InFile { file_id: self.file, value: self.match_expr.clone().into() }
136 } 135 }
137 fn as_any(&self) -> &(dyn Any + Send + 'static) { 136 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -149,7 +148,7 @@ impl Diagnostic for MissingOkInTailExpr {
149 fn message(&self) -> String { 148 fn message(&self) -> String {
150 "wrap return expression in Ok".to_string() 149 "wrap return expression in Ok".to_string()
151 } 150 }
152 fn source(&self) -> InFile<SyntaxNodePtr> { 151 fn fix_source(&self) -> InFile<SyntaxNodePtr> {
153 InFile { file_id: self.file, value: self.expr.clone().into() } 152 InFile { file_id: self.file, value: self.expr.clone().into() }
154 } 153 }
155 fn as_any(&self) -> &(dyn Any + Send + 'static) { 154 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -162,8 +161,7 @@ impl AstDiagnostic for MissingOkInTailExpr {
162 161
163 fn ast(&self, db: &dyn AstDatabase) -> Self::AST { 162 fn ast(&self, db: &dyn AstDatabase) -> Self::AST {
164 let root = db.parse_or_expand(self.file).unwrap(); 163 let root = db.parse_or_expand(self.file).unwrap();
165 let node = self.source().value.to_node(&root); 164 self.expr.to_node(&root)
166 ast::Expr::cast(node).unwrap()
167 } 165 }
168} 166}
169 167
@@ -177,7 +175,7 @@ impl Diagnostic for BreakOutsideOfLoop {
177 fn message(&self) -> String { 175 fn message(&self) -> String {
178 "break outside of loop".to_string() 176 "break outside of loop".to_string()
179 } 177 }
180 fn source(&self) -> InFile<SyntaxNodePtr> { 178 fn fix_source(&self) -> InFile<SyntaxNodePtr> {
181 InFile { file_id: self.file, value: self.expr.clone().into() } 179 InFile { file_id: self.file, value: self.expr.clone().into() }
182 } 180 }
183 fn as_any(&self) -> &(dyn Any + Send + 'static) { 181 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -190,8 +188,7 @@ impl AstDiagnostic for BreakOutsideOfLoop {
190 188
191 fn ast(&self, db: &dyn AstDatabase) -> Self::AST { 189 fn ast(&self, db: &dyn AstDatabase) -> Self::AST {
192 let root = db.parse_or_expand(self.file).unwrap(); 190 let root = db.parse_or_expand(self.file).unwrap();
193 let node = self.source().value.to_node(&root); 191 self.expr.to_node(&root)
194 ast::Expr::cast(node).unwrap()
195 } 192 }
196} 193}
197 194
@@ -205,7 +202,7 @@ impl Diagnostic for MissingUnsafe {
205 fn message(&self) -> String { 202 fn message(&self) -> String {
206 format!("This operation is unsafe and requires an unsafe function or block") 203 format!("This operation is unsafe and requires an unsafe function or block")
207 } 204 }
208 fn source(&self) -> InFile<SyntaxNodePtr> { 205 fn fix_source(&self) -> InFile<SyntaxNodePtr> {
209 InFile { file_id: self.file, value: self.expr.clone().into() } 206 InFile { file_id: self.file, value: self.expr.clone().into() }
210 } 207 }
211 fn as_any(&self) -> &(dyn Any + Send + 'static) { 208 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -217,9 +214,8 @@ impl AstDiagnostic for MissingUnsafe {
217 type AST = ast::Expr; 214 type AST = ast::Expr;
218 215
219 fn ast(&self, db: &dyn AstDatabase) -> Self::AST { 216 fn ast(&self, db: &dyn AstDatabase) -> Self::AST {
220 let root = db.parse_or_expand(self.source().file_id).unwrap(); 217 let root = db.parse_or_expand(self.file).unwrap();
221 let node = self.source().value.to_node(&root); 218 self.expr.to_node(&root)
222 ast::Expr::cast(node).unwrap()
223 } 219 }
224} 220}
225 221
@@ -236,7 +232,7 @@ impl Diagnostic for MismatchedArgCount {
236 let s = if self.expected == 1 { "" } else { "s" }; 232 let s = if self.expected == 1 { "" } else { "s" };
237 format!("Expected {} argument{}, found {}", self.expected, s, self.found) 233 format!("Expected {} argument{}, found {}", self.expected, s, self.found)
238 } 234 }
239 fn source(&self) -> InFile<SyntaxNodePtr> { 235 fn fix_source(&self) -> InFile<SyntaxNodePtr> {
240 InFile { file_id: self.file, value: self.call_expr.clone().into() } 236 InFile { file_id: self.file, value: self.call_expr.clone().into() }
241 } 237 }
242 fn as_any(&self) -> &(dyn Any + Send + 'static) { 238 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -250,7 +246,7 @@ impl Diagnostic for MismatchedArgCount {
250impl AstDiagnostic for MismatchedArgCount { 246impl AstDiagnostic for MismatchedArgCount {
251 type AST = ast::CallExpr; 247 type AST = ast::CallExpr;
252 fn ast(&self, db: &dyn AstDatabase) -> Self::AST { 248 fn ast(&self, db: &dyn AstDatabase) -> Self::AST {
253 let root = db.parse_or_expand(self.source().file_id).unwrap(); 249 let root = db.parse_or_expand(self.file).unwrap();
254 let node = self.source().value.to_node(&root); 250 let node = self.source().value.to_node(&root);
255 ast::CallExpr::cast(node).unwrap() 251 ast::CallExpr::cast(node).unwrap()
256 } 252 }
@@ -308,12 +304,11 @@ mod tests {
308 let mut actual: FxHashMap<FileId, Vec<(TextRange, String)>> = FxHashMap::default(); 304 let mut actual: FxHashMap<FileId, Vec<(TextRange, String)>> = FxHashMap::default();
309 db.diagnostics(|d| { 305 db.diagnostics(|d| {
310 // FXIME: macros... 306 // FXIME: macros...
311 let file_id = d.source().file_id.original_file(&db); 307 let source = d.source();
312 let highlighting_source = d.highlighting_source(); 308 let root = db.parse_or_expand(source.file_id).unwrap();
313 let node = db.parse_or_expand(highlighting_source.file_id).unwrap(); 309 let range = source.value.to_node(&root).text_range();
314 let range = highlighting_source.value.to_node(&node).text_range();
315 let message = d.message().to_owned(); 310 let message = d.message().to_owned();
316 actual.entry(file_id).or_default().push((range, message)); 311 actual.entry(source.file_id.original_file(&db)).or_default().push((range, message));
317 }); 312 });
318 313
319 for (file_id, diags) in actual.iter_mut() { 314 for (file_id, diags) in actual.iter_mut() {