Restore accidentally removed public method

This commit is contained in:
Kirill Bulatov 2020-07-27 23:56:57 +03:00
parent cb0b13a583
commit 21184a1b2a
2 changed files with 11 additions and 10 deletions

View file

@ -16,7 +16,7 @@
use std::{any::Any, fmt};
use ra_syntax::SyntaxNodePtr;
use ra_syntax::{SyntaxNode, SyntaxNodePtr};
use crate::{db::AstDatabase, InFile};
@ -38,6 +38,11 @@ pub trait AstDiagnostic {
}
impl dyn Diagnostic {
pub fn syntax_node(&self, db: &impl AstDatabase) -> SyntaxNode {
let node = db.parse_or_expand(self.source().file_id).unwrap();
self.source().value.to_node(&node)
}
pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> {
self.as_any().downcast_ref()
}

View file

@ -262,10 +262,7 @@ impl AstDiagnostic for MismatchedArgCount {
#[cfg(test)]
mod tests {
use hir_def::{db::DefDatabase, AssocItemId, ModuleDefId};
use hir_expand::{
db::AstDatabase,
diagnostics::{Diagnostic, DiagnosticSinkBuilder},
};
use hir_expand::diagnostics::{Diagnostic, DiagnosticSinkBuilder};
use ra_db::{fixture::WithFixture, FileId, SourceDatabase, SourceDatabaseExt};
use ra_syntax::{TextRange, TextSize};
use rustc_hash::FxHashMap;
@ -310,12 +307,11 @@ mod tests {
let mut actual: FxHashMap<FileId, Vec<(TextRange, String)>> = FxHashMap::default();
db.diagnostics(|d| {
// FXIME: macros...
let source = d.source();
let root = db.parse_or_expand(source.file_id).unwrap();
let range = source.value.to_node(&root).text_range();
// FIXME: macros...
let file_id = d.source().file_id.original_file(&db);
let range = d.syntax_node(&db).text_range();
let message = d.message().to_owned();
actual.entry(source.file_id.original_file(&db)).or_default().push((range, message));
actual.entry(file_id).or_default().push((range, message));
});
for (file_id, diags) in actual.iter_mut() {