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 {
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> {
"no such field".to_string()
}
- fn fix_source(&self) -> InFile<SyntaxNodePtr> {
+ fn source(&self) -> InFile<SyntaxNodePtr> {
InFile::new(self.file, self.field.clone().into())
}
fn message(&self) -> String {
String::from("Missing match arm")
}
- fn fix_source(&self) -> InFile<SyntaxNodePtr> {
+ fn source(&self) -> InFile<SyntaxNodePtr> {
InFile { file_id: self.file, value: self.match_expr.clone().into() }
}
fn as_any(&self) -> &(dyn Any + Send + 'static) {
fn message(&self) -> String {
"wrap return expression in Ok".to_string()
}
- fn fix_source(&self) -> InFile<SyntaxNodePtr> {
+ fn source(&self) -> InFile<SyntaxNodePtr> {
InFile { file_id: self.file, value: self.expr.clone().into() }
}
fn as_any(&self) -> &(dyn Any + Send + 'static) {
fn message(&self) -> String {
"break outside of loop".to_string()
}
- fn fix_source(&self) -> InFile<SyntaxNodePtr> {
+ fn source(&self) -> InFile<SyntaxNodePtr> {
InFile { file_id: self.file, value: self.expr.clone().into() }
}
fn as_any(&self) -> &(dyn Any + Send + 'static) {
fn message(&self) -> String {
format!("This operation is unsafe and requires an unsafe function or block")
}
- fn fix_source(&self) -> InFile<SyntaxNodePtr> {
+ fn source(&self) -> InFile<SyntaxNodePtr> {
InFile { file_id: self.file, value: self.expr.clone().into() }
}
fn as_any(&self) -> &(dyn Any + Send + 'static) {
let s = if self.expected == 1 { "" } else { "s" };
format!("Expected {} argument{}, found {}", self.expected, s, self.found)
}
- fn fix_source(&self) -> InFile<SyntaxNodePtr> {
+ fn source(&self) -> InFile<SyntaxNodePtr> {
InFile { file_id: self.file, value: self.call_expr.clone().into() }
}
fn as_any(&self) -> &(dyn Any + Send + 'static) {