aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers/add_custom_impl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/handlers/add_custom_impl.rs')
-rw-r--r--crates/ra_assists/src/handlers/add_custom_impl.rs14
1 files changed, 5 insertions, 9 deletions
diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs
index dd2bed25a..15f9b216b 100644
--- a/crates/ra_assists/src/handlers/add_custom_impl.rs
+++ b/crates/ra_assists/src/handlers/add_custom_impl.rs
@@ -1,17 +1,13 @@
1//! FIXME: write short doc here
2
3use join_to_string::join;
4use ra_syntax::{ 1use ra_syntax::{
5 ast::{self, AstNode}, 2 ast::{self, AstNode},
6 Direction, SmolStr, 3 Direction, SmolStr,
7 SyntaxKind::{IDENT, WHITESPACE}, 4 SyntaxKind::{IDENT, WHITESPACE},
8 TextRange, TextUnit, 5 TextRange, TextUnit,
9}; 6};
7use stdx::SepBy;
10 8
11use crate::{Assist, AssistCtx, AssistId}; 9use crate::{Assist, AssistCtx, AssistId};
12 10
13const DERIVE_TRAIT: &str = "derive";
14
15// Assist: add_custom_impl 11// Assist: add_custom_impl
16// 12//
17// Adds impl block for derived trait. 13// Adds impl block for derived trait.
@@ -38,7 +34,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
38 .descendants_with_tokens() 34 .descendants_with_tokens()
39 .filter(|t| t.kind() == IDENT) 35 .filter(|t| t.kind() == IDENT)
40 .find_map(|i| i.into_token()) 36 .find_map(|i| i.into_token())
41 .filter(|t| *t.text() == DERIVE_TRAIT)? 37 .filter(|t| *t.text() == "derive")?
42 .text() 38 .text()
43 .clone(); 39 .clone();
44 40
@@ -63,8 +59,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
63 .filter(|t| t != trait_token.text()) 59 .filter(|t| t != trait_token.text())
64 .collect::<Vec<SmolStr>>(); 60 .collect::<Vec<SmolStr>>();
65 let has_more_derives = !new_attr_input.is_empty(); 61 let has_more_derives = !new_attr_input.is_empty();
66 let new_attr_input = 62 let new_attr_input = new_attr_input.iter().sep_by(", ").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(); 63 let new_attr_input_len = new_attr_input.len();
69 64
70 let mut buf = String::new(); 65 let mut buf = String::new();
@@ -100,9 +95,10 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
100 95
101#[cfg(test)] 96#[cfg(test)]
102mod tests { 97mod tests {
103 use super::*;
104 use crate::helpers::{check_assist, check_assist_not_applicable}; 98 use crate::helpers::{check_assist, check_assist_not_applicable};
105 99
100 use super::*;
101
106 #[test] 102 #[test]
107 fn add_custom_impl_for_unique_input() { 103 fn add_custom_impl_for_unique_input() {
108 check_assist( 104 check_assist(