diff options
author | Aleksey Kladov <[email protected]> | 2019-03-23 15:35:14 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-03-25 07:52:50 +0000 |
commit | 3fb88e95aa5e122a521beec766d5b1264ca4de3b (patch) | |
tree | 17e5815f78f81f04fd462605288e09e82c8caee8 /crates/ra_hir/src/diagnostics.rs | |
parent | fcca35969dd7c63a83ee34c4ce7d54cefdb72bbe (diff) |
switch modules to new diagnostics
Diffstat (limited to 'crates/ra_hir/src/diagnostics.rs')
-rw-r--r-- | crates/ra_hir/src/diagnostics.rs | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs index 46a3fdd47..e8bb1ed92 100644 --- a/crates/ra_hir/src/diagnostics.rs +++ b/crates/ra_hir/src/diagnostics.rs | |||
@@ -3,7 +3,20 @@ use std::{fmt, any::Any}; | |||
3 | use ra_syntax::{SyntaxNodePtr, AstPtr, ast}; | 3 | use ra_syntax::{SyntaxNodePtr, AstPtr, ast}; |
4 | 4 | ||
5 | use crate::HirFileId; | 5 | use crate::HirFileId; |
6 | use relative_path::RelativePathBuf; | ||
6 | 7 | ||
8 | /// Diagnostic defines hir API for errors and warnings. | ||
9 | /// | ||
10 | /// It is used as a `dyn` object, which you can downcast to a concrete | ||
11 | /// diagnostic. Diagnostics are structured, meaning that they include rich | ||
12 | /// information which can be used by IDE to create fixes. Diagnostics are | ||
13 | /// expressed in terms of macro-expanded syntax tree nodes (so, it's a bad idea | ||
14 | /// to diagnostic in a salsa value). | ||
15 | /// | ||
16 | /// Internally, various subsystems of hir produce diagnostics specific to a | ||
17 | /// subsytem (typically, an `enum`), which are safe to store in salsa but do not | ||
18 | /// include source locations. Such internal diagnostic are transformed into an | ||
19 | /// instance of `Diagnostic` on demand. | ||
7 | pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { | 20 | pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { |
8 | fn file(&self) -> HirFileId; | 21 | fn file(&self) -> HirFileId; |
9 | fn syntax_node(&self) -> SyntaxNodePtr; | 22 | fn syntax_node(&self) -> SyntaxNodePtr; |
@@ -34,14 +47,8 @@ impl Diagnostics { | |||
34 | 47 | ||
35 | #[derive(Debug)] | 48 | #[derive(Debug)] |
36 | pub struct NoSuchField { | 49 | pub struct NoSuchField { |
37 | pub(crate) file: HirFileId, | 50 | pub file: HirFileId, |
38 | pub(crate) field: AstPtr<ast::NamedField>, | 51 | pub field: AstPtr<ast::NamedField>, |
39 | } | ||
40 | |||
41 | impl NoSuchField { | ||
42 | pub fn field(&self) -> AstPtr<ast::NamedField> { | ||
43 | self.field | ||
44 | } | ||
45 | } | 52 | } |
46 | 53 | ||
47 | impl Diagnostic for NoSuchField { | 54 | impl Diagnostic for NoSuchField { |
@@ -58,3 +65,25 @@ impl Diagnostic for NoSuchField { | |||
58 | self | 65 | self |
59 | } | 66 | } |
60 | } | 67 | } |
68 | |||
69 | #[derive(Debug)] | ||
70 | pub struct UnresolvedModule { | ||
71 | pub file: HirFileId, | ||
72 | pub decl: AstPtr<ast::Module>, | ||
73 | pub candidate: RelativePathBuf, | ||
74 | } | ||
75 | |||
76 | impl Diagnostic for UnresolvedModule { | ||
77 | fn file(&self) -> HirFileId { | ||
78 | self.file | ||
79 | } | ||
80 | fn syntax_node(&self) -> SyntaxNodePtr { | ||
81 | self.decl.into() | ||
82 | } | ||
83 | fn message(&self) -> String { | ||
84 | "unresolved module".to_string() | ||
85 | } | ||
86 | fn as_any(&self) -> &(Any + Send + 'static) { | ||
87 | self | ||
88 | } | ||
89 | } | ||