aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/diagnostics/fixes
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-13 18:13:15 +0100
committerAleksey Kladov <[email protected]>2021-06-13 18:14:12 +0100
commit74f3cca85ab870614f314c6180e2fbb883ad4fe3 (patch)
tree69f0f7aac85ae2fe0a6907a956b94b0bd434ea7e /crates/ide/src/diagnostics/fixes
parent8d391ec981562785ec92ce3afe950972c523f925 (diff)
internal: refactor remove this semicolon diagnostics
Diffstat (limited to 'crates/ide/src/diagnostics/fixes')
-rw-r--r--crates/ide/src/diagnostics/fixes/create_field.rs1
-rw-r--r--crates/ide/src/diagnostics/fixes/remove_semicolon.rs41
2 files changed, 0 insertions, 42 deletions
diff --git a/crates/ide/src/diagnostics/fixes/create_field.rs b/crates/ide/src/diagnostics/fixes/create_field.rs
deleted file mode 100644
index 8b1378917..000000000
--- a/crates/ide/src/diagnostics/fixes/create_field.rs
+++ /dev/null
@@ -1 +0,0 @@
1
diff --git a/crates/ide/src/diagnostics/fixes/remove_semicolon.rs b/crates/ide/src/diagnostics/fixes/remove_semicolon.rs
deleted file mode 100644
index f1724d479..000000000
--- a/crates/ide/src/diagnostics/fixes/remove_semicolon.rs
+++ /dev/null
@@ -1,41 +0,0 @@
1use hir::{db::AstDatabase, diagnostics::RemoveThisSemicolon, Semantics};
2use ide_assists::{Assist, AssistResolveStrategy};
3use ide_db::{source_change::SourceChange, RootDatabase};
4use syntax::{ast, AstNode};
5use text_edit::TextEdit;
6
7use crate::diagnostics::{fix, DiagnosticWithFixes};
8
9impl DiagnosticWithFixes for RemoveThisSemicolon {
10 fn fixes(
11 &self,
12 sema: &Semantics<RootDatabase>,
13 _resolve: &AssistResolveStrategy,
14 ) -> Option<Vec<Assist>> {
15 let root = sema.db.parse_or_expand(self.file)?;
16
17 let semicolon = self
18 .expr
19 .to_node(&root)
20 .syntax()
21 .parent()
22 .and_then(ast::ExprStmt::cast)
23 .and_then(|expr| expr.semicolon_token())?
24 .text_range();
25
26 let edit = TextEdit::delete(semicolon);
27 let source_change = SourceChange::from_text_edit(self.file.original_file(sema.db), edit);
28
29 Some(vec![fix("remove_semicolon", "Remove this semicolon", source_change, semicolon)])
30 }
31}
32
33#[cfg(test)]
34mod tests {
35 use crate::diagnostics::tests::check_fix;
36
37 #[test]
38 fn remove_semicolon() {
39 check_fix(r#"fn f() -> i32 { 92$0; }"#, r#"fn f() -> i32 { 92 }"#);
40 }
41}