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.rs45
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};
3use ra_syntax::{SyntaxNodePtr, AstPtr, ast}; 3use ra_syntax::{SyntaxNodePtr, AstPtr, ast};
4 4
5use crate::HirFileId; 5use crate::HirFileId;
6use 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.
7pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { 20pub 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)]
36pub struct NoSuchField { 49pub 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
41impl NoSuchField {
42 pub fn field(&self) -> AstPtr<ast::NamedField> {
43 self.field
44 }
45} 52}
46 53
47impl Diagnostic for NoSuchField { 54impl Diagnostic for NoSuchField {
@@ -58,3 +65,25 @@ impl Diagnostic for NoSuchField {
58 self 65 self
59 } 66 }
60} 67}
68
69#[derive(Debug)]
70pub struct UnresolvedModule {
71 pub file: HirFileId,
72 pub decl: AstPtr<ast::Module>,
73 pub candidate: RelativePathBuf,
74}
75
76impl 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}