diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-09 08:52:09 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-09 08:52:09 +0000 |
commit | 3e8351fb0607f8711749b00d80f68bf25de01a76 (patch) | |
tree | 97388dafe71ececcbaf97249021b9c8d49786ccf /crates/ra_assists/src/assist_ctx.rs | |
parent | 12e3b4c70b5ef23b2fdfc197296d483680e125f9 (diff) | |
parent | 4fdeb54bb5c7ba0704839a65996766d223c51fc1 (diff) |
Merge #768
768: Sort assists by the range of the affected element r=matklad a=robojumper
Closes #763.
https://github.com/rust-analyzer/rust-analyzer/blob/3be98f2ac93b278828e76eb813bdd8033f647b12/crates/ra_assists/src/lib.rs#L233-L236
This could be made more robust by a) adding a way to identify actions by things other than their label and b) allowing arbitrary actions to appear in the list as long as the tested actions are there in the correct order. Let me know if I should do any of that.
Co-authored-by: robojumper <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/assist_ctx.rs')
-rw-r--r-- | crates/ra_assists/src/assist_ctx.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 0bf640241..41c8ac2f6 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs | |||
@@ -16,7 +16,7 @@ pub(crate) enum Assist { | |||
16 | 16 | ||
17 | /// `AssistCtx` allows to apply an assist or check if it could be applied. | 17 | /// `AssistCtx` allows to apply an assist or check if it could be applied. |
18 | /// | 18 | /// |
19 | /// Assists use a somewhat overengineered approach, given the current needs. The | 19 | /// Assists use a somewhat over-engineered approach, given the current needs. The |
20 | /// assists workflow consists of two phases. In the first phase, a user asks for | 20 | /// assists workflow consists of two phases. In the first phase, a user asks for |
21 | /// the list of available assists. In the second phase, the user picks a | 21 | /// the list of available assists. In the second phase, the user picks a |
22 | /// particular assist and it gets applied. | 22 | /// particular assist and it gets applied. |
@@ -106,6 +106,7 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> { | |||
106 | pub(crate) struct AssistBuilder { | 106 | pub(crate) struct AssistBuilder { |
107 | edit: TextEditBuilder, | 107 | edit: TextEditBuilder, |
108 | cursor_position: Option<TextUnit>, | 108 | cursor_position: Option<TextUnit>, |
109 | target: Option<TextRange>, | ||
109 | } | 110 | } |
110 | 111 | ||
111 | impl AssistBuilder { | 112 | impl AssistBuilder { |
@@ -138,7 +139,15 @@ impl AssistBuilder { | |||
138 | self.cursor_position = Some(offset) | 139 | self.cursor_position = Some(offset) |
139 | } | 140 | } |
140 | 141 | ||
142 | pub(crate) fn target(&mut self, target: TextRange) { | ||
143 | self.target = Some(target) | ||
144 | } | ||
145 | |||
141 | fn build(self) -> AssistAction { | 146 | fn build(self) -> AssistAction { |
142 | AssistAction { edit: self.edit.finish(), cursor_position: self.cursor_position } | 147 | AssistAction { |
148 | edit: self.edit.finish(), | ||
149 | cursor_position: self.cursor_position, | ||
150 | target: self.target, | ||
151 | } | ||
143 | } | 152 | } |
144 | } | 153 | } |