diff options
author | Seivan Heidari <[email protected]> | 2019-11-28 07:19:14 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-11-28 07:19:14 +0000 |
commit | 18a0937585b836ec5ed054b9ae48e0156ab6d9ef (patch) | |
tree | 9de2c0267ddcc00df717f90034d0843d751a851b /crates/ra_hir/src/diagnostics.rs | |
parent | a7394b44c870f585eacfeb3036a33471aff49ff8 (diff) | |
parent | 484acc8a61d599662ed63a4cbda091d38a982551 (diff) |
Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer into feature/themes
Diffstat (limited to 'crates/ra_hir/src/diagnostics.rs')
-rw-r--r-- | crates/ra_hir/src/diagnostics.rs | 86 |
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 | |||
3 | use std::any::Any; | ||
4 | |||
5 | use hir_expand::HirFileId; | ||
6 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; | ||
7 | |||
8 | use crate::{db::AstDatabase, Name, Source}; | ||
9 | |||
10 | pub use hir_def::diagnostics::UnresolvedModule; | 2 | pub use hir_def::diagnostics::UnresolvedModule; |
11 | pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; | 3 | pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; |
12 | 4 | pub use hir_ty::diagnostics::{MissingFields, MissingOkInTailExpr, NoSuchField}; | |
13 | #[derive(Debug)] | ||
14 | pub struct NoSuchField { | ||
15 | pub file: HirFileId, | ||
16 | pub field: AstPtr<ast::RecordField>, | ||
17 | } | ||
18 | |||
19 | impl 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)] | ||
34 | pub struct MissingFields { | ||
35 | pub file: HirFileId, | ||
36 | pub field_list: AstPtr<ast::RecordFieldList>, | ||
37 | pub missed_fields: Vec<Name>, | ||
38 | } | ||
39 | |||
40 | impl 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 | |||
52 | impl 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)] | ||
63 | pub struct MissingOkInTailExpr { | ||
64 | pub file: HirFileId, | ||
65 | pub expr: AstPtr<ast::Expr>, | ||
66 | } | ||
67 | |||
68 | impl 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 | |||
80 | impl 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 | } | ||