diff options
Diffstat (limited to 'crates/ra_assists')
-rw-r--r-- | crates/ra_assists/Cargo.toml | 4 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/add_custom_impl.rs | 8 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/add_new.rs | 2 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/move_guard.rs | 6 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/replace_if_let_with_match.rs | 2 | ||||
-rw-r--r-- | crates/ra_assists/src/lib.rs | 4 |
6 files changed, 13 insertions, 13 deletions
diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml index 6973038d4..12a933645 100644 --- a/crates/ra_assists/Cargo.toml +++ b/crates/ra_assists/Cargo.toml | |||
@@ -10,8 +10,8 @@ doctest = false | |||
10 | [dependencies] | 10 | [dependencies] |
11 | format-buf = "1.0.0" | 11 | format-buf = "1.0.0" |
12 | join_to_string = "0.1.3" | 12 | join_to_string = "0.1.3" |
13 | rustc-hash = "1.0" | 13 | rustc-hash = "1.1.0" |
14 | either = "1.5" | 14 | either = "1.5.3" |
15 | 15 | ||
16 | ra_syntax = { path = "../ra_syntax" } | 16 | ra_syntax = { path = "../ra_syntax" } |
17 | ra_text_edit = { path = "../ra_text_edit" } | 17 | ra_text_edit = { path = "../ra_text_edit" } |
diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs index 7fdd816bf..74aa4b001 100644 --- a/crates/ra_assists/src/handlers/add_custom_impl.rs +++ b/crates/ra_assists/src/handlers/add_custom_impl.rs | |||
@@ -43,9 +43,9 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> { | |||
43 | .clone(); | 43 | .clone(); |
44 | 44 | ||
45 | let trait_token = | 45 | let trait_token = |
46 | ctx.token_at_offset().filter(|t| t.kind() == IDENT && *t.text() != attr_name).next()?; | 46 | ctx.token_at_offset().find(|t| t.kind() == IDENT && *t.text() != attr_name)?; |
47 | 47 | ||
48 | let annotated = attr.syntax().siblings(Direction::Next).find_map(|s| ast::Name::cast(s))?; | 48 | let annotated = attr.syntax().siblings(Direction::Next).find_map(ast::Name::cast)?; |
49 | let annotated_name = annotated.syntax().text().to_string(); | 49 | let annotated_name = annotated.syntax().text().to_string(); |
50 | let start_offset = annotated.syntax().parent()?.text_range().end(); | 50 | let start_offset = annotated.syntax().parent()?.text_range().end(); |
51 | 51 | ||
@@ -62,7 +62,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> { | |||
62 | .filter_map(|t| t.into_token().map(|t| t.text().clone())) | 62 | .filter_map(|t| t.into_token().map(|t| t.text().clone())) |
63 | .filter(|t| t != trait_token.text()) | 63 | .filter(|t| t != trait_token.text()) |
64 | .collect::<Vec<SmolStr>>(); | 64 | .collect::<Vec<SmolStr>>(); |
65 | let has_more_derives = new_attr_input.len() > 0; | 65 | let has_more_derives = !new_attr_input.is_empty(); |
66 | let new_attr_input = | 66 | let new_attr_input = |
67 | join(new_attr_input.iter()).separator(", ").surround_with("(", ")").to_string(); | 67 | join(new_attr_input.iter()).separator(", ").surround_with("(", ")").to_string(); |
68 | let new_attr_input_len = new_attr_input.len(); | 68 | let new_attr_input_len = new_attr_input.len(); |
@@ -86,7 +86,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> { | |||
86 | .next_sibling_or_token() | 86 | .next_sibling_or_token() |
87 | .filter(|t| t.kind() == WHITESPACE) | 87 | .filter(|t| t.kind() == WHITESPACE) |
88 | .map(|t| t.text_range()) | 88 | .map(|t| t.text_range()) |
89 | .unwrap_or(TextRange::from_to(TextUnit::from(0), TextUnit::from(0))); | 89 | .unwrap_or_else(|| TextRange::from_to(TextUnit::from(0), TextUnit::from(0))); |
90 | edit.delete(line_break_range); | 90 | edit.delete(line_break_range); |
91 | 91 | ||
92 | attr_range.len() + line_break_range.len() | 92 | attr_range.len() + line_break_range.len() |
diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs index 2701eddb8..dd070e8ec 100644 --- a/crates/ra_assists/src/handlers/add_new.rs +++ b/crates/ra_assists/src/handlers/add_new.rs | |||
@@ -53,7 +53,7 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option<Assist> { | |||
53 | } | 53 | } |
54 | 54 | ||
55 | let vis = strukt.visibility().map(|v| format!("{} ", v.syntax())); | 55 | let vis = strukt.visibility().map(|v| format!("{} ", v.syntax())); |
56 | let vis = vis.as_ref().map(String::as_str).unwrap_or(""); | 56 | let vis = vis.as_deref().unwrap_or(""); |
57 | write!(&mut buf, " {}fn new(", vis).unwrap(); | 57 | write!(&mut buf, " {}fn new(", vis).unwrap(); |
58 | 58 | ||
59 | join(field_list.fields().filter_map(|f| { | 59 | join(field_list.fields().filter_map(|f| { |
diff --git a/crates/ra_assists/src/handlers/move_guard.rs b/crates/ra_assists/src/handlers/move_guard.rs index a61a2ba3e..1cc498638 100644 --- a/crates/ra_assists/src/handlers/move_guard.rs +++ b/crates/ra_assists/src/handlers/move_guard.rs | |||
@@ -44,7 +44,7 @@ pub(crate) fn move_guard_to_arm_body(ctx: AssistCtx) -> Option<Assist> { | |||
44 | edit.target(guard.syntax().text_range()); | 44 | edit.target(guard.syntax().text_range()); |
45 | let offseting_amount = match space_before_guard.and_then(|it| it.into_token()) { | 45 | let offseting_amount = match space_before_guard.and_then(|it| it.into_token()) { |
46 | Some(tok) => { | 46 | Some(tok) => { |
47 | if let Some(_) = ast::Whitespace::cast(tok.clone()) { | 47 | if ast::Whitespace::cast(tok.clone()).is_some() { |
48 | let ele = tok.text_range(); | 48 | let ele = tok.text_range(); |
49 | edit.delete(ele); | 49 | edit.delete(ele); |
50 | ele.len() | 50 | ele.len() |
@@ -98,11 +98,11 @@ pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option<Assist> { | |||
98 | let then_block = if_expr.then_branch()?; | 98 | let then_block = if_expr.then_branch()?; |
99 | 99 | ||
100 | // Not support if with else branch | 100 | // Not support if with else branch |
101 | if let Some(_) = if_expr.else_branch() { | 101 | if if_expr.else_branch().is_some() { |
102 | return None; | 102 | return None; |
103 | } | 103 | } |
104 | // Not support moving if let to arm guard | 104 | // Not support moving if let to arm guard |
105 | if let Some(_) = cond.pat() { | 105 | if cond.pat().is_some() { |
106 | return None; | 106 | return None; |
107 | } | 107 | } |
108 | 108 | ||
diff --git a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs index e6cd50bc1..0a0a88f3d 100644 --- a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs | |||
@@ -61,7 +61,7 @@ pub(crate) fn replace_if_let_with_match(ctx: AssistCtx) -> Option<Assist> { | |||
61 | 61 | ||
62 | edit.target(if_expr.syntax().text_range()); | 62 | edit.target(if_expr.syntax().text_range()); |
63 | edit.set_cursor(if_expr.syntax().text_range().start()); | 63 | edit.set_cursor(if_expr.syntax().text_range().start()); |
64 | edit.replace_ast::<ast::Expr>(if_expr.into(), match_expr.into()); | 64 | edit.replace_ast::<ast::Expr>(if_expr.into(), match_expr); |
65 | }) | 65 | }) |
66 | } | 66 | } |
67 | 67 | ||
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index cb124eaf0..a0e7fe17e 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs | |||
@@ -38,8 +38,8 @@ pub struct GroupLabel(pub String); | |||
38 | impl AssistLabel { | 38 | impl AssistLabel { |
39 | pub(crate) fn new(label: String, id: AssistId) -> AssistLabel { | 39 | pub(crate) fn new(label: String, id: AssistId) -> AssistLabel { |
40 | // FIXME: make fields private, so that this invariant can't be broken | 40 | // FIXME: make fields private, so that this invariant can't be broken |
41 | assert!(label.chars().nth(0).unwrap().is_uppercase()); | 41 | assert!(label.chars().next().unwrap().is_uppercase()); |
42 | AssistLabel { label: label.into(), id } | 42 | AssistLabel { label, id } |
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||