aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-25 14:45:52 +0000
committerAleksey Kladov <[email protected]>2020-03-25 14:45:52 +0000
commitb3665fccfb0a81752c35e56f6c41043133a949dd (patch)
tree150a039b5cd4102e21cadd5e6bc421539bbd38a7 /crates
parent785eb32f49653fbc5789396af4fa6ad61f89fb38 (diff)
Preserve relative ordering of grouped assists
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs44
1 files changed, 26 insertions, 18 deletions
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index 1cc2f6571..1033d6de9 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -734,19 +734,29 @@ pub fn handle_code_action(
734 res.push(fix.action.clone()); 734 res.push(fix.action.clone());
735 } 735 }
736 736
737 let mut grouped_assists: FxHashMap<String, Vec<Assist>> = FxHashMap::default(); 737 let mut grouped_assists: FxHashMap<String, (usize, Vec<Assist>)> = FxHashMap::default();
738 for assist in world.analysis().assists(FileRange { file_id, range })?.into_iter() { 738 for assist in world.analysis().assists(FileRange { file_id, range })?.into_iter() {
739 match &assist.group_label { 739 match &assist.group_label {
740 Some(label) => grouped_assists.entry(label.to_owned()).or_default().push(assist), 740 Some(label) => grouped_assists
741 None => res.push(create_single_code_action(assist, &world)?.into()), 741 .entry(label.to_owned())
742 .or_insert_with(|| {
743 let idx = res.len();
744 let dummy = Command::new(String::new(), String::new(), None);
745 res.push(dummy.into());
746 (idx, Vec::new())
747 })
748 .1
749 .push(assist),
750 None => {
751 res.push(create_single_code_action(assist, &world)?.into());
752 }
742 } 753 }
743 } 754 }
744 755
745 for (group_label, assists) in grouped_assists { 756 for (group_label, (idx, assists)) in grouped_assists {
746 if assists.len() == 1 { 757 if assists.len() == 1 {
747 res.push( 758 res[idx] =
748 create_single_code_action(assists.into_iter().next().unwrap(), &world)?.into(), 759 create_single_code_action(assists.into_iter().next().unwrap(), &world)?.into();
749 );
750 } else { 760 } else {
751 let title = group_label; 761 let title = group_label;
752 762
@@ -760,17 +770,15 @@ pub fn handle_code_action(
760 command: "rust-analyzer.selectAndApplySourceChange".to_string(), 770 command: "rust-analyzer.selectAndApplySourceChange".to_string(),
761 arguments: Some(vec![serde_json::Value::Array(arguments)]), 771 arguments: Some(vec![serde_json::Value::Array(arguments)]),
762 }); 772 });
763 res.push( 773 res[idx] = CodeAction {
764 CodeAction { 774 title,
765 title, 775 kind: None,
766 kind: None, 776 diagnostics: None,
767 diagnostics: None, 777 edit: None,
768 edit: None, 778 command,
769 command, 779 is_preferred: None,
770 is_preferred: None, 780 }
771 } 781 .into();
772 .into(),
773 );
774 } 782 }
775 } 783 }
776 784