aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/diagnostics/remove_this_semicolon.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/diagnostics/remove_this_semicolon.rs')
-rw-r--r--crates/ide/src/diagnostics/remove_this_semicolon.rs64
1 files changed, 0 insertions, 64 deletions
diff --git a/crates/ide/src/diagnostics/remove_this_semicolon.rs b/crates/ide/src/diagnostics/remove_this_semicolon.rs
deleted file mode 100644
index 814cb0f8c..000000000
--- a/crates/ide/src/diagnostics/remove_this_semicolon.rs
+++ /dev/null
@@ -1,64 +0,0 @@
1use hir::db::AstDatabase;
2use ide_db::source_change::SourceChange;
3use syntax::{ast, AstNode};
4use text_edit::TextEdit;
5
6use crate::{
7 diagnostics::{fix, Diagnostic, DiagnosticsContext},
8 Assist,
9};
10
11// Diagnostic: remove-this-semicolon
12//
13// This diagnostic is triggered when there's an erroneous `;` at the end of the block.
14pub(super) fn remove_this_semicolon(
15 ctx: &DiagnosticsContext<'_>,
16 d: &hir::RemoveThisSemicolon,
17) -> Diagnostic {
18 Diagnostic::new(
19 "remove-this-semicolon",
20 "remove this semicolon",
21 ctx.sema.diagnostics_display_range(d.expr.clone().map(|it| it.into())).range,
22 )
23 .with_fixes(fixes(ctx, d))
24}
25
26fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::RemoveThisSemicolon) -> Option<Vec<Assist>> {
27 let root = ctx.sema.db.parse_or_expand(d.expr.file_id)?;
28
29 let semicolon = d
30 .expr
31 .value
32 .to_node(&root)
33 .syntax()
34 .parent()
35 .and_then(ast::ExprStmt::cast)
36 .and_then(|expr| expr.semicolon_token())?
37 .text_range();
38
39 let edit = TextEdit::delete(semicolon);
40 let source_change =
41 SourceChange::from_text_edit(d.expr.file_id.original_file(ctx.sema.db), edit);
42
43 Some(vec![fix("remove_semicolon", "Remove this semicolon", source_change, semicolon)])
44}
45
46#[cfg(test)]
47mod tests {
48 use crate::diagnostics::tests::{check_diagnostics, check_fix};
49
50 #[test]
51 fn missing_semicolon() {
52 check_diagnostics(
53 r#"
54fn test() -> i32 { 123; }
55 //^^^ remove this semicolon
56"#,
57 );
58 }
59
60 #[test]
61 fn remove_semicolon() {
62 check_fix(r#"fn f() -> i32 { 92$0; }"#, r#"fn f() -> i32 { 92 }"#);
63 }
64}