diff options
Diffstat (limited to 'crates/ra_assists/src/assist_ctx.rs')
-rw-r--r-- | crates/ra_assists/src/assist_ctx.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index c3e653299..2fe7c3de3 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs | |||
@@ -5,12 +5,12 @@ use ra_fmt::{leading_indent, reindent}; | |||
5 | use ra_ide_db::RootDatabase; | 5 | use ra_ide_db::RootDatabase; |
6 | use ra_syntax::{ | 6 | use ra_syntax::{ |
7 | algo::{self, find_covering_element, find_node_at_offset}, | 7 | algo::{self, find_covering_element, find_node_at_offset}, |
8 | AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextUnit, | 8 | AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize, |
9 | TokenAtOffset, | 9 | TokenAtOffset, |
10 | }; | 10 | }; |
11 | use ra_text_edit::TextEditBuilder; | 11 | use ra_text_edit::TextEditBuilder; |
12 | 12 | ||
13 | use crate::{AssistAction, AssistId, AssistLabel, GroupLabel, ResolvedAssist}; | 13 | use crate::{AssistAction, AssistFile, AssistId, AssistLabel, GroupLabel, ResolvedAssist}; |
14 | use algo::SyntaxRewriter; | 14 | use algo::SyntaxRewriter; |
15 | 15 | ||
16 | #[derive(Clone, Debug)] | 16 | #[derive(Clone, Debug)] |
@@ -178,8 +178,9 @@ impl<'a> AssistGroup<'a> { | |||
178 | #[derive(Default)] | 178 | #[derive(Default)] |
179 | pub(crate) struct ActionBuilder { | 179 | pub(crate) struct ActionBuilder { |
180 | edit: TextEditBuilder, | 180 | edit: TextEditBuilder, |
181 | cursor_position: Option<TextUnit>, | 181 | cursor_position: Option<TextSize>, |
182 | target: Option<TextRange>, | 182 | target: Option<TextRange>, |
183 | file: AssistFile, | ||
183 | } | 184 | } |
184 | 185 | ||
185 | impl ActionBuilder { | 186 | impl ActionBuilder { |
@@ -210,12 +211,12 @@ impl ActionBuilder { | |||
210 | } | 211 | } |
211 | 212 | ||
212 | /// Append specified `text` at the given `offset` | 213 | /// Append specified `text` at the given `offset` |
213 | pub(crate) fn insert(&mut self, offset: TextUnit, text: impl Into<String>) { | 214 | pub(crate) fn insert(&mut self, offset: TextSize, text: impl Into<String>) { |
214 | self.edit.insert(offset, text.into()) | 215 | self.edit.insert(offset, text.into()) |
215 | } | 216 | } |
216 | 217 | ||
217 | /// Specify desired position of the cursor after the assist is applied. | 218 | /// Specify desired position of the cursor after the assist is applied. |
218 | pub(crate) fn set_cursor(&mut self, offset: TextUnit) { | 219 | pub(crate) fn set_cursor(&mut self, offset: TextSize) { |
219 | self.cursor_position = Some(offset) | 220 | self.cursor_position = Some(offset) |
220 | } | 221 | } |
221 | 222 | ||
@@ -241,11 +242,16 @@ impl ActionBuilder { | |||
241 | algo::diff(&node, &new).into_text_edit(&mut self.edit) | 242 | algo::diff(&node, &new).into_text_edit(&mut self.edit) |
242 | } | 243 | } |
243 | 244 | ||
245 | pub(crate) fn set_file(&mut self, assist_file: AssistFile) { | ||
246 | self.file = assist_file | ||
247 | } | ||
248 | |||
244 | fn build(self) -> AssistAction { | 249 | fn build(self) -> AssistAction { |
245 | AssistAction { | 250 | AssistAction { |
246 | edit: self.edit.finish(), | 251 | edit: self.edit.finish(), |
247 | cursor_position: self.cursor_position, | 252 | cursor_position: self.cursor_position, |
248 | target: self.target, | 253 | target: self.target, |
254 | file: self.file, | ||
249 | } | 255 | } |
250 | } | 256 | } |
251 | } | 257 | } |