diff options
Diffstat (limited to 'crates/ide/src/diagnostics/fixes')
7 files changed, 70 insertions, 69 deletions
diff --git a/crates/ide/src/diagnostics/fixes/change_case.rs b/crates/ide/src/diagnostics/fixes/change_case.rs index 80aca58a1..42be3375f 100644 --- a/crates/ide/src/diagnostics/fixes/change_case.rs +++ b/crates/ide/src/diagnostics/fixes/change_case.rs | |||
@@ -4,16 +4,16 @@ use ide_db::{base_db::FilePosition, RootDatabase}; | |||
4 | use syntax::AstNode; | 4 | use syntax::AstNode; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | diagnostics::{unresolved_fix, DiagnosticWithFix}, | 7 | diagnostics::{unresolved_fix, DiagnosticWithFixes}, |
8 | references::rename::rename_with_semantics, | 8 | references::rename::rename_with_semantics, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | impl DiagnosticWithFix for IncorrectCase { | 11 | impl DiagnosticWithFixes for IncorrectCase { |
12 | fn fix( | 12 | fn fixes( |
13 | &self, | 13 | &self, |
14 | sema: &Semantics<RootDatabase>, | 14 | sema: &Semantics<RootDatabase>, |
15 | resolve: &AssistResolveStrategy, | 15 | resolve: &AssistResolveStrategy, |
16 | ) -> Option<Assist> { | 16 | ) -> Option<Vec<Assist>> { |
17 | let root = sema.db.parse_or_expand(self.file)?; | 17 | let root = sema.db.parse_or_expand(self.file)?; |
18 | let name_node = self.ident.to_node(&root); | 18 | let name_node = self.ident.to_node(&root); |
19 | 19 | ||
@@ -28,7 +28,7 @@ impl DiagnosticWithFix for IncorrectCase { | |||
28 | res.source_change = Some(source_change.ok().unwrap_or_default()); | 28 | res.source_change = Some(source_change.ok().unwrap_or_default()); |
29 | } | 29 | } |
30 | 30 | ||
31 | Some(res) | 31 | Some(vec![res]) |
32 | } | 32 | } |
33 | } | 33 | } |
34 | 34 | ||
diff --git a/crates/ide/src/diagnostics/fixes/create_field.rs b/crates/ide/src/diagnostics/fixes/create_field.rs index 24e0fda52..a5f457dce 100644 --- a/crates/ide/src/diagnostics/fixes/create_field.rs +++ b/crates/ide/src/diagnostics/fixes/create_field.rs | |||
@@ -7,18 +7,17 @@ use syntax::{ | |||
7 | use text_edit::TextEdit; | 7 | use text_edit::TextEdit; |
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | diagnostics::{fix, DiagnosticWithFix}, | 10 | diagnostics::{fix, DiagnosticWithFixes}, |
11 | Assist, AssistResolveStrategy, | 11 | Assist, AssistResolveStrategy, |
12 | }; | 12 | }; |
13 | 13 | impl DiagnosticWithFixes for NoSuchField { | |
14 | impl DiagnosticWithFix for NoSuchField { | 14 | fn fixes( |
15 | fn fix( | ||
16 | &self, | 15 | &self, |
17 | sema: &Semantics<RootDatabase>, | 16 | sema: &Semantics<RootDatabase>, |
18 | _resolve: &AssistResolveStrategy, | 17 | _resolve: &AssistResolveStrategy, |
19 | ) -> Option<Assist> { | 18 | ) -> Option<Vec<Assist>> { |
20 | let root = sema.db.parse_or_expand(self.file)?; | 19 | let root = sema.db.parse_or_expand(self.file)?; |
21 | missing_record_expr_field_fix( | 20 | missing_record_expr_field_fixes( |
22 | &sema, | 21 | &sema, |
23 | self.file.original_file(sema.db), | 22 | self.file.original_file(sema.db), |
24 | &self.field.to_node(&root), | 23 | &self.field.to_node(&root), |
@@ -26,11 +25,11 @@ impl DiagnosticWithFix for NoSuchField { | |||
26 | } | 25 | } |
27 | } | 26 | } |
28 | 27 | ||
29 | fn missing_record_expr_field_fix( | 28 | fn missing_record_expr_field_fixes( |
30 | sema: &Semantics<RootDatabase>, | 29 | sema: &Semantics<RootDatabase>, |
31 | usage_file_id: FileId, | 30 | usage_file_id: FileId, |
32 | record_expr_field: &ast::RecordExprField, | 31 | record_expr_field: &ast::RecordExprField, |
33 | ) -> Option<Assist> { | 32 | ) -> Option<Vec<Assist>> { |
34 | let record_lit = ast::RecordExpr::cast(record_expr_field.syntax().parent()?.parent()?)?; | 33 | let record_lit = ast::RecordExpr::cast(record_expr_field.syntax().parent()?.parent()?)?; |
35 | let def_id = sema.resolve_variant(record_lit)?; | 34 | let def_id = sema.resolve_variant(record_lit)?; |
36 | let module; | 35 | let module; |
@@ -89,12 +88,12 @@ fn missing_record_expr_field_fix( | |||
89 | TextEdit::insert(last_field_syntax.text_range().end(), new_field), | 88 | TextEdit::insert(last_field_syntax.text_range().end(), new_field), |
90 | ); | 89 | ); |
91 | 90 | ||
92 | return Some(fix( | 91 | return Some(vec![fix( |
93 | "create_field", | 92 | "create_field", |
94 | "Create field", | 93 | "Create field", |
95 | source_change, | 94 | source_change, |
96 | record_expr_field.syntax().text_range(), | 95 | record_expr_field.syntax().text_range(), |
97 | )); | 96 | )]); |
98 | 97 | ||
99 | fn record_field_list(field_def_list: ast::FieldList) -> Option<ast::RecordFieldList> { | 98 | fn record_field_list(field_def_list: ast::FieldList) -> Option<ast::RecordFieldList> { |
100 | match field_def_list { | 99 | match field_def_list { |
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}; | |||
5 | use text_edit::TextEdit; | 5 | use text_edit::TextEdit; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | diagnostics::{fix, fixes::DiagnosticWithFix}, | 8 | diagnostics::{fix, fixes::DiagnosticWithFixes}, |
9 | Assist, | 9 | Assist, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | impl DiagnosticWithFix for MissingFields { | 12 | impl 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 | ||
diff --git a/crates/ide/src/diagnostics/fixes/remove_semicolon.rs b/crates/ide/src/diagnostics/fixes/remove_semicolon.rs index 45471da41..f1724d479 100644 --- a/crates/ide/src/diagnostics/fixes/remove_semicolon.rs +++ b/crates/ide/src/diagnostics/fixes/remove_semicolon.rs | |||
@@ -4,14 +4,14 @@ use ide_db::{source_change::SourceChange, RootDatabase}; | |||
4 | use syntax::{ast, AstNode}; | 4 | use syntax::{ast, AstNode}; |
5 | use text_edit::TextEdit; | 5 | use text_edit::TextEdit; |
6 | 6 | ||
7 | use crate::diagnostics::{fix, DiagnosticWithFix}; | 7 | use crate::diagnostics::{fix, DiagnosticWithFixes}; |
8 | 8 | ||
9 | impl DiagnosticWithFix for RemoveThisSemicolon { | 9 | impl DiagnosticWithFixes for RemoveThisSemicolon { |
10 | fn fix( | 10 | fn fixes( |
11 | &self, | 11 | &self, |
12 | sema: &Semantics<RootDatabase>, | 12 | sema: &Semantics<RootDatabase>, |
13 | _resolve: &AssistResolveStrategy, | 13 | _resolve: &AssistResolveStrategy, |
14 | ) -> Option<Assist> { | 14 | ) -> Option<Vec<Assist>> { |
15 | let root = sema.db.parse_or_expand(self.file)?; | 15 | let root = sema.db.parse_or_expand(self.file)?; |
16 | 16 | ||
17 | let semicolon = self | 17 | let semicolon = self |
@@ -26,7 +26,7 @@ impl DiagnosticWithFix for RemoveThisSemicolon { | |||
26 | let edit = TextEdit::delete(semicolon); | 26 | let edit = TextEdit::delete(semicolon); |
27 | let source_change = SourceChange::from_text_edit(self.file.original_file(sema.db), edit); | 27 | let source_change = SourceChange::from_text_edit(self.file.original_file(sema.db), edit); |
28 | 28 | ||
29 | Some(fix("remove_semicolon", "Remove this semicolon", source_change, semicolon)) | 29 | Some(vec![fix("remove_semicolon", "Remove this semicolon", source_change, semicolon)]) |
30 | } | 30 | } |
31 | } | 31 | } |
32 | 32 | ||
diff --git a/crates/ide/src/diagnostics/fixes/replace_with_find_map.rs b/crates/ide/src/diagnostics/fixes/replace_with_find_map.rs index b0ef7b44a..444bf563b 100644 --- a/crates/ide/src/diagnostics/fixes/replace_with_find_map.rs +++ b/crates/ide/src/diagnostics/fixes/replace_with_find_map.rs | |||
@@ -7,14 +7,14 @@ use syntax::{ | |||
7 | }; | 7 | }; |
8 | use text_edit::TextEdit; | 8 | use text_edit::TextEdit; |
9 | 9 | ||
10 | use crate::diagnostics::{fix, DiagnosticWithFix}; | 10 | use crate::diagnostics::{fix, DiagnosticWithFixes}; |
11 | 11 | ||
12 | impl DiagnosticWithFix for ReplaceFilterMapNextWithFindMap { | 12 | impl DiagnosticWithFixes for ReplaceFilterMapNextWithFindMap { |
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 | let root = sema.db.parse_or_expand(self.file)?; | 18 | let root = sema.db.parse_or_expand(self.file)?; |
19 | let next_expr = self.next_expr.to_node(&root); | 19 | let next_expr = self.next_expr.to_node(&root); |
20 | let next_call = ast::MethodCallExpr::cast(next_expr.syntax().clone())?; | 20 | let next_call = ast::MethodCallExpr::cast(next_expr.syntax().clone())?; |
@@ -32,12 +32,12 @@ impl DiagnosticWithFix for ReplaceFilterMapNextWithFindMap { | |||
32 | 32 | ||
33 | let source_change = SourceChange::from_text_edit(self.file.original_file(sema.db), edit); | 33 | let source_change = SourceChange::from_text_edit(self.file.original_file(sema.db), edit); |
34 | 34 | ||
35 | Some(fix( | 35 | Some(vec![fix( |
36 | "replace_with_find_map", | 36 | "replace_with_find_map", |
37 | "Replace filter_map(..).next() with find_map()", | 37 | "Replace filter_map(..).next() with find_map()", |
38 | source_change, | 38 | source_change, |
39 | trigger_range, | 39 | trigger_range, |
40 | )) | 40 | )]) |
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
diff --git a/crates/ide/src/diagnostics/fixes/unresolved_module.rs b/crates/ide/src/diagnostics/fixes/unresolved_module.rs index 81244b293..b3d0283bb 100644 --- a/crates/ide/src/diagnostics/fixes/unresolved_module.rs +++ b/crates/ide/src/diagnostics/fixes/unresolved_module.rs | |||
@@ -3,17 +3,17 @@ use ide_assists::{Assist, AssistResolveStrategy}; | |||
3 | use ide_db::{base_db::AnchoredPathBuf, source_change::FileSystemEdit, RootDatabase}; | 3 | use ide_db::{base_db::AnchoredPathBuf, source_change::FileSystemEdit, RootDatabase}; |
4 | use syntax::AstNode; | 4 | use syntax::AstNode; |
5 | 5 | ||
6 | use crate::diagnostics::{fix, DiagnosticWithFix}; | 6 | use crate::diagnostics::{fix, DiagnosticWithFixes}; |
7 | 7 | ||
8 | impl DiagnosticWithFix for UnresolvedModule { | 8 | impl DiagnosticWithFixes for UnresolvedModule { |
9 | fn fix( | 9 | fn fixes( |
10 | &self, | 10 | &self, |
11 | sema: &Semantics<RootDatabase>, | 11 | sema: &Semantics<RootDatabase>, |
12 | _resolve: &AssistResolveStrategy, | 12 | _resolve: &AssistResolveStrategy, |
13 | ) -> Option<Assist> { | 13 | ) -> Option<Vec<Assist>> { |
14 | let root = sema.db.parse_or_expand(self.file)?; | 14 | let root = sema.db.parse_or_expand(self.file)?; |
15 | let unresolved_module = self.decl.to_node(&root); | 15 | let unresolved_module = self.decl.to_node(&root); |
16 | Some(fix( | 16 | Some(vec![fix( |
17 | "create_module", | 17 | "create_module", |
18 | "Create module", | 18 | "Create module", |
19 | FileSystemEdit::CreateFile { | 19 | FileSystemEdit::CreateFile { |
@@ -25,7 +25,7 @@ impl DiagnosticWithFix for UnresolvedModule { | |||
25 | } | 25 | } |
26 | .into(), | 26 | .into(), |
27 | unresolved_module.syntax().text_range(), | 27 | unresolved_module.syntax().text_range(), |
28 | )) | 28 | )]) |
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 | ||
@@ -45,33 +45,35 @@ mod tests { | |||
45 | message: "unresolved module", | 45 | message: "unresolved module", |
46 | range: 0..8, | 46 | range: 0..8, |
47 | severity: Error, | 47 | severity: Error, |
48 | fix: Some( | 48 | fixes: Some( |
49 | Assist { | 49 | [ |
50 | id: AssistId( | 50 | Assist { |
51 | "create_module", | 51 | id: AssistId( |
52 | QuickFix, | 52 | "create_module", |
53 | ), | 53 | QuickFix, |
54 | label: "Create module", | 54 | ), |
55 | group: None, | 55 | label: "Create module", |
56 | target: 0..8, | 56 | group: None, |
57 | source_change: Some( | 57 | target: 0..8, |
58 | SourceChange { | 58 | source_change: Some( |
59 | source_file_edits: {}, | 59 | SourceChange { |
60 | file_system_edits: [ | 60 | source_file_edits: {}, |
61 | CreateFile { | 61 | file_system_edits: [ |
62 | dst: AnchoredPathBuf { | 62 | CreateFile { |
63 | anchor: FileId( | 63 | dst: AnchoredPathBuf { |
64 | 0, | 64 | anchor: FileId( |
65 | ), | 65 | 0, |
66 | path: "foo.rs", | 66 | ), |
67 | path: "foo.rs", | ||
68 | }, | ||
69 | initial_contents: "", | ||
67 | }, | 70 | }, |
68 | initial_contents: "", | 71 | ], |
69 | }, | 72 | is_snippet: false, |
70 | ], | 73 | }, |
71 | is_snippet: false, | 74 | ), |
72 | }, | 75 | }, |
73 | ), | 76 | ], |
74 | }, | ||
75 | ), | 77 | ), |
76 | unused: false, | 78 | unused: false, |
77 | code: Some( | 79 | code: Some( |
diff --git a/crates/ide/src/diagnostics/fixes/wrap_tail_expr.rs b/crates/ide/src/diagnostics/fixes/wrap_tail_expr.rs index 66676064a..715a403b9 100644 --- a/crates/ide/src/diagnostics/fixes/wrap_tail_expr.rs +++ b/crates/ide/src/diagnostics/fixes/wrap_tail_expr.rs | |||
@@ -4,14 +4,14 @@ use ide_db::{source_change::SourceChange, RootDatabase}; | |||
4 | use syntax::AstNode; | 4 | use syntax::AstNode; |
5 | use text_edit::TextEdit; | 5 | use text_edit::TextEdit; |
6 | 6 | ||
7 | use crate::diagnostics::{fix, DiagnosticWithFix}; | 7 | use crate::diagnostics::{fix, DiagnosticWithFixes}; |
8 | 8 | ||
9 | impl DiagnosticWithFix for MissingOkOrSomeInTailExpr { | 9 | impl DiagnosticWithFixes for MissingOkOrSomeInTailExpr { |
10 | fn fix( | 10 | fn fixes( |
11 | &self, | 11 | &self, |
12 | sema: &Semantics<RootDatabase>, | 12 | sema: &Semantics<RootDatabase>, |
13 | _resolve: &AssistResolveStrategy, | 13 | _resolve: &AssistResolveStrategy, |
14 | ) -> Option<Assist> { | 14 | ) -> Option<Vec<Assist>> { |
15 | let root = sema.db.parse_or_expand(self.file)?; | 15 | let root = sema.db.parse_or_expand(self.file)?; |
16 | let tail_expr = self.expr.to_node(&root); | 16 | let tail_expr = self.expr.to_node(&root); |
17 | let tail_expr_range = tail_expr.syntax().text_range(); | 17 | let tail_expr_range = tail_expr.syntax().text_range(); |
@@ -19,7 +19,7 @@ impl DiagnosticWithFix for MissingOkOrSomeInTailExpr { | |||
19 | let edit = TextEdit::replace(tail_expr_range, replacement); | 19 | let edit = TextEdit::replace(tail_expr_range, replacement); |
20 | let source_change = SourceChange::from_text_edit(self.file.original_file(sema.db), edit); | 20 | let source_change = SourceChange::from_text_edit(self.file.original_file(sema.db), edit); |
21 | let name = if self.required == "Ok" { "Wrap with Ok" } else { "Wrap with Some" }; | 21 | let name = if self.required == "Ok" { "Wrap with Ok" } else { "Wrap with Some" }; |
22 | Some(fix("wrap_tail_expr", name, source_change, tail_expr_range)) | 22 | Some(vec![fix("wrap_tail_expr", name, source_change, tail_expr_range)]) |
23 | } | 23 | } |
24 | } | 24 | } |
25 | 25 | ||