aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/diagnostics
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-08-10 22:37:23 +0100
committerKirill Bulatov <[email protected]>2020-08-11 13:09:08 +0100
commit29fbc8e02180aac1f4d7819a9626206aa64028a0 (patch)
treeed97a21451cdb34a33ac984c7df035a5c29ca25e /crates/ra_ide/src/diagnostics
parent936861993935d5b2c78b953e2f4b719e1992bd73 (diff)
Move the DiagnosticsWithFix trait on the ide level
Diffstat (limited to 'crates/ra_ide/src/diagnostics')
-rw-r--r--crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs b/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs
new file mode 100644
index 000000000..8578a90ec
--- /dev/null
+++ b/crates/ra_ide/src/diagnostics/diagnostics_with_fix.rs
@@ -0,0 +1,46 @@
1use hir::{
2 db::AstDatabase,
3 diagnostics::{MissingFields, MissingOkInTailExpr, NoSuchField, UnresolvedModule},
4};
5use ra_syntax::ast;
6
7// TODO kb
8pub trait DiagnosticWithFix {
9 type AST;
10 fn fix_source(&self, db: &dyn AstDatabase) -> Option<Self::AST>;
11}
12
13impl DiagnosticWithFix for UnresolvedModule {
14 type AST = ast::Module;
15 fn fix_source(&self, db: &dyn AstDatabase) -> Option<Self::AST> {
16 let root = db.parse_or_expand(self.file)?;
17 Some(self.decl.to_node(&root))
18 }
19}
20
21impl DiagnosticWithFix for NoSuchField {
22 type AST = ast::RecordExprField;
23
24 fn fix_source(&self, db: &dyn AstDatabase) -> Option<Self::AST> {
25 let root = db.parse_or_expand(self.file)?;
26 Some(self.field.to_node(&root))
27 }
28}
29
30impl DiagnosticWithFix for MissingFields {
31 type AST = ast::RecordExpr;
32
33 fn fix_source(&self, db: &dyn AstDatabase) -> Option<Self::AST> {
34 let root = db.parse_or_expand(self.file)?;
35 Some(self.field_list_parent.to_node(&root))
36 }
37}
38
39impl DiagnosticWithFix for MissingOkInTailExpr {
40 type AST = ast::Expr;
41
42 fn fix_source(&self, db: &dyn AstDatabase) -> Option<Self::AST> {
43 let root = db.parse_or_expand(self.file)?;
44 Some(self.expr.to_node(&root))
45 }
46}