aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/diagnostics/fixes/fill_missing_fields.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-18 03:02:34 +0100
committerGitHub <[email protected]>2021-05-18 03:02:34 +0100
commite3d0d89d7e3e253234271008df9324ec1faf1746 (patch)
tree13c4972204ac32dd1a1702c254ffef4b85a76bf3 /crates/ide/src/diagnostics/fixes/fill_missing_fields.rs
parentc04eaa1f37f31d7125372ba14da3d5059297e8b2 (diff)
parente0b01f34bb994ca8959f3040dbacafc6c56e4778 (diff)
Merge #8345
8345: Add pub mod option for UnlinkedFile r=rainy-me a=rainy-me close #8228 This is a draft that changes `Diagnostic` to contain multiple fixes. Pre analysis is in https://github.com/rust-analyzer/rust-analyzer/issues/8228#issuecomment-812887085 Because this solution is straightforward so I decided to type it out for discussion. Currently the `check_fix` is not able to test the situation when multiple fixes available. <del>Also because `Insert 'mod x;'` and `Insert 'pub mod x;'` are so similar, I don't know how to test them correctly and want some suggestions.</del>. I added `check_fixes` to allow checking mutiple possible fixes. In additional, instead of append after possible existing `mod y`, I think it's possible to Insert `pub mod x;` after `pub mod y`. Should I implement this too? Co-authored-by: rainy-me <[email protected]>
Diffstat (limited to 'crates/ide/src/diagnostics/fixes/fill_missing_fields.rs')
-rw-r--r--crates/ide/src/diagnostics/fixes/fill_missing_fields.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/crates/ide/src/diagnostics/fixes/fill_missing_fields.rs b/crates/ide/src/diagnostics/fixes/fill_missing_fields.rs
index 37a0e37a9..b5dd64c08 100644
--- a/crates/ide/src/diagnostics/fixes/fill_missing_fields.rs
+++ b/crates/ide/src/diagnostics/fixes/fill_missing_fields.rs
@@ -5,16 +5,16 @@ use syntax::{algo, ast::make, AstNode};
5use text_edit::TextEdit; 5use text_edit::TextEdit;
6 6
7use crate::{ 7use crate::{
8 diagnostics::{fix, fixes::DiagnosticWithFix}, 8 diagnostics::{fix, fixes::DiagnosticWithFixes},
9 Assist, 9 Assist,
10}; 10};
11 11
12impl DiagnosticWithFix for MissingFields { 12impl DiagnosticWithFixes for MissingFields {
13 fn fix( 13 fn fixes(
14 &self, 14 &self,
15 sema: &Semantics<RootDatabase>, 15 sema: &Semantics<RootDatabase>,
16 _resolve: &AssistResolveStrategy, 16 _resolve: &AssistResolveStrategy,
17 ) -> Option<Assist> { 17 ) -> Option<Vec<Assist>> {
18 // Note that although we could add a diagnostics to 18 // Note that although we could add a diagnostics to
19 // fill the missing tuple field, e.g : 19 // fill the missing tuple field, e.g :
20 // `struct A(usize);` 20 // `struct A(usize);`
@@ -41,12 +41,12 @@ impl DiagnosticWithFix for MissingFields {
41 .into_text_edit(&mut builder); 41 .into_text_edit(&mut builder);
42 builder.finish() 42 builder.finish()
43 }; 43 };
44 Some(fix( 44 Some(vec![fix(
45 "fill_missing_fields", 45 "fill_missing_fields",
46 "Fill struct fields", 46 "Fill struct fields",
47 SourceChange::from_text_edit(self.file.original_file(sema.db), edit), 47 SourceChange::from_text_edit(self.file.original_file(sema.db), edit),
48 sema.original_range(&field_list_parent.syntax()).range, 48 sema.original_range(&field_list_parent.syntax()).range,
49 )) 49 )])
50 } 50 }
51} 51}
52 52