From 74f3cca85ab870614f314c6180e2fbb883ad4fe3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 20:13:15 +0300 Subject: internal: refactor remove this semicolon diagnostics --- crates/ide/src/diagnostics/fixes/create_field.rs | 1 - .../ide/src/diagnostics/fixes/remove_semicolon.rs | 41 ---------------------- 2 files changed, 42 deletions(-) delete mode 100644 crates/ide/src/diagnostics/fixes/create_field.rs delete mode 100644 crates/ide/src/diagnostics/fixes/remove_semicolon.rs (limited to 'crates/ide/src/diagnostics/fixes') 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 @@ - 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 @@ -use hir::{db::AstDatabase, diagnostics::RemoveThisSemicolon, Semantics}; -use ide_assists::{Assist, AssistResolveStrategy}; -use ide_db::{source_change::SourceChange, RootDatabase}; -use syntax::{ast, AstNode}; -use text_edit::TextEdit; - -use crate::diagnostics::{fix, DiagnosticWithFixes}; - -impl DiagnosticWithFixes for RemoveThisSemicolon { - fn fixes( - &self, - sema: &Semantics, - _resolve: &AssistResolveStrategy, - ) -> Option> { - let root = sema.db.parse_or_expand(self.file)?; - - let semicolon = self - .expr - .to_node(&root) - .syntax() - .parent() - .and_then(ast::ExprStmt::cast) - .and_then(|expr| expr.semicolon_token())? - .text_range(); - - let edit = TextEdit::delete(semicolon); - let source_change = SourceChange::from_text_edit(self.file.original_file(sema.db), edit); - - Some(vec![fix("remove_semicolon", "Remove this semicolon", source_change, semicolon)]) - } -} - -#[cfg(test)] -mod tests { - use crate::diagnostics::tests::check_fix; - - #[test] - fn remove_semicolon() { - check_fix(r#"fn f() -> i32 { 92$0; }"#, r#"fn f() -> i32 { 92 }"#); - } -} -- cgit v1.2.3