aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/lib.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-05-06 11:51:28 +0100
committerAleksey Kladov <[email protected]>2020-05-06 11:51:28 +0100
commit233f01c9ba555e5d06f336cb0ff64e7a83e4a23a (patch)
tree7922dca3f7c4133e2616257be537428337e479d6 /crates/ra_assists/src/lib.rs
parentede8906844e206f252810d58533538cf1fb326d4 (diff)
Move target to AssistLabel
Target is used for assists sorting, so we need it before we compute the action.
Diffstat (limited to 'crates/ra_assists/src/lib.rs')
-rw-r--r--crates/ra_assists/src/lib.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index b794b021d..f4f37614f 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -36,16 +36,24 @@ pub struct AssistLabel {
36 /// Short description of the assist, as shown in the UI. 36 /// Short description of the assist, as shown in the UI.
37 pub label: String, 37 pub label: String,
38 pub group: Option<GroupLabel>, 38 pub group: Option<GroupLabel>,
39 /// Target ranges are used to sort assists: the smaller the target range,
40 /// the more specific assist is, and so it should be sorted first.
41 pub target: TextRange,
39} 42}
40 43
41#[derive(Clone, Debug)] 44#[derive(Clone, Debug)]
42pub struct GroupLabel(pub String); 45pub struct GroupLabel(pub String);
43 46
44impl AssistLabel { 47impl AssistLabel {
45 pub(crate) fn new(id: AssistId, label: String, group: Option<GroupLabel>) -> AssistLabel { 48 pub(crate) fn new(
49 id: AssistId,
50 label: String,
51 group: Option<GroupLabel>,
52 target: TextRange,
53 ) -> AssistLabel {
46 // FIXME: make fields private, so that this invariant can't be broken 54 // FIXME: make fields private, so that this invariant can't be broken
47 assert!(label.starts_with(|c: char| c.is_uppercase())); 55 assert!(label.starts_with(|c: char| c.is_uppercase()));
48 AssistLabel { id, label, group } 56 AssistLabel { id, label, group, target }
49 } 57 }
50} 58}
51 59
@@ -53,8 +61,6 @@ impl AssistLabel {
53pub struct AssistAction { 61pub struct AssistAction {
54 pub edit: TextEdit, 62 pub edit: TextEdit,
55 pub cursor_position: Option<TextSize>, 63 pub cursor_position: Option<TextSize>,
56 // FIXME: This belongs to `AssistLabel`
57 pub target: Option<TextRange>,
58 pub file: AssistFile, 64 pub file: AssistFile,
59} 65}
60 66
@@ -104,7 +110,7 @@ pub fn resolved_assists(db: &RootDatabase, range: FileRange) -> Vec<ResolvedAssi
104 .flat_map(|it| it.0) 110 .flat_map(|it| it.0)
105 .map(|it| it.into_resolved().unwrap()) 111 .map(|it| it.into_resolved().unwrap())
106 .collect::<Vec<_>>(); 112 .collect::<Vec<_>>();
107 a.sort_by_key(|it| it.action.target.map_or(TextSize::from(!0u32), |it| it.len())); 113 a.sort_by_key(|it| it.label.target.len());
108 a 114 a
109} 115}
110 116