diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_assists/src/assist_ctx.rs | 14 | ||||
-rw-r--r-- | crates/ra_assists/src/lib.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide/src/assists.rs | 19 | ||||
-rw-r--r-- | crates/ra_ide/src/diagnostics.rs | 12 | ||||
-rw-r--r-- | crates/ra_ide/src/references/rename.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide/src/source_change.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/typing/on_enter.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/main.rs | 16 |
8 files changed, 42 insertions, 45 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index da2880037..82f61bc8f 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs | |||
@@ -38,8 +38,7 @@ impl AssistInfo { | |||
38 | 38 | ||
39 | pub(crate) fn into_resolved(self) -> Option<ResolvedAssist> { | 39 | pub(crate) fn into_resolved(self) -> Option<ResolvedAssist> { |
40 | let label = self.label; | 40 | let label = self.label; |
41 | let group_label = self.group_label; | 41 | self.action.map(|action| ResolvedAssist { label, action }) |
42 | self.action.map(|action| ResolvedAssist { label, group_label, action }) | ||
43 | } | 42 | } |
44 | } | 43 | } |
45 | 44 | ||
@@ -100,7 +99,7 @@ impl<'a> AssistCtx<'a> { | |||
100 | label: impl Into<String>, | 99 | label: impl Into<String>, |
101 | f: impl FnOnce(&mut ActionBuilder), | 100 | f: impl FnOnce(&mut ActionBuilder), |
102 | ) -> Option<Assist> { | 101 | ) -> Option<Assist> { |
103 | let label = AssistLabel::new(label.into(), id); | 102 | let label = AssistLabel::new(id, label.into(), None); |
104 | 103 | ||
105 | let mut info = AssistInfo::new(label); | 104 | let mut info = AssistInfo::new(label); |
106 | if self.should_compute_edit { | 105 | if self.should_compute_edit { |
@@ -116,7 +115,8 @@ impl<'a> AssistCtx<'a> { | |||
116 | } | 115 | } |
117 | 116 | ||
118 | pub(crate) fn add_assist_group(self, group_name: impl Into<String>) -> AssistGroup<'a> { | 117 | pub(crate) fn add_assist_group(self, group_name: impl Into<String>) -> AssistGroup<'a> { |
119 | AssistGroup { ctx: self, group_name: group_name.into(), assists: Vec::new() } | 118 | let group = GroupLabel(group_name.into()); |
119 | AssistGroup { ctx: self, group, assists: Vec::new() } | ||
120 | } | 120 | } |
121 | 121 | ||
122 | pub(crate) fn token_at_offset(&self) -> TokenAtOffset<SyntaxToken> { | 122 | pub(crate) fn token_at_offset(&self) -> TokenAtOffset<SyntaxToken> { |
@@ -146,7 +146,7 @@ impl<'a> AssistCtx<'a> { | |||
146 | 146 | ||
147 | pub(crate) struct AssistGroup<'a> { | 147 | pub(crate) struct AssistGroup<'a> { |
148 | ctx: AssistCtx<'a>, | 148 | ctx: AssistCtx<'a>, |
149 | group_name: String, | 149 | group: GroupLabel, |
150 | assists: Vec<AssistInfo>, | 150 | assists: Vec<AssistInfo>, |
151 | } | 151 | } |
152 | 152 | ||
@@ -157,9 +157,9 @@ impl<'a> AssistGroup<'a> { | |||
157 | label: impl Into<String>, | 157 | label: impl Into<String>, |
158 | f: impl FnOnce(&mut ActionBuilder), | 158 | f: impl FnOnce(&mut ActionBuilder), |
159 | ) { | 159 | ) { |
160 | let label = AssistLabel::new(label.into(), id); | 160 | let label = AssistLabel::new(id, label.into(), Some(self.group.clone())); |
161 | 161 | ||
162 | let mut info = AssistInfo::new(label).with_group(GroupLabel(self.group_name.clone())); | 162 | let mut info = AssistInfo::new(label).with_group(self.group.clone()); |
163 | if self.ctx.should_compute_edit { | 163 | if self.ctx.should_compute_edit { |
164 | let action = { | 164 | let action = { |
165 | let mut edit = ActionBuilder::new(&self.ctx); | 165 | let mut edit = ActionBuilder::new(&self.ctx); |
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index c5df86600..5cec10088 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs | |||
@@ -17,13 +17,13 @@ mod doc_tests; | |||
17 | pub mod utils; | 17 | pub mod utils; |
18 | pub mod ast_transform; | 18 | pub mod ast_transform; |
19 | 19 | ||
20 | use hir::Semantics; | ||
20 | use ra_db::{FileId, FileRange}; | 21 | use ra_db::{FileId, FileRange}; |
21 | use ra_ide_db::RootDatabase; | 22 | use ra_ide_db::RootDatabase; |
22 | use ra_syntax::{TextRange, TextSize}; | 23 | use ra_syntax::{TextRange, TextSize}; |
23 | use ra_text_edit::TextEdit; | 24 | use ra_text_edit::TextEdit; |
24 | 25 | ||
25 | pub(crate) use crate::assist_ctx::{Assist, AssistCtx, AssistHandler}; | 26 | pub(crate) use crate::assist_ctx::{Assist, AssistCtx, AssistHandler}; |
26 | use hir::Semantics; | ||
27 | 27 | ||
28 | /// Unique identifier of the assist, should not be shown to the user | 28 | /// Unique identifier of the assist, should not be shown to the user |
29 | /// directly. | 29 | /// directly. |
@@ -32,19 +32,20 @@ pub struct AssistId(pub &'static str); | |||
32 | 32 | ||
33 | #[derive(Debug, Clone)] | 33 | #[derive(Debug, Clone)] |
34 | pub struct AssistLabel { | 34 | pub struct AssistLabel { |
35 | pub id: AssistId, | ||
35 | /// Short description of the assist, as shown in the UI. | 36 | /// Short description of the assist, as shown in the UI. |
36 | pub label: String, | 37 | pub label: String, |
37 | pub id: AssistId, | 38 | pub group: Option<GroupLabel>, |
38 | } | 39 | } |
39 | 40 | ||
40 | #[derive(Clone, Debug)] | 41 | #[derive(Clone, Debug)] |
41 | pub struct GroupLabel(pub String); | 42 | pub struct GroupLabel(pub String); |
42 | 43 | ||
43 | impl AssistLabel { | 44 | impl AssistLabel { |
44 | pub(crate) fn new(label: String, id: AssistId) -> AssistLabel { | 45 | pub(crate) fn new(id: AssistId, label: String, group: Option<GroupLabel>) -> AssistLabel { |
45 | // FIXME: make fields private, so that this invariant can't be broken | 46 | // FIXME: make fields private, so that this invariant can't be broken |
46 | assert!(label.starts_with(|c: char| c.is_uppercase())); | 47 | assert!(label.starts_with(|c: char| c.is_uppercase())); |
47 | AssistLabel { label, id } | 48 | AssistLabel { id, label, group } |
48 | } | 49 | } |
49 | } | 50 | } |
50 | 51 | ||
@@ -60,7 +61,6 @@ pub struct AssistAction { | |||
60 | #[derive(Debug, Clone)] | 61 | #[derive(Debug, Clone)] |
61 | pub struct ResolvedAssist { | 62 | pub struct ResolvedAssist { |
62 | pub label: AssistLabel, | 63 | pub label: AssistLabel, |
63 | pub group_label: Option<GroupLabel>, | ||
64 | pub action: AssistAction, | 64 | pub action: AssistAction, |
65 | } | 65 | } |
66 | 66 | ||
diff --git a/crates/ra_ide/src/assists.rs b/crates/ra_ide/src/assists.rs index 2b5d11681..389339a03 100644 --- a/crates/ra_ide/src/assists.rs +++ b/crates/ra_ide/src/assists.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use ra_assists::{resolved_assists, AssistAction, AssistLabel}; | 3 | use ra_assists::{resolved_assists, AssistAction}; |
4 | use ra_db::{FilePosition, FileRange}; | 4 | use ra_db::{FilePosition, FileRange}; |
5 | use ra_ide_db::RootDatabase; | 5 | use ra_ide_db::RootDatabase; |
6 | 6 | ||
@@ -21,27 +21,22 @@ pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> { | |||
21 | .into_iter() | 21 | .into_iter() |
22 | .map(|assist| { | 22 | .map(|assist| { |
23 | let file_id = frange.file_id; | 23 | let file_id = frange.file_id; |
24 | let assist_label = &assist.label; | ||
25 | Assist { | 24 | Assist { |
26 | id: assist_label.id, | 25 | id: assist.label.id, |
27 | label: assist_label.label.clone(), | 26 | label: assist.label.label.clone(), |
28 | group_label: assist.group_label.map(|it| it.0), | 27 | group_label: assist.label.group.map(|it| it.0), |
29 | source_change: action_to_edit(assist.action, file_id, assist_label), | 28 | source_change: action_to_edit(assist.action, file_id, assist.label.label.clone()), |
30 | } | 29 | } |
31 | }) | 30 | }) |
32 | .collect() | 31 | .collect() |
33 | } | 32 | } |
34 | 33 | ||
35 | fn action_to_edit( | 34 | fn action_to_edit(action: AssistAction, file_id: FileId, label: String) -> SourceChange { |
36 | action: AssistAction, | ||
37 | file_id: FileId, | ||
38 | assist_label: &AssistLabel, | ||
39 | ) -> SourceChange { | ||
40 | let file_id = match action.file { | 35 | let file_id = match action.file { |
41 | ra_assists::AssistFile::TargetFile(it) => it, | 36 | ra_assists::AssistFile::TargetFile(it) => it, |
42 | _ => file_id, | 37 | _ => file_id, |
43 | }; | 38 | }; |
44 | let file_edit = SourceFileEdit { file_id, edit: action.edit }; | 39 | let file_edit = SourceFileEdit { file_id, edit: action.edit }; |
45 | SourceChange::source_file_edit(assist_label.label.clone(), file_edit) | 40 | SourceChange::source_file_edit(label, file_edit) |
46 | .with_cursor_opt(action.cursor_position.map(|offset| FilePosition { offset, file_id })) | 41 | .with_cursor_opt(action.cursor_position.map(|offset| FilePosition { offset, file_id })) |
47 | } | 42 | } |
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index a6b4c2c28..4c04cee07 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs | |||
@@ -64,7 +64,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> | |||
64 | .unwrap_or_else(|| RelativePath::new("")) | 64 | .unwrap_or_else(|| RelativePath::new("")) |
65 | .join(&d.candidate); | 65 | .join(&d.candidate); |
66 | let create_file = FileSystemEdit::CreateFile { source_root, path }; | 66 | let create_file = FileSystemEdit::CreateFile { source_root, path }; |
67 | let fix = SourceChange::file_system_edit("create module", create_file); | 67 | let fix = SourceChange::file_system_edit("Create module", create_file); |
68 | res.borrow_mut().push(Diagnostic { | 68 | res.borrow_mut().push(Diagnostic { |
69 | range: sema.diagnostics_range(d).range, | 69 | range: sema.diagnostics_range(d).range, |
70 | message: d.message(), | 70 | message: d.message(), |
@@ -92,7 +92,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> | |||
92 | algo::diff(&d.ast(db).syntax(), &field_list.syntax()).into_text_edit(&mut builder); | 92 | algo::diff(&d.ast(db).syntax(), &field_list.syntax()).into_text_edit(&mut builder); |
93 | 93 | ||
94 | Some(SourceChange::source_file_edit_from( | 94 | Some(SourceChange::source_file_edit_from( |
95 | "fill struct fields", | 95 | "Fill struct fields", |
96 | file_id, | 96 | file_id, |
97 | builder.finish(), | 97 | builder.finish(), |
98 | )) | 98 | )) |
@@ -117,7 +117,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> | |||
117 | let node = d.ast(db); | 117 | let node = d.ast(db); |
118 | let replacement = format!("Ok({})", node.syntax()); | 118 | let replacement = format!("Ok({})", node.syntax()); |
119 | let edit = TextEdit::replace(node.syntax().text_range(), replacement); | 119 | let edit = TextEdit::replace(node.syntax().text_range(), replacement); |
120 | let fix = SourceChange::source_file_edit_from("wrap with ok", file_id, edit); | 120 | let fix = SourceChange::source_file_edit_from("Wrap with ok", file_id, edit); |
121 | res.borrow_mut().push(Diagnostic { | 121 | res.borrow_mut().push(Diagnostic { |
122 | range: sema.diagnostics_range(d).range, | 122 | range: sema.diagnostics_range(d).range, |
123 | message: d.message(), | 123 | message: d.message(), |
@@ -199,7 +199,7 @@ fn check_struct_shorthand_initialization( | |||
199 | message: "Shorthand struct initialization".to_string(), | 199 | message: "Shorthand struct initialization".to_string(), |
200 | severity: Severity::WeakWarning, | 200 | severity: Severity::WeakWarning, |
201 | fix: Some(SourceChange::source_file_edit( | 201 | fix: Some(SourceChange::source_file_edit( |
202 | "use struct shorthand initialization", | 202 | "Use struct shorthand initialization", |
203 | SourceFileEdit { file_id, edit }, | 203 | SourceFileEdit { file_id, edit }, |
204 | )), | 204 | )), |
205 | }); | 205 | }); |
@@ -606,7 +606,7 @@ mod tests { | |||
606 | range: 0..8, | 606 | range: 0..8, |
607 | fix: Some( | 607 | fix: Some( |
608 | SourceChange { | 608 | SourceChange { |
609 | label: "create module", | 609 | label: "Create module", |
610 | source_file_edits: [], | 610 | source_file_edits: [], |
611 | file_system_edits: [ | 611 | file_system_edits: [ |
612 | CreateFile { | 612 | CreateFile { |
@@ -655,7 +655,7 @@ mod tests { | |||
655 | range: 224..233, | 655 | range: 224..233, |
656 | fix: Some( | 656 | fix: Some( |
657 | SourceChange { | 657 | SourceChange { |
658 | label: "fill struct fields", | 658 | label: "Fill struct fields", |
659 | source_file_edits: [ | 659 | source_file_edits: [ |
660 | SourceFileEdit { | 660 | SourceFileEdit { |
661 | file_id: FileId( | 661 | file_id: FileId( |
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 916edaef2..52e55b0a0 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs | |||
@@ -122,7 +122,7 @@ fn rename_mod( | |||
122 | source_file_edits.extend(ref_edits); | 122 | source_file_edits.extend(ref_edits); |
123 | } | 123 | } |
124 | 124 | ||
125 | Some(SourceChange::from_edits("rename", source_file_edits, file_system_edits)) | 125 | Some(SourceChange::from_edits("Rename", source_file_edits, file_system_edits)) |
126 | } | 126 | } |
127 | 127 | ||
128 | fn rename_reference( | 128 | fn rename_reference( |
@@ -141,7 +141,7 @@ fn rename_reference( | |||
141 | return None; | 141 | return None; |
142 | } | 142 | } |
143 | 143 | ||
144 | Some(RangeInfo::new(range, SourceChange::source_file_edits("rename", edit))) | 144 | Some(RangeInfo::new(range, SourceChange::source_file_edits("Rename", edit))) |
145 | } | 145 | } |
146 | 146 | ||
147 | #[cfg(test)] | 147 | #[cfg(test)] |
@@ -530,7 +530,7 @@ mod tests { | |||
530 | RangeInfo { | 530 | RangeInfo { |
531 | range: 4..7, | 531 | range: 4..7, |
532 | info: SourceChange { | 532 | info: SourceChange { |
533 | label: "rename", | 533 | label: "Rename", |
534 | source_file_edits: [ | 534 | source_file_edits: [ |
535 | SourceFileEdit { | 535 | SourceFileEdit { |
536 | file_id: FileId( | 536 | file_id: FileId( |
@@ -582,7 +582,7 @@ mod tests { | |||
582 | RangeInfo { | 582 | RangeInfo { |
583 | range: 4..7, | 583 | range: 4..7, |
584 | info: SourceChange { | 584 | info: SourceChange { |
585 | label: "rename", | 585 | label: "Rename", |
586 | source_file_edits: [ | 586 | source_file_edits: [ |
587 | SourceFileEdit { | 587 | SourceFileEdit { |
588 | file_id: FileId( | 588 | file_id: FileId( |
@@ -665,7 +665,7 @@ mod tests { | |||
665 | RangeInfo { | 665 | RangeInfo { |
666 | range: 8..11, | 666 | range: 8..11, |
667 | info: SourceChange { | 667 | info: SourceChange { |
668 | label: "rename", | 668 | label: "Rename", |
669 | source_file_edits: [ | 669 | source_file_edits: [ |
670 | SourceFileEdit { | 670 | SourceFileEdit { |
671 | file_id: FileId( | 671 | file_id: FileId( |
diff --git a/crates/ra_ide/src/source_change.rs b/crates/ra_ide/src/source_change.rs index 71b0e8f75..10afd7825 100644 --- a/crates/ra_ide/src/source_change.rs +++ b/crates/ra_ide/src/source_change.rs | |||
@@ -35,8 +35,10 @@ impl SourceChange { | |||
35 | /// Creates a new SourceChange with the given label, | 35 | /// Creates a new SourceChange with the given label, |
36 | /// containing only the given `SourceFileEdits`. | 36 | /// containing only the given `SourceFileEdits`. |
37 | pub(crate) fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self { | 37 | pub(crate) fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self { |
38 | let label = label.into(); | ||
39 | assert!(label.starts_with(char::is_uppercase)); | ||
38 | SourceChange { | 40 | SourceChange { |
39 | label: label.into(), | 41 | label: label, |
40 | source_file_edits: edits, | 42 | source_file_edits: edits, |
41 | file_system_edits: vec![], | 43 | file_system_edits: vec![], |
42 | cursor_position: None, | 44 | cursor_position: None, |
diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs index 30c8c5572..725237464 100644 --- a/crates/ra_ide/src/typing/on_enter.rs +++ b/crates/ra_ide/src/typing/on_enter.rs | |||
@@ -44,7 +44,7 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour | |||
44 | 44 | ||
45 | Some( | 45 | Some( |
46 | SourceChange::source_file_edit( | 46 | SourceChange::source_file_edit( |
47 | "on enter", | 47 | "On enter", |
48 | SourceFileEdit { edit, file_id: position.file_id }, | 48 | SourceFileEdit { edit, file_id: position.file_id }, |
49 | ) | 49 | ) |
50 | .with_cursor(FilePosition { offset: cursor_position, file_id: position.file_id }), | 50 | .with_cursor(FilePosition { offset: cursor_position, file_id: position.file_id }), |
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs index a218da76d..1efa5dd63 100644 --- a/crates/rust-analyzer/tests/heavy_tests/main.rs +++ b/crates/rust-analyzer/tests/heavy_tests/main.rs | |||
@@ -337,7 +337,7 @@ fn main() {} | |||
337 | "arguments": [ | 337 | "arguments": [ |
338 | { | 338 | { |
339 | "cursorPosition": null, | 339 | "cursorPosition": null, |
340 | "label": "create module", | 340 | "label": "Create module", |
341 | "workspaceEdit": { | 341 | "workspaceEdit": { |
342 | "documentChanges": [ | 342 | "documentChanges": [ |
343 | { | 343 | { |
@@ -349,9 +349,9 @@ fn main() {} | |||
349 | } | 349 | } |
350 | ], | 350 | ], |
351 | "command": "rust-analyzer.applySourceChange", | 351 | "command": "rust-analyzer.applySourceChange", |
352 | "title": "create module" | 352 | "title": "Create module" |
353 | }, | 353 | }, |
354 | "title": "create module" | 354 | "title": "Create module" |
355 | } | 355 | } |
356 | ]), | 356 | ]), |
357 | ); | 357 | ); |
@@ -420,7 +420,7 @@ fn main() {{}} | |||
420 | "arguments": [ | 420 | "arguments": [ |
421 | { | 421 | { |
422 | "cursorPosition": null, | 422 | "cursorPosition": null, |
423 | "label": "create module", | 423 | "label": "Create module", |
424 | "workspaceEdit": { | 424 | "workspaceEdit": { |
425 | "documentChanges": [ | 425 | "documentChanges": [ |
426 | { | 426 | { |
@@ -432,9 +432,9 @@ fn main() {{}} | |||
432 | } | 432 | } |
433 | ], | 433 | ], |
434 | "command": "rust-analyzer.applySourceChange", | 434 | "command": "rust-analyzer.applySourceChange", |
435 | "title": "create module" | 435 | "title": "Create module" |
436 | }, | 436 | }, |
437 | "title": "create module" | 437 | "title": "Create module" |
438 | } | 438 | } |
439 | ]), | 439 | ]), |
440 | ); | 440 | ); |
@@ -500,7 +500,7 @@ fn main() {{}} | |||
500 | "position": { "character": 4, "line": 1 }, | 500 | "position": { "character": 4, "line": 1 }, |
501 | "textDocument": { "uri": "file:///[..]src/m0.rs" } | 501 | "textDocument": { "uri": "file:///[..]src/m0.rs" } |
502 | }, | 502 | }, |
503 | "label": "on enter", | 503 | "label": "On enter", |
504 | "workspaceEdit": { | 504 | "workspaceEdit": { |
505 | "documentChanges": [ | 505 | "documentChanges": [ |
506 | { | 506 | { |
@@ -552,7 +552,7 @@ version = \"0.0.0\" | |||
552 | "position": { "line": 1, "character": 4 }, | 552 | "position": { "line": 1, "character": 4 }, |
553 | "textDocument": { "uri": "file:///[..]src/main.rs" } | 553 | "textDocument": { "uri": "file:///[..]src/main.rs" } |
554 | }, | 554 | }, |
555 | "label": "on enter", | 555 | "label": "On enter", |
556 | "workspaceEdit": { | 556 | "workspaceEdit": { |
557 | "documentChanges": [ | 557 | "documentChanges": [ |
558 | { | 558 | { |