mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Require source implementations for Diagnostic
This commit is contained in:
parent
21184a1b2a
commit
cfbbd91a88
3 changed files with 15 additions and 12 deletions
|
@ -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> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue