aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs39
1 files changed, 20 insertions, 19 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs
index 24435e8a7..7ab7f79db 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 presentation(&self) -> InFile<SyntaxNodePtr> { 40 fn display_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
@@ -63,7 +63,7 @@ impl Diagnostic for MissingFields {
63 buf 63 buf
64 } 64 }
65 65
66 fn presentation(&self) -> InFile<SyntaxNodePtr> { 66 fn display_source(&self) -> InFile<SyntaxNodePtr> {
67 InFile { 67 InFile {
68 file_id: self.file, 68 file_id: self.file,
69 value: self 69 value: self
@@ -95,13 +95,15 @@ impl Diagnostic for MissingPatFields {
95 } 95 }
96 buf 96 buf
97 } 97 }
98 fn presentation(&self) -> InFile<SyntaxNodePtr> { 98 fn display_source(&self) -> InFile<SyntaxNodePtr> {
99 let value = self 99 InFile {
100 .field_list_parent_path 100 file_id: self.file,
101 .clone() 101 value: self
102 .map(SyntaxNodePtr::from) 102 .field_list_parent_path
103 .unwrap_or_else(|| self.field_list_parent.clone().into()); 103 .clone()
104 InFile { file_id: self.file, value } 104 .map(SyntaxNodePtr::from)
105 .unwrap_or_else(|| self.field_list_parent.clone().into()),
106 }
105 } 107 }
106 fn as_any(&self) -> &(dyn Any + Send + 'static) { 108 fn as_any(&self) -> &(dyn Any + Send + 'static) {
107 self 109 self
@@ -119,7 +121,7 @@ impl Diagnostic for MissingMatchArms {
119 fn message(&self) -> String { 121 fn message(&self) -> String {
120 String::from("Missing match arm") 122 String::from("Missing match arm")
121 } 123 }
122 fn presentation(&self) -> InFile<SyntaxNodePtr> { 124 fn display_source(&self) -> InFile<SyntaxNodePtr> {
123 InFile { file_id: self.file, value: self.match_expr.clone().into() } 125 InFile { file_id: self.file, value: self.match_expr.clone().into() }
124 } 126 }
125 fn as_any(&self) -> &(dyn Any + Send + 'static) { 127 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -137,7 +139,7 @@ impl Diagnostic for MissingOkInTailExpr {
137 fn message(&self) -> String { 139 fn message(&self) -> String {
138 "wrap return expression in Ok".to_string() 140 "wrap return expression in Ok".to_string()
139 } 141 }
140 fn presentation(&self) -> InFile<SyntaxNodePtr> { 142 fn display_source(&self) -> InFile<SyntaxNodePtr> {
141 InFile { file_id: self.file, value: self.expr.clone().into() } 143 InFile { file_id: self.file, value: self.expr.clone().into() }
142 } 144 }
143 fn as_any(&self) -> &(dyn Any + Send + 'static) { 145 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -155,7 +157,7 @@ impl Diagnostic for BreakOutsideOfLoop {
155 fn message(&self) -> String { 157 fn message(&self) -> String {
156 "break outside of loop".to_string() 158 "break outside of loop".to_string()
157 } 159 }
158 fn presentation(&self) -> InFile<SyntaxNodePtr> { 160 fn display_source(&self) -> InFile<SyntaxNodePtr> {
159 InFile { file_id: self.file, value: self.expr.clone().into() } 161 InFile { file_id: self.file, value: self.expr.clone().into() }
160 } 162 }
161 fn as_any(&self) -> &(dyn Any + Send + 'static) { 163 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -173,7 +175,7 @@ impl Diagnostic for MissingUnsafe {
173 fn message(&self) -> String { 175 fn message(&self) -> String {
174 format!("This operation is unsafe and requires an unsafe function or block") 176 format!("This operation is unsafe and requires an unsafe function or block")
175 } 177 }
176 fn presentation(&self) -> InFile<SyntaxNodePtr> { 178 fn display_source(&self) -> InFile<SyntaxNodePtr> {
177 InFile { file_id: self.file, value: self.expr.clone().into() } 179 InFile { file_id: self.file, value: self.expr.clone().into() }
178 } 180 }
179 fn as_any(&self) -> &(dyn Any + Send + 'static) { 181 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -194,7 +196,7 @@ impl Diagnostic for MismatchedArgCount {
194 let s = if self.expected == 1 { "" } else { "s" }; 196 let s = if self.expected == 1 { "" } else { "s" };
195 format!("Expected {} argument{}, found {}", self.expected, s, self.found) 197 format!("Expected {} argument{}, found {}", self.expected, s, self.found)
196 } 198 }
197 fn presentation(&self) -> InFile<SyntaxNodePtr> { 199 fn display_source(&self) -> InFile<SyntaxNodePtr> {
198 InFile { file_id: self.file, value: self.call_expr.clone().into() } 200 InFile { file_id: self.file, value: self.call_expr.clone().into() }
199 } 201 }
200 fn as_any(&self) -> &(dyn Any + Send + 'static) { 202 fn as_any(&self) -> &(dyn Any + Send + 'static) {
@@ -256,12 +258,11 @@ mod tests {
256 258
257 let mut actual: FxHashMap<FileId, Vec<(TextRange, String)>> = FxHashMap::default(); 259 let mut actual: FxHashMap<FileId, Vec<(TextRange, String)>> = FxHashMap::default();
258 db.diagnostics(|d| { 260 db.diagnostics(|d| {
261 let src = d.display_source();
262 let root = db.parse_or_expand(src.file_id).unwrap();
259 // FIXME: macros... 263 // FIXME: macros...
260 let diagnostics_presentation = d.presentation(); 264 let file_id = src.file_id.original_file(&db);
261 let root = db.parse_or_expand(diagnostics_presentation.file_id).unwrap(); 265 let range = src.value.to_node(&root).text_range();
262
263 let file_id = diagnostics_presentation.file_id.original_file(&db);
264 let range = diagnostics_presentation.value.to_node(&root).text_range();
265 let message = d.message().to_owned(); 266 let message = d.message().to_owned();
266 actual.entry(file_id).or_default().push((range, message)); 267 actual.entry(file_id).or_default().push((range, message));
267 }); 268 });