aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/assist_ctx.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/assist_ctx.rs')
-rw-r--r--crates/ra_assists/src/assist_ctx.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs
index a12c3ed54..c45262efa 100644
--- a/crates/ra_assists/src/assist_ctx.rs
+++ b/crates/ra_assists/src/assist_ctx.rs
@@ -129,10 +129,13 @@ pub(crate) struct AssistBuilder {
129} 129}
130 130
131impl AssistBuilder { 131impl AssistBuilder {
132 /// Replaces specified `range` of text with a given string.
132 pub(crate) fn replace(&mut self, range: TextRange, replace_with: impl Into<String>) { 133 pub(crate) fn replace(&mut self, range: TextRange, replace_with: impl Into<String>) {
133 self.edit.replace(range, replace_with.into()) 134 self.edit.replace(range, replace_with.into())
134 } 135 }
135 136
137 /// Replaces specified `node` of text with a given string, reindenting the
138 /// string to maintain `node`'s existing indent.
136 pub(crate) fn replace_node_and_indent( 139 pub(crate) fn replace_node_and_indent(
137 &mut self, 140 &mut self,
138 node: &SyntaxNode, 141 node: &SyntaxNode,
@@ -145,27 +148,31 @@ impl AssistBuilder {
145 self.replace(node.text_range(), replace_with) 148 self.replace(node.text_range(), replace_with)
146 } 149 }
147 150
148 pub(crate) fn set_edit_builder(&mut self, edit: TextEditBuilder) { 151 /// Remove specified `range` of text.
149 self.edit = edit;
150 }
151
152 #[allow(unused)] 152 #[allow(unused)]
153 pub(crate) fn delete(&mut self, range: TextRange) { 153 pub(crate) fn delete(&mut self, range: TextRange) {
154 self.edit.delete(range) 154 self.edit.delete(range)
155 } 155 }
156 156
157 /// Append specified `text` at the given `offset`
157 pub(crate) fn insert(&mut self, offset: TextUnit, text: impl Into<String>) { 158 pub(crate) fn insert(&mut self, offset: TextUnit, text: impl Into<String>) {
158 self.edit.insert(offset, text.into()) 159 self.edit.insert(offset, text.into())
159 } 160 }
160 161
162 /// Specify desired position of the cursor after the assist is applied.
161 pub(crate) fn set_cursor(&mut self, offset: TextUnit) { 163 pub(crate) fn set_cursor(&mut self, offset: TextUnit) {
162 self.cursor_position = Some(offset) 164 self.cursor_position = Some(offset)
163 } 165 }
164 166
167 /// Specify that the assist should be active withing the `target` range.
168 ///
169 /// Target ranges are used to sort assists: the smaller the target range,
170 /// the more specific assist is, and so it should be sorted first.
165 pub(crate) fn target(&mut self, target: TextRange) { 171 pub(crate) fn target(&mut self, target: TextRange) {
166 self.target = Some(target) 172 self.target = Some(target)
167 } 173 }
168 174
175 /// Get access to the raw `TextEditBuilder`.
169 pub(crate) fn text_edit_builder(&mut self) -> &mut TextEditBuilder { 176 pub(crate) fn text_edit_builder(&mut self) -> &mut TextEditBuilder {
170 &mut self.edit 177 &mut self.edit
171 } 178 }