diff options
-rw-r--r-- | crates/ra_hir_expand/src/diagnostics.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics.rs | 14 |
2 files changed, 11 insertions, 10 deletions
diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs index 074a8c45e..23f28a7f7 100644 --- a/crates/ra_hir_expand/src/diagnostics.rs +++ b/crates/ra_hir_expand/src/diagnostics.rs | |||
@@ -16,7 +16,7 @@ | |||
16 | 16 | ||
17 | use std::{any::Any, fmt}; | 17 | use std::{any::Any, fmt}; |
18 | 18 | ||
19 | use ra_syntax::SyntaxNodePtr; | 19 | use ra_syntax::{SyntaxNode, SyntaxNodePtr}; |
20 | 20 | ||
21 | use crate::{db::AstDatabase, InFile}; | 21 | use crate::{db::AstDatabase, InFile}; |
22 | 22 | ||
@@ -38,6 +38,11 @@ pub trait AstDiagnostic { | |||
38 | } | 38 | } |
39 | 39 | ||
40 | impl dyn Diagnostic { | 40 | impl dyn Diagnostic { |
41 | pub fn syntax_node(&self, db: &impl AstDatabase) -> SyntaxNode { | ||
42 | let node = db.parse_or_expand(self.source().file_id).unwrap(); | ||
43 | self.source().value.to_node(&node) | ||
44 | } | ||
45 | |||
41 | pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { | 46 | pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { |
42 | self.as_any().downcast_ref() | 47 | self.as_any().downcast_ref() |
43 | } | 48 | } |
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 48b578fb0..9d29f3071 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs | |||
@@ -262,10 +262,7 @@ impl AstDiagnostic for MismatchedArgCount { | |||
262 | #[cfg(test)] | 262 | #[cfg(test)] |
263 | mod tests { | 263 | mod tests { |
264 | use hir_def::{db::DefDatabase, AssocItemId, ModuleDefId}; | 264 | use hir_def::{db::DefDatabase, AssocItemId, ModuleDefId}; |
265 | use hir_expand::{ | 265 | use hir_expand::diagnostics::{Diagnostic, DiagnosticSinkBuilder}; |
266 | db::AstDatabase, | ||
267 | diagnostics::{Diagnostic, DiagnosticSinkBuilder}, | ||
268 | }; | ||
269 | use ra_db::{fixture::WithFixture, FileId, SourceDatabase, SourceDatabaseExt}; | 266 | use ra_db::{fixture::WithFixture, FileId, SourceDatabase, SourceDatabaseExt}; |
270 | use ra_syntax::{TextRange, TextSize}; | 267 | use ra_syntax::{TextRange, TextSize}; |
271 | use rustc_hash::FxHashMap; | 268 | use rustc_hash::FxHashMap; |
@@ -310,12 +307,11 @@ mod tests { | |||
310 | 307 | ||
311 | let mut actual: FxHashMap<FileId, Vec<(TextRange, String)>> = FxHashMap::default(); | 308 | let mut actual: FxHashMap<FileId, Vec<(TextRange, String)>> = FxHashMap::default(); |
312 | db.diagnostics(|d| { | 309 | db.diagnostics(|d| { |
313 | // FXIME: macros... | 310 | // FIXME: macros... |
314 | let source = d.source(); | 311 | let file_id = d.source().file_id.original_file(&db); |
315 | let root = db.parse_or_expand(source.file_id).unwrap(); | 312 | let range = d.syntax_node(&db).text_range(); |
316 | let range = source.value.to_node(&root).text_range(); | ||
317 | let message = d.message().to_owned(); | 313 | let message = d.message().to_owned(); |
318 | actual.entry(source.file_id.original_file(&db)).or_default().push((range, message)); | 314 | actual.entry(file_id).or_default().push((range, message)); |
319 | }); | 315 | }); |
320 | 316 | ||
321 | for (file_id, diags) in actual.iter_mut() { | 317 | for (file_id, diags) in actual.iter_mut() { |