aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/diagnostics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/diagnostics.rs')
-rw-r--r--crates/ra_hir/src/diagnostics.rs86
1 files changed, 1 insertions, 85 deletions
diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs
index dafacba70..a9040ea3d 100644
--- a/crates/ra_hir/src/diagnostics.rs
+++ b/crates/ra_hir/src/diagnostics.rs
@@ -1,88 +1,4 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2
3use std::any::Any;
4
5use hir_expand::HirFileId;
6use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr};
7
8use crate::{db::AstDatabase, Name, Source};
9
10pub use hir_def::diagnostics::UnresolvedModule; 2pub use hir_def::diagnostics::UnresolvedModule;
11pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; 3pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink};
12 4pub use hir_ty::diagnostics::{MissingFields, MissingOkInTailExpr, NoSuchField};
13#[derive(Debug)]
14pub struct NoSuchField {
15 pub file: HirFileId,
16 pub field: AstPtr<ast::RecordField>,
17}
18
19impl Diagnostic for NoSuchField {
20 fn message(&self) -> String {
21 "no such field".to_string()
22 }
23
24 fn source(&self) -> Source<SyntaxNodePtr> {
25 Source { file_id: self.file, value: self.field.into() }
26 }
27
28 fn as_any(&self) -> &(dyn Any + Send + 'static) {
29 self
30 }
31}
32
33#[derive(Debug)]
34pub struct MissingFields {
35 pub file: HirFileId,
36 pub field_list: AstPtr<ast::RecordFieldList>,
37 pub missed_fields: Vec<Name>,
38}
39
40impl Diagnostic for MissingFields {
41 fn message(&self) -> String {
42 "fill structure fields".to_string()
43 }
44 fn source(&self) -> Source<SyntaxNodePtr> {
45 Source { file_id: self.file, value: self.field_list.into() }
46 }
47 fn as_any(&self) -> &(dyn Any + Send + 'static) {
48 self
49 }
50}
51
52impl AstDiagnostic for MissingFields {
53 type AST = ast::RecordFieldList;
54
55 fn ast(&self, db: &impl AstDatabase) -> Self::AST {
56 let root = db.parse_or_expand(self.source().file_id).unwrap();
57 let node = self.source().value.to_node(&root);
58 ast::RecordFieldList::cast(node).unwrap()
59 }
60}
61
62#[derive(Debug)]
63pub struct MissingOkInTailExpr {
64 pub file: HirFileId,
65 pub expr: AstPtr<ast::Expr>,
66}
67
68impl Diagnostic for MissingOkInTailExpr {
69 fn message(&self) -> String {
70 "wrap return expression in Ok".to_string()
71 }
72 fn source(&self) -> Source<SyntaxNodePtr> {
73 Source { file_id: self.file, value: self.expr.into() }
74 }
75 fn as_any(&self) -> &(dyn Any + Send + 'static) {
76 self
77 }
78}
79
80impl AstDiagnostic for MissingOkInTailExpr {
81 type AST = ast::Expr;
82
83 fn ast(&self, db: &impl AstDatabase) -> Self::AST {
84 let root = db.parse_or_expand(self.file).unwrap();
85 let node = self.source().value.to_node(&root);
86 ast::Expr::cast(node).unwrap()
87 }
88}