From 21184a1b2a4bea57a7666432749b171414136c60 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 27 Jul 2020 23:56:57 +0300 Subject: [PATCH] Restore accidentally removed public method --- crates/ra_hir_expand/src/diagnostics.rs | 7 ++++++- 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 074a8c45e8..23f28a7f71 100644 --- a/crates/ra_hir_expand/src/diagnostics.rs +++ b/crates/ra_hir_expand/src/diagnostics.rs @@ -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(&self) -> Option<&D> { self.as_any().downcast_ref() } diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 48b578fb0e..9d29f30716 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 { #[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> = 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() {