diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-03 13:44:09 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-03 13:44:09 +0100 |
commit | f51b0cfdd6c23dd57a0a11154179730171c0425d (patch) | |
tree | f856e6b751b23a20d68e9df5350ec39d5e8ee85b /crates/ra_assists/src/handlers/move_bounds.rs | |
parent | ef6a6d75d5dba2825e6b90e67e0b147a5f7158e1 (diff) | |
parent | 4c9347ecc3356748c52847a29d5e53a65778dc13 (diff) |
Merge #5116
5116: Categorize assists r=matklad a=kjeremy
Categorize assists so that editors can use them. Follows the LSP spec pretty close (and some things may need adjustments) but this populates the Refactor menu in vscode and pushes quickfixes through again.
This is a prerequisite to filtering out assists that the client doesn't care about.
Fixes #4147
Co-authored-by: Jeremy Kolb <[email protected]>
Co-authored-by: kjeremy <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/handlers/move_bounds.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/move_bounds.rs | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/crates/ra_assists/src/handlers/move_bounds.rs b/crates/ra_assists/src/handlers/move_bounds.rs index be2a7eddc..ba3dafb99 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs | |||
@@ -5,7 +5,7 @@ use ra_syntax::{ | |||
5 | T, | 5 | T, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use crate::{AssistContext, AssistId, Assists}; | 8 | use crate::{AssistContext, AssistId, AssistKind, Assists}; |
9 | 9 | ||
10 | // Assist: move_bounds_to_where_clause | 10 | // Assist: move_bounds_to_where_clause |
11 | // | 11 | // |
@@ -50,29 +50,36 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext | |||
50 | }; | 50 | }; |
51 | 51 | ||
52 | let target = type_param_list.syntax().text_range(); | 52 | let target = type_param_list.syntax().text_range(); |
53 | acc.add(AssistId("move_bounds_to_where_clause"), "Move to where clause", target, |edit| { | 53 | acc.add( |
54 | let new_params = type_param_list | 54 | AssistId("move_bounds_to_where_clause", AssistKind::RefactorRewrite), |
55 | .type_params() | 55 | "Move to where clause", |
56 | .filter(|it| it.type_bound_list().is_some()) | 56 | target, |
57 | .map(|type_param| { | 57 | |edit| { |
58 | let without_bounds = type_param.remove_bounds(); | 58 | let new_params = type_param_list |
59 | (type_param, without_bounds) | 59 | .type_params() |
60 | }); | 60 | .filter(|it| it.type_bound_list().is_some()) |
61 | 61 | .map(|type_param| { | |
62 | let new_type_param_list = type_param_list.replace_descendants(new_params); | 62 | let without_bounds = type_param.remove_bounds(); |
63 | edit.replace_ast(type_param_list.clone(), new_type_param_list); | 63 | (type_param, without_bounds) |
64 | 64 | }); | |
65 | let where_clause = { | 65 | |
66 | let predicates = type_param_list.type_params().filter_map(build_predicate); | 66 | let new_type_param_list = type_param_list.replace_descendants(new_params); |
67 | make::where_clause(predicates) | 67 | edit.replace_ast(type_param_list.clone(), new_type_param_list); |
68 | }; | 68 | |
69 | 69 | let where_clause = { | |
70 | let to_insert = match anchor.prev_sibling_or_token() { | 70 | let predicates = type_param_list.type_params().filter_map(build_predicate); |
71 | Some(ref elem) if elem.kind() == WHITESPACE => format!("{} ", where_clause.syntax()), | 71 | make::where_clause(predicates) |
72 | _ => format!(" {}", where_clause.syntax()), | 72 | }; |
73 | }; | 73 | |
74 | edit.insert(anchor.text_range().start(), to_insert); | 74 | let to_insert = match anchor.prev_sibling_or_token() { |
75 | }) | 75 | Some(ref elem) if elem.kind() == WHITESPACE => { |
76 | format!("{} ", where_clause.syntax()) | ||
77 | } | ||
78 | _ => format!(" {}", where_clause.syntax()), | ||
79 | }; | ||
80 | edit.insert(anchor.text_range().start(), to_insert); | ||
81 | }, | ||
82 | ) | ||
76 | } | 83 | } |
77 | 84 | ||
78 | fn build_predicate(param: ast::TypeParam) -> Option<ast::WherePred> { | 85 | fn build_predicate(param: ast::TypeParam) -> Option<ast::WherePred> { |