diff options
Diffstat (limited to 'crates/ide/src/diagnostics')
-rw-r--r-- | crates/ide/src/diagnostics/field_shorthand.rs | 34 | ||||
-rw-r--r-- | crates/ide/src/diagnostics/fixes.rs | 2 |
2 files changed, 15 insertions, 21 deletions
diff --git a/crates/ide/src/diagnostics/field_shorthand.rs b/crates/ide/src/diagnostics/field_shorthand.rs index 2c4acd783..f41bcd619 100644 --- a/crates/ide/src/diagnostics/field_shorthand.rs +++ b/crates/ide/src/diagnostics/field_shorthand.rs | |||
@@ -1,12 +1,12 @@ | |||
1 | //! Suggests shortening `Foo { field: field }` to `Foo { field }` in both | 1 | //! Suggests shortening `Foo { field: field }` to `Foo { field }` in both |
2 | //! expressions and patterns. | 2 | //! expressions and patterns. |
3 | 3 | ||
4 | use base_db::FileId; | 4 | use ide_db::base_db::FileId; |
5 | use ide_db::source_change::SourceFileEdit; | 5 | use ide_db::source_change::SourceFileEdit; |
6 | use syntax::{ast, match_ast, AstNode, SyntaxNode}; | 6 | use syntax::{ast, match_ast, AstNode, SyntaxNode}; |
7 | use text_edit::TextEdit; | 7 | use text_edit::TextEdit; |
8 | 8 | ||
9 | use crate::{Diagnostic, Fix, Severity}; | 9 | use crate::{Diagnostic, Fix}; |
10 | 10 | ||
11 | pub(super) fn check(acc: &mut Vec<Diagnostic>, file_id: FileId, node: &SyntaxNode) { | 11 | pub(super) fn check(acc: &mut Vec<Diagnostic>, file_id: FileId, node: &SyntaxNode) { |
12 | match_ast! { | 12 | match_ast! { |
@@ -46,17 +46,15 @@ fn check_expr_field_shorthand( | |||
46 | let edit = edit_builder.finish(); | 46 | let edit = edit_builder.finish(); |
47 | 47 | ||
48 | let field_range = record_field.syntax().text_range(); | 48 | let field_range = record_field.syntax().text_range(); |
49 | acc.push(Diagnostic { | 49 | acc.push( |
50 | // name: None, | 50 | Diagnostic::hint(field_range, "Shorthand struct initialization".to_string()).with_fix( |
51 | range: field_range, | 51 | Some(Fix::new( |
52 | message: "Shorthand struct initialization".to_string(), | 52 | "Use struct shorthand initialization", |
53 | severity: Severity::WeakWarning, | 53 | SourceFileEdit { file_id, edit }.into(), |
54 | fix: Some(Fix::new( | 54 | field_range, |
55 | "Use struct shorthand initialization", | 55 | )), |
56 | SourceFileEdit { file_id, edit }.into(), | 56 | ), |
57 | field_range, | 57 | ); |
58 | )), | ||
59 | }); | ||
60 | } | 58 | } |
61 | } | 59 | } |
62 | 60 | ||
@@ -88,17 +86,13 @@ fn check_pat_field_shorthand( | |||
88 | let edit = edit_builder.finish(); | 86 | let edit = edit_builder.finish(); |
89 | 87 | ||
90 | let field_range = record_pat_field.syntax().text_range(); | 88 | let field_range = record_pat_field.syntax().text_range(); |
91 | acc.push(Diagnostic { | 89 | acc.push(Diagnostic::hint(field_range, "Shorthand struct pattern".to_string()).with_fix( |
92 | // name: None, | 90 | Some(Fix::new( |
93 | range: field_range, | ||
94 | message: "Shorthand struct pattern".to_string(), | ||
95 | severity: Severity::WeakWarning, | ||
96 | fix: Some(Fix::new( | ||
97 | "Use struct field shorthand", | 91 | "Use struct field shorthand", |
98 | SourceFileEdit { file_id, edit }.into(), | 92 | SourceFileEdit { file_id, edit }.into(), |
99 | field_range, | 93 | field_range, |
100 | )), | 94 | )), |
101 | }); | 95 | )); |
102 | } | 96 | } |
103 | } | 97 | } |
104 | 98 | ||
diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs index 0c75e50b0..0c950003e 100644 --- a/crates/ide/src/diagnostics/fixes.rs +++ b/crates/ide/src/diagnostics/fixes.rs | |||
@@ -1,6 +1,5 @@ | |||
1 | //! Provides a way to attach fixes to the diagnostics. | 1 | //! Provides a way to attach fixes to the diagnostics. |
2 | //! The same module also has all curret custom fixes for the diagnostics implemented. | 2 | //! The same module also has all curret custom fixes for the diagnostics implemented. |
3 | use base_db::FileId; | ||
4 | use hir::{ | 3 | use hir::{ |
5 | db::AstDatabase, | 4 | db::AstDatabase, |
6 | diagnostics::{ | 5 | diagnostics::{ |
@@ -9,6 +8,7 @@ use hir::{ | |||
9 | }, | 8 | }, |
10 | HasSource, HirDisplay, Semantics, VariantDef, | 9 | HasSource, HirDisplay, Semantics, VariantDef, |
11 | }; | 10 | }; |
11 | use ide_db::base_db::FileId; | ||
12 | use ide_db::{ | 12 | use ide_db::{ |
13 | source_change::{FileSystemEdit, SourceFileEdit}, | 13 | source_change::{FileSystemEdit, SourceFileEdit}, |
14 | RootDatabase, | 14 | RootDatabase, |