aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src
diff options
context:
space:
mode:
authorivan770 <[email protected]>2020-12-08 18:47:20 +0000
committerivan770 <[email protected]>2020-12-08 18:47:20 +0000
commitcb66bb8ff9609d4fc3702ac1ed6197802b54e473 (patch)
treebebe4b12adb6916a5a5eefdc50be523028368987 /crates/ide/src
parente2e6b709e60f22279b755ceae74e579520c9ae3b (diff)
Remove this semicolon
Diffstat (limited to 'crates/ide/src')
-rw-r--r--crates/ide/src/diagnostics.rs3
-rw-r--r--crates/ide/src/diagnostics/fixes.rs26
2 files changed, 23 insertions, 6 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index c8453edb3..9157704dc 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 d275dd75b..cb4d49ad9 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, Semantics, VariantDef, 9 HasSource, HirDisplay, Semantics, VariantDef,
10}; 10};
@@ -13,11 +13,7 @@ use ide_db::{
13 source_change::{FileSystemEdit, SourceFileEdit}, 13 source_change::{FileSystemEdit, SourceFileEdit},
14 RootDatabase, 14 RootDatabase,
15}; 15};
16use syntax::{ 16use syntax::{AstNode, Direction, T, algo, ast::{self, ExprStmt, edit::IndentLevel, make}};
17 algo,
18 ast::{self, edit::IndentLevel, make},
19 AstNode,
20};
21use text_edit::TextEdit; 17use text_edit::TextEdit;
22 18
23use crate::{diagnostics::Fix, references::rename::rename_with_semantics, FilePosition}; 19use crate::{diagnostics::Fix, references::rename::rename_with_semantics, FilePosition};
@@ -102,6 +98,24 @@ impl DiagnosticWithFix for MissingOkInTailExpr {
102 } 98 }
103} 99}
104 100
101impl DiagnosticWithFix for RemoveThisSemicolon {
102 fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix> {
103 let root = sema.db.parse_or_expand(self.file)?;
104
105 let semicolon = self.expr.to_node(&root)
106 .syntax()
107 .siblings_with_tokens(Direction::Next)
108 .filter_map(|it| it.into_token())
109 .find(|it| it.kind() == T![;])?
110 .text_range();
111
112 let edit = TextEdit::delete(semicolon);
113 let source_change = SourceFileEdit { file_id: self.file.original_file(sema.db), edit }.into();
114
115 Some(Fix::new("Remove this semicolon", source_change, semicolon))
116 }
117}
118
105impl DiagnosticWithFix for IncorrectCase { 119impl DiagnosticWithFix for IncorrectCase {
106 fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix> { 120 fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix> {
107 let root = sema.db.parse_or_expand(self.file)?; 121 let root = sema.db.parse_or_expand(self.file)?;