aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src')
-rw-r--r--crates/ide/src/diagnostics.rs3
-rw-r--r--crates/ide/src/diagnostics/fixes.rs23
2 files changed, 25 insertions, 1 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index d09f3a0a1..049f808dc 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -131,6 +131,9 @@ pub(crate) fn diagnostics(
131 .on::<hir::diagnostics::NoSuchField, _>(|d| { 131 .on::<hir::diagnostics::NoSuchField, _>(|d| {
132 res.borrow_mut().push(diagnostic_with_fix(d, &sema)); 132 res.borrow_mut().push(diagnostic_with_fix(d, &sema));
133 }) 133 })
134 .on::<hir::diagnostics::RemoveThisSemicolon, _>(|d| {
135 res.borrow_mut().push(diagnostic_with_fix(d, &sema));
136 })
134 .on::<hir::diagnostics::IncorrectCase, _>(|d| { 137 .on::<hir::diagnostics::IncorrectCase, _>(|d| {
135 res.borrow_mut().push(warning_with_fix(d, &sema)); 138 res.borrow_mut().push(warning_with_fix(d, &sema));
136 }) 139 })
diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs
index a900d7bae..13240672f 100644
--- a/crates/ide/src/diagnostics/fixes.rs
+++ b/crates/ide/src/diagnostics/fixes.rs
@@ -4,7 +4,7 @@ use hir::{
4 db::AstDatabase, 4 db::AstDatabase,
5 diagnostics::{ 5 diagnostics::{
6 Diagnostic, IncorrectCase, MissingFields, MissingOkInTailExpr, NoSuchField, 6 Diagnostic, IncorrectCase, MissingFields, MissingOkInTailExpr, NoSuchField,
7 UnresolvedModule, 7 RemoveThisSemicolon, UnresolvedModule,
8 }, 8 },
9 HasSource, HirDisplay, InFile, Semantics, VariantDef, 9 HasSource, HirDisplay, InFile, Semantics, VariantDef,
10}; 10};
@@ -105,6 +105,27 @@ impl DiagnosticWithFix for MissingOkInTailExpr {
105 } 105 }
106} 106}
107 107
108impl DiagnosticWithFix for RemoveThisSemicolon {
109 fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix> {
110 let root = sema.db.parse_or_expand(self.file)?;
111
112 let semicolon = self
113 .expr
114 .to_node(&root)
115 .syntax()
116 .parent()
117 .and_then(ast::ExprStmt::cast)
118 .and_then(|expr| expr.semicolon_token())?
119 .text_range();
120
121 let edit = TextEdit::delete(semicolon);
122 let source_change =
123 SourceFileEdit { file_id: self.file.original_file(sema.db), edit }.into();
124
125 Some(Fix::new("Remove this semicolon", source_change, semicolon))
126 }
127}
128
108impl DiagnosticWithFix for IncorrectCase { 129impl DiagnosticWithFix for IncorrectCase {
109 fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix> { 130 fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix> {
110 let root = sema.db.parse_or_expand(self.file)?; 131 let root = sema.db.parse_or_expand(self.file)?;