From 233f01c9ba555e5d06f336cb0ff64e7a83e4a23a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 May 2020 12:51:28 +0200 Subject: Move target to AssistLabel Target is used for assists sorting, so we need it before we compute the action. --- crates/ra_assists/src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'crates/ra_assists/src/lib.rs') 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 { /// Short description of the assist, as shown in the UI. pub label: String, pub group: Option, + /// Target ranges are used to sort assists: the smaller the target range, + /// the more specific assist is, and so it should be sorted first. + pub target: TextRange, } #[derive(Clone, Debug)] pub struct GroupLabel(pub String); impl AssistLabel { - pub(crate) fn new(id: AssistId, label: String, group: Option) -> AssistLabel { + pub(crate) fn new( + id: AssistId, + label: String, + group: Option, + target: TextRange, + ) -> AssistLabel { // FIXME: make fields private, so that this invariant can't be broken assert!(label.starts_with(|c: char| c.is_uppercase())); - AssistLabel { id, label, group } + AssistLabel { id, label, group, target } } } @@ -53,8 +61,6 @@ impl AssistLabel { pub struct AssistAction { pub edit: TextEdit, pub cursor_position: Option, - // FIXME: This belongs to `AssistLabel` - pub target: Option, pub file: AssistFile, } @@ -104,7 +110,7 @@ pub fn resolved_assists(db: &RootDatabase, range: FileRange) -> Vec>(); - a.sort_by_key(|it| it.action.target.map_or(TextSize::from(!0u32), |it| it.len())); + a.sort_by_key(|it| it.label.target.len()); a } -- cgit v1.2.3