aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/assists/move_bounds.rs3
-rw-r--r--crates/ra_assists/src/ast_editor.rs15
-rw-r--r--crates/ra_syntax/src/ast/edit.rs16
3 files changed, 16 insertions, 18 deletions
diff --git a/crates/ra_assists/src/assists/move_bounds.rs b/crates/ra_assists/src/assists/move_bounds.rs
index fd4bdc55c..1d27832a3 100644
--- a/crates/ra_assists/src/assists/move_bounds.rs
+++ b/crates/ra_assists/src/assists/move_bounds.rs
@@ -39,8 +39,7 @@ pub(crate) fn move_bounds_to_where_clause(mut ctx: AssistCtx<impl HirDatabase>)
39 .type_params() 39 .type_params()
40 .filter(|it| it.type_bound_list().is_some()) 40 .filter(|it| it.type_bound_list().is_some())
41 .map(|type_param| { 41 .map(|type_param| {
42 let without_bounds = 42 let without_bounds = type_param.remove_bounds();
43 AstEditor::new(type_param.clone()).remove_bounds().ast().clone();
44 (type_param, without_bounds) 43 (type_param, without_bounds)
45 }); 44 });
46 45
diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs
index 54849b7b0..69abf28a1 100644
--- a/crates/ra_assists/src/ast_editor.rs
+++ b/crates/ra_assists/src/ast_editor.rs
@@ -51,18 +51,3 @@ impl<N: AstNode> AstEditor<N> {
51 N::cast(new_syntax).unwrap() 51 N::cast(new_syntax).unwrap()
52 } 52 }
53} 53}
54
55impl AstEditor<ast::TypeParam> {
56 pub fn remove_bounds(&mut self) -> &mut Self {
57 let colon = match self.ast.colon_token() {
58 Some(it) => it,
59 None => return self,
60 };
61 let end = match self.ast.type_bound_list() {
62 Some(it) => it.syntax().clone().into(),
63 None => colon.clone().into(),
64 };
65 self.ast = self.replace_children(RangeInclusive::new(colon.into(), end), iter::empty());
66 self
67 }
68}
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index 6e64c0675..9d0fd1383 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -10,7 +10,7 @@ use crate::{
10 ast::{ 10 ast::{
11 self, 11 self,
12 make::{self, tokens}, 12 make::{self, tokens},
13 AstNode, 13 AstNode, TypeBoundsOwner,
14 }, 14 },
15 AstToken, Direction, InsertPosition, SmolStr, SyntaxElement, 15 AstToken, Direction, InsertPosition, SmolStr, SyntaxElement,
16 SyntaxKind::{ATTR, COMMENT, WHITESPACE}, 16 SyntaxKind::{ATTR, COMMENT, WHITESPACE},
@@ -185,6 +185,20 @@ impl ast::RecordFieldList {
185 } 185 }
186} 186}
187 187
188impl ast::TypeParam {
189 pub fn remove_bounds(&self) -> ast::TypeParam {
190 let colon = match self.colon_token() {
191 Some(it) => it,
192 None => return self.clone(),
193 };
194 let end = match self.type_bound_list() {
195 Some(it) => it.syntax().clone().into(),
196 None => colon.clone().into(),
197 };
198 replace_children(self, RangeInclusive::new(colon.into(), end), iter::empty())
199 }
200}
201
188pub fn strip_attrs_and_docs<N: ast::AttrsOwner>(node: N) -> N { 202pub fn strip_attrs_and_docs<N: ast::AttrsOwner>(node: N) -> N {
189 N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap() 203 N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap()
190} 204}