aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/diagnostics.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-27 14:46:02 +0000
committerAleksey Kladov <[email protected]>2019-11-27 18:16:00 +0000
commita87579500a2c35597071efd0ad6983927f0c1815 (patch)
tree9805b3dcbf8d767b2fc0623f42794068f3660d44 /crates/ra_hir/src/diagnostics.rs
parent368653081558ab389c6543d6b5027859e26beb3b (diff)
Move Ty
Diffstat (limited to 'crates/ra_hir/src/diagnostics.rs')
-rw-r--r--crates/ra_hir/src/diagnostics.rs91
1 files changed, 1 insertions, 90 deletions
diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs
index 6db499e06..a9040ea3d 100644
--- a/crates/ra_hir/src/diagnostics.rs
+++ b/crates/ra_hir/src/diagnostics.rs
@@ -1,93 +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 use std::fmt::Write;
43 let mut message = String::from("Missing structure fields:\n");
44 for field in &self.missed_fields {
45 write!(message, "- {}\n", field).unwrap();
46 }
47 message
48 }
49 fn source(&self) -> Source<SyntaxNodePtr> {
50 Source { file_id: self.file, value: self.field_list.into() }
51 }
52 fn as_any(&self) -> &(dyn Any + Send + 'static) {
53 self
54 }
55}
56
57impl AstDiagnostic for MissingFields {
58 type AST = ast::RecordFieldList;
59
60 fn ast(&self, db: &impl AstDatabase) -> Self::AST {
61 let root = db.parse_or_expand(self.source().file_id).unwrap();
62 let node = self.source().value.to_node(&root);
63 ast::RecordFieldList::cast(node).unwrap()
64 }
65}
66
67#[derive(Debug)]
68pub struct MissingOkInTailExpr {
69 pub file: HirFileId,
70 pub expr: AstPtr<ast::Expr>,
71}
72
73impl Diagnostic for MissingOkInTailExpr {
74 fn message(&self) -> String {
75 "wrap return expression in Ok".to_string()
76 }
77 fn source(&self) -> Source<SyntaxNodePtr> {
78 Source { file_id: self.file, value: self.expr.into() }
79 }
80 fn as_any(&self) -> &(dyn Any + Send + 'static) {
81 self
82 }
83}
84
85impl AstDiagnostic for MissingOkInTailExpr {
86 type AST = ast::Expr;
87
88 fn ast(&self, db: &impl AstDatabase) -> Self::AST {
89 let root = db.parse_or_expand(self.file).unwrap();
90 let node = self.source().value.to_node(&root);
91 ast::Expr::cast(node).unwrap()
92 }
93}