aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/join_lines.rs12
-rw-r--r--crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs86
2 files changed, 31 insertions, 67 deletions
diff --git a/crates/ide/src/join_lines.rs b/crates/ide/src/join_lines.rs
index 3e30e71ce..61dcbb399 100644
--- a/crates/ide/src/join_lines.rs
+++ b/crates/ide/src/join_lines.rs
@@ -67,18 +67,6 @@ fn remove_newlines(edit: &mut TextEditBuilder, token: &SyntaxToken, range: TextR
67 67
68fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextSize) { 68fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextSize) {
69 if token.kind() != WHITESPACE || token.text().bytes().filter(|&b| b == b'\n').count() != 1 { 69 if token.kind() != WHITESPACE || token.text().bytes().filter(|&b| b == b'\n').count() != 1 {
70 let mut no_space = false;
71 if let Some(string) = ast::String::cast(token.clone()) {
72 if let Some(range) = string.open_quote_text_range() {
73 cov_mark::hit!(join_string_literal_open_quote);
74 no_space |= range.end() == offset;
75 }
76 if let Some(range) = string.close_quote_text_range() {
77 cov_mark::hit!(join_string_literal_close_quote);
78 no_space |= range.start() == offset + TextSize::of('\n');
79 }
80 }
81
82 let n_spaces_after_line_break = { 70 let n_spaces_after_line_break = {
83 let suff = &token.text()[TextRange::new( 71 let suff = &token.text()[TextRange::new(
84 offset - token.text_range().start() + TextSize::of('\n'), 72 offset - token.text_range().start() + TextSize::of('\n'),
diff --git a/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs b/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs
index ff25b61ea..8509a5e11 100644
--- a/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs
+++ b/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs
@@ -55,12 +55,8 @@ mod tests {
55 fn replace_impl_trait_with_generic_params() { 55 fn replace_impl_trait_with_generic_params() {
56 check_assist( 56 check_assist(
57 replace_impl_trait_with_generic, 57 replace_impl_trait_with_generic,
58 r#" 58 r#"fn foo<G>(bar: $0impl Bar) {}"#,
59 fn foo<G>(bar: $0impl Bar) {} 59 r#"fn foo<G, B: Bar>(bar: B) {}"#,
60 "#,
61 r#"
62 fn foo<G, B: Bar>(bar: B) {}
63 "#,
64 ); 60 );
65 } 61 }
66 62
@@ -68,12 +64,8 @@ mod tests {
68 fn replace_impl_trait_without_generic_params() { 64 fn replace_impl_trait_without_generic_params() {
69 check_assist( 65 check_assist(
70 replace_impl_trait_with_generic, 66 replace_impl_trait_with_generic,
71 r#" 67 r#"fn foo(bar: $0impl Bar) {}"#,
72 fn foo(bar: $0impl Bar) {} 68 r#"fn foo<B: Bar>(bar: B) {}"#,
73 "#,
74 r#"
75 fn foo<B: Bar>(bar: B) {}
76 "#,
77 ); 69 );
78 } 70 }
79 71
@@ -81,12 +73,8 @@ mod tests {
81 fn replace_two_impl_trait_with_generic_params() { 73 fn replace_two_impl_trait_with_generic_params() {
82 check_assist( 74 check_assist(
83 replace_impl_trait_with_generic, 75 replace_impl_trait_with_generic,
84 r#" 76 r#"fn foo<G>(foo: impl Foo, bar: $0impl Bar) {}"#,
85 fn foo<G>(foo: impl Foo, bar: $0impl Bar) {} 77 r#"fn foo<G, B: Bar>(foo: impl Foo, bar: B) {}"#,
86 "#,
87 r#"
88 fn foo<G, B: Bar>(foo: impl Foo, bar: B) {}
89 "#,
90 ); 78 );
91 } 79 }
92 80
@@ -94,12 +82,8 @@ mod tests {
94 fn replace_impl_trait_with_empty_generic_params() { 82 fn replace_impl_trait_with_empty_generic_params() {
95 check_assist( 83 check_assist(
96 replace_impl_trait_with_generic, 84 replace_impl_trait_with_generic,
97 r#" 85 r#"fn foo<>(bar: $0impl Bar) {}"#,
98 fn foo<>(bar: $0impl Bar) {} 86 r#"fn foo<B: Bar>(bar: B) {}"#,
99 "#,
100 r#"
101 fn foo<B: Bar>(bar: B) {}
102 "#,
103 ); 87 );
104 } 88 }
105 89
@@ -108,13 +92,13 @@ mod tests {
108 check_assist( 92 check_assist(
109 replace_impl_trait_with_generic, 93 replace_impl_trait_with_generic,
110 r#" 94 r#"
111 fn foo< 95fn foo<
112 >(bar: $0impl Bar) {} 96>(bar: $0impl Bar) {}
113 "#, 97"#,
114 r#" 98 r#"
115 fn foo<B: Bar 99fn foo<B: Bar
116 >(bar: B) {} 100>(bar: B) {}
117 "#, 101"#,
118 ); 102 );
119 } 103 }
120 104
@@ -123,12 +107,8 @@ mod tests {
123 fn replace_impl_trait_with_exist_generic_letter() { 107 fn replace_impl_trait_with_exist_generic_letter() {
124 check_assist( 108 check_assist(
125 replace_impl_trait_with_generic, 109 replace_impl_trait_with_generic,
126 r#" 110 r#"fn foo<B>(bar: $0impl Bar) {}"#,
127 fn foo<B>(bar: $0impl Bar) {} 111 r#"fn foo<B, C: Bar>(bar: C) {}"#,
128 "#,
129 r#"
130 fn foo<B, C: Bar>(bar: C) {}
131 "#,
132 ); 112 );
133 } 113 }
134 114
@@ -137,19 +117,19 @@ mod tests {
137 check_assist( 117 check_assist(
138 replace_impl_trait_with_generic, 118 replace_impl_trait_with_generic,
139 r#" 119 r#"
140 fn foo< 120fn foo<
141 G: Foo, 121 G: Foo,
142 F, 122 F,
143 H, 123 H,
144 >(bar: $0impl Bar) {} 124>(bar: $0impl Bar) {}
145 "#, 125"#,
146 r#" 126 r#"
147 fn foo< 127fn foo<
148 G: Foo, 128 G: Foo,
149 F, 129 F,
150 H, B: Bar 130 H, B: Bar
151 >(bar: B) {} 131>(bar: B) {}
152 "#, 132"#,
153 ); 133 );
154 } 134 }
155 135
@@ -157,12 +137,8 @@ mod tests {
157 fn replace_impl_trait_multiple() { 137 fn replace_impl_trait_multiple() {
158 check_assist( 138 check_assist(
159 replace_impl_trait_with_generic, 139 replace_impl_trait_with_generic,
160 r#" 140 r#"fn foo(bar: $0impl Foo + Bar) {}"#,
161 fn foo(bar: $0impl Foo + Bar) {} 141 r#"fn foo<F: Foo + Bar>(bar: F) {}"#,
162 "#,
163 r#"
164 fn foo<F: Foo + Bar>(bar: F) {}
165 "#,
166 ); 142 );
167 } 143 }
168} 144}