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 std::{any::Any, fmt};
use ra_syntax::SyntaxNodePtr; use ra_syntax::{SyntaxNode, SyntaxNodePtr};
use crate::{db::AstDatabase, InFile}; use crate::{db::AstDatabase, InFile};
@ -38,6 +38,11 @@ pub trait AstDiagnostic {
} }
impl dyn Diagnostic { 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> { pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> {
self.as_any().downcast_ref() self.as_any().downcast_ref()
} }

View file

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