diff options
author | Aleksey Kladov <[email protected]> | 2020-05-20 23:03:42 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-05-20 23:03:42 +0100 |
commit | 70930d3bb2ba1d4a7a7d4a489da714096294acca (patch) | |
tree | 87375353a2ed211933ceb66e1ee7f7dc536067e9 /crates/ra_assists/src/assist_context.rs | |
parent | 4ac0abd2960acf1b3a357c681e64b3cddba6fc8e (diff) |
Remove set_cursor
Diffstat (limited to 'crates/ra_assists/src/assist_context.rs')
-rw-r--r-- | crates/ra_assists/src/assist_context.rs | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/crates/ra_assists/src/assist_context.rs b/crates/ra_assists/src/assist_context.rs index 005c17776..9f6ca449b 100644 --- a/crates/ra_assists/src/assist_context.rs +++ b/crates/ra_assists/src/assist_context.rs | |||
@@ -171,19 +171,13 @@ impl Assists { | |||
171 | 171 | ||
172 | pub(crate) struct AssistBuilder { | 172 | pub(crate) struct AssistBuilder { |
173 | edit: TextEditBuilder, | 173 | edit: TextEditBuilder, |
174 | cursor_position: Option<TextSize>, | ||
175 | file: FileId, | 174 | file: FileId, |
176 | is_snippet: bool, | 175 | is_snippet: bool, |
177 | } | 176 | } |
178 | 177 | ||
179 | impl AssistBuilder { | 178 | impl AssistBuilder { |
180 | pub(crate) fn new(file: FileId) -> AssistBuilder { | 179 | pub(crate) fn new(file: FileId) -> AssistBuilder { |
181 | AssistBuilder { | 180 | AssistBuilder { edit: TextEditBuilder::default(), file, is_snippet: false } |
182 | edit: TextEditBuilder::default(), | ||
183 | cursor_position: None, | ||
184 | file, | ||
185 | is_snippet: false, | ||
186 | } | ||
187 | } | 181 | } |
188 | 182 | ||
189 | /// Remove specified `range` of text. | 183 | /// Remove specified `range` of text. |
@@ -241,10 +235,6 @@ impl AssistBuilder { | |||
241 | algo::diff(&node, &new).into_text_edit(&mut self.edit) | 235 | algo::diff(&node, &new).into_text_edit(&mut self.edit) |
242 | } | 236 | } |
243 | 237 | ||
244 | /// Specify desired position of the cursor after the assist is applied. | ||
245 | pub(crate) fn set_cursor(&mut self, offset: TextSize) { | ||
246 | self.cursor_position = Some(offset) | ||
247 | } | ||
248 | // FIXME: better API | 238 | // FIXME: better API |
249 | pub(crate) fn set_file(&mut self, assist_file: FileId) { | 239 | pub(crate) fn set_file(&mut self, assist_file: FileId) { |
250 | self.file = assist_file; | 240 | self.file = assist_file; |
@@ -258,12 +248,8 @@ impl AssistBuilder { | |||
258 | 248 | ||
259 | fn finish(self, change_label: String) -> SourceChange { | 249 | fn finish(self, change_label: String) -> SourceChange { |
260 | let edit = self.edit.finish(); | 250 | let edit = self.edit.finish(); |
261 | if edit.is_empty() && self.cursor_position.is_none() { | 251 | let mut res = SingleFileChange { label: change_label, edit, cursor_position: None } |
262 | panic!("Only call `add_assist` if the assist can be applied") | 252 | .into_source_change(self.file); |
263 | } | ||
264 | let mut res = | ||
265 | SingleFileChange { label: change_label, edit, cursor_position: self.cursor_position } | ||
266 | .into_source_change(self.file); | ||
267 | if self.is_snippet { | 253 | if self.is_snippet { |
268 | res.is_snippet = true; | 254 | res.is_snippet = true; |
269 | } | 255 | } |