2019-09-30 03:58:53 -05:00
|
|
|
//! FIXME: write short doc here
|
|
|
|
|
2019-11-02 15:42:38 -05:00
|
|
|
use std::any::Any;
|
2019-03-21 14:13:11 -05:00
|
|
|
|
2019-11-24 05:02:08 -06:00
|
|
|
use hir_expand::HirFileId;
|
2019-11-02 15:42:38 -05:00
|
|
|
use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr};
|
2019-03-23 08:28:47 -05:00
|
|
|
|
2019-11-24 05:02:08 -06:00
|
|
|
use crate::{db::AstDatabase, Name, Source};
|
2019-03-23 08:28:47 -05:00
|
|
|
|
2019-10-31 10:45:10 -05:00
|
|
|
pub use hir_def::diagnostics::UnresolvedModule;
|
2019-11-02 15:42:38 -05:00
|
|
|
pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink};
|
2019-03-23 08:28:47 -05:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct NoSuchField {
|
2019-03-23 10:35:14 -05:00
|
|
|
pub file: HirFileId,
|
2019-08-23 07:55:21 -05:00
|
|
|
pub field: AstPtr<ast::RecordField>,
|
2019-03-23 08:28:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Diagnostic for NoSuchField {
|
2019-03-23 12:41:59 -05:00
|
|
|
fn message(&self) -> String {
|
|
|
|
"no such field".to_string()
|
|
|
|
}
|
2019-08-12 11:06:08 -05:00
|
|
|
|
|
|
|
fn source(&self) -> Source<SyntaxNodePtr> {
|
2019-11-20 00:40:36 -06:00
|
|
|
Source { file_id: self.file, value: self.field.into() }
|
2019-03-23 08:28:47 -05:00
|
|
|
}
|
2019-08-12 11:06:08 -05:00
|
|
|
|
2019-06-05 21:06:46 -05:00
|
|
|
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
2019-03-23 08:28:47 -05:00
|
|
|
self
|
|
|
|
}
|
2019-03-21 14:13:11 -05:00
|
|
|
}
|
2019-03-23 10:35:14 -05:00
|
|
|
|
2019-04-10 16:00:56 -05:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct MissingFields {
|
|
|
|
pub file: HirFileId,
|
2019-08-23 07:55:21 -05:00
|
|
|
pub field_list: AstPtr<ast::RecordFieldList>,
|
2019-04-10 16:00:56 -05:00
|
|
|
pub missed_fields: Vec<Name>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Diagnostic for MissingFields {
|
|
|
|
fn message(&self) -> String {
|
|
|
|
"fill structure fields".to_string()
|
|
|
|
}
|
2019-08-12 11:06:08 -05:00
|
|
|
fn source(&self) -> Source<SyntaxNodePtr> {
|
2019-11-20 00:40:36 -06:00
|
|
|
Source { file_id: self.file, value: self.field_list.into() }
|
2019-04-10 16:00:56 -05:00
|
|
|
}
|
|
|
|
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
2019-07-05 11:40:02 -05:00
|
|
|
|
|
|
|
impl AstDiagnostic for MissingFields {
|
2019-08-23 07:55:21 -05:00
|
|
|
type AST = ast::RecordFieldList;
|
2019-07-05 11:40:02 -05:00
|
|
|
|
2019-11-02 15:42:38 -05:00
|
|
|
fn ast(&self, db: &impl AstDatabase) -> Self::AST {
|
2019-08-12 11:06:08 -05:00
|
|
|
let root = db.parse_or_expand(self.source().file_id).unwrap();
|
2019-11-20 00:40:36 -06:00
|
|
|
let node = self.source().value.to_node(&root);
|
2019-08-23 07:55:21 -05:00
|
|
|
ast::RecordFieldList::cast(node).unwrap()
|
2019-07-05 11:40:02 -05:00
|
|
|
}
|
|
|
|
}
|
2019-08-10 10:40:48 -05:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct MissingOkInTailExpr {
|
|
|
|
pub file: HirFileId,
|
|
|
|
pub expr: AstPtr<ast::Expr>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Diagnostic for MissingOkInTailExpr {
|
|
|
|
fn message(&self) -> String {
|
|
|
|
"wrap return expression in Ok".to_string()
|
|
|
|
}
|
2019-08-13 01:31:06 -05:00
|
|
|
fn source(&self) -> Source<SyntaxNodePtr> {
|
2019-11-20 00:40:36 -06:00
|
|
|
Source { file_id: self.file, value: self.expr.into() }
|
2019-08-10 10:40:48 -05:00
|
|
|
}
|
|
|
|
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AstDiagnostic for MissingOkInTailExpr {
|
|
|
|
type AST = ast::Expr;
|
|
|
|
|
2019-11-02 15:42:38 -05:00
|
|
|
fn ast(&self, db: &impl AstDatabase) -> Self::AST {
|
2019-08-13 01:31:06 -05:00
|
|
|
let root = db.parse_or_expand(self.file).unwrap();
|
2019-11-20 00:40:36 -06:00
|
|
|
let node = self.source().value.to_node(&root);
|
2019-08-10 10:40:48 -05:00
|
|
|
ast::Expr::cast(node).unwrap()
|
|
|
|
}
|
|
|
|
}
|