Require source implementations for Diagnostic

This commit is contained in:
Kirill Bulatov 2020-07-28 10:24:59 +03:00
parent 21184a1b2a
commit cfbbd91a88
3 changed files with 15 additions and 12 deletions

View file

@ -22,9 +22,11 @@ use crate::{db::AstDatabase, InFile};
pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
fn message(&self) -> String;
fn fix_source(&self) -> InFile<SyntaxNodePtr>;
fn source(&self) -> InFile<SyntaxNodePtr> {
self.fix_source()
/// A source to be used in highlighting and other visual representations
fn source(&self) -> InFile<SyntaxNodePtr>;
/// A source to be used during the fix application
fn fix_source(&self) -> InFile<SyntaxNodePtr> {
self.source()
}
fn as_any(&self) -> &(dyn Any + Send + 'static);
fn is_experimental(&self) -> bool {
@ -39,8 +41,9 @@ 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)
let source = self.source();
let node = db.parse_or_expand(source.file_id).unwrap();
source.value.to_node(&node)
}
pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> {