aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r--crates/ra_assists/src/handlers/add_function.rs1
-rw-r--r--crates/ra_assists/src/handlers/fill_match_arms.rs6
-rw-r--r--crates/ra_assists/src/handlers/introduce_variable.rs20
-rw-r--r--crates/ra_assists/src/handlers/raw_string.rs48
-rw-r--r--crates/ra_assists/src/tests.rs23
-rw-r--r--crates/ra_assists/src/utils.rs3
6 files changed, 47 insertions, 54 deletions
diff --git a/crates/ra_assists/src/handlers/add_function.rs b/crates/ra_assists/src/handlers/add_function.rs
index 19ce81d99..1cfbd75aa 100644
--- a/crates/ra_assists/src/handlers/add_function.rs
+++ b/crates/ra_assists/src/handlers/add_function.rs
@@ -986,6 +986,7 @@ fn main() {
986", 986",
987 r" 987 r"
988 988
989
989pub(crate) fn bar() { 990pub(crate) fn bar() {
990 ${0:todo!()} 991 ${0:todo!()}
991}", 992}",
diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs
index 3c12c1daa..64270c86f 100644
--- a/crates/ra_assists/src/handlers/fill_match_arms.rs
+++ b/crates/ra_assists/src/handlers/fill_match_arms.rs
@@ -763,9 +763,9 @@ mod tests {
763fn foo(opt: Option<i32>) { 763fn foo(opt: Option<i32>) {
764 match opt<|> { 764 match opt<|> {
765 } 765 }
766}"#; 766}
767 let before = 767"#;
768 &format!("//- /main.rs crate:main deps:core\n{}{}", before, FamousDefs::FIXTURE); 768 let before = &format!("//- /main.rs crate:main deps:core{}{}", before, FamousDefs::FIXTURE);
769 769
770 check_assist( 770 check_assist(
771 fill_match_arms, 771 fill_match_arms,
diff --git a/crates/ra_assists/src/handlers/introduce_variable.rs b/crates/ra_assists/src/handlers/introduce_variable.rs
index 31d6539f7..88b62278f 100644
--- a/crates/ra_assists/src/handlers/introduce_variable.rs
+++ b/crates/ra_assists/src/handlers/introduce_variable.rs
@@ -226,27 +226,31 @@ fn foo() {
226 mark::check!(test_introduce_var_last_expr); 226 mark::check!(test_introduce_var_last_expr);
227 check_assist( 227 check_assist(
228 introduce_variable, 228 introduce_variable,
229 " 229 r#"
230fn foo() { 230fn foo() {
231 bar(<|>1 + 1<|>) 231 bar(<|>1 + 1<|>)
232}", 232}
233 " 233"#,
234 r#"
234fn foo() { 235fn foo() {
235 let $0var_name = 1 + 1; 236 let $0var_name = 1 + 1;
236 bar(var_name) 237 bar(var_name)
237}", 238}
239"#,
238 ); 240 );
239 check_assist( 241 check_assist(
240 introduce_variable, 242 introduce_variable,
241 " 243 r#"
242fn foo() { 244fn foo() {
243 <|>bar(1 + 1)<|> 245 <|>bar(1 + 1)<|>
244}", 246}
245 " 247"#,
248 r#"
246fn foo() { 249fn foo() {
247 let $0var_name = bar(1 + 1); 250 let $0var_name = bar(1 + 1);
248 var_name 251 var_name
249}", 252}
253"#,
250 ) 254 )
251 } 255 }
252 256
diff --git a/crates/ra_assists/src/handlers/raw_string.rs b/crates/ra_assists/src/handlers/raw_string.rs
index 16002d2ac..d22d0aa55 100644
--- a/crates/ra_assists/src/handlers/raw_string.rs
+++ b/crates/ra_assists/src/handlers/raw_string.rs
@@ -158,16 +158,16 @@ mod test {
158 check_assist( 158 check_assist(
159 make_raw_string, 159 make_raw_string,
160 r#" 160 r#"
161 fn f() { 161fn f() {
162 let s = <|>"random\nstring"; 162 let s = <|>"random\nstring";
163 } 163}
164 "#, 164"#,
165 r##" 165 r##"
166 fn f() { 166fn f() {
167 let s = r#"random 167 let s = r#"random
168string"#; 168string"#;
169 } 169}
170 "##, 170"##,
171 ) 171 )
172 } 172 }
173 173
@@ -193,16 +193,16 @@ string"#;
193 check_assist( 193 check_assist(
194 make_raw_string, 194 make_raw_string,
195 r###" 195 r###"
196 fn f() { 196fn f() {
197 let s = <|>"#random##\nstring"; 197 let s = <|>"#random##\nstring";
198 } 198}
199 "###, 199"###,
200 r####" 200 r####"
201 fn f() { 201fn f() {
202 let s = r#"#random## 202 let s = r#"#random##
203string"#; 203string"#;
204 } 204}
205 "####, 205"####,
206 ) 206 )
207 } 207 }
208 208
@@ -211,16 +211,16 @@ string"#;
211 check_assist( 211 check_assist(
212 make_raw_string, 212 make_raw_string,
213 r###" 213 r###"
214 fn f() { 214fn f() {
215 let s = <|>"#random\"##\nstring"; 215 let s = <|>"#random\"##\nstring";
216 } 216}
217 "###, 217"###,
218 r####" 218 r####"
219 fn f() { 219fn f() {
220 let s = r###"#random"## 220 let s = r###"#random"##
221string"###; 221string"###;
222 } 222}
223 "####, 223"####,
224 ) 224 )
225 } 225 }
226 226
diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs
index 55576813f..49837d60b 100644
--- a/crates/ra_assists/src/tests.rs
+++ b/crates/ra_assists/src/tests.rs
@@ -4,18 +4,18 @@ use hir::Semantics;
4use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; 4use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt};
5use ra_ide_db::RootDatabase; 5use ra_ide_db::RootDatabase;
6use ra_syntax::TextRange; 6use ra_syntax::TextRange;
7use test_utils::{ 7use test_utils::{assert_eq_text, extract_offset, extract_range, extract_range_or_offset};
8 assert_eq_text, extract_offset, extract_range, extract_range_or_offset, RangeOrOffset,
9};
10 8
11use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, Assists}; 9use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, Assists};
10use stdx::trim_indent;
12 11
13pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { 12pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
14 RootDatabase::with_single_file(text) 13 RootDatabase::with_single_file(text)
15} 14}
16 15
17pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_after: &str) { 16pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_after: &str) {
18 check(assist, ra_fixture_before, ExpectedResult::After(ra_fixture_after)); 17 let ra_fixture_after = trim_indent(ra_fixture_after);
18 check(assist, ra_fixture_before, ExpectedResult::After(&ra_fixture_after));
19} 19}
20 20
21// FIXME: instead of having a separate function here, maybe use 21// FIXME: instead of having a separate function here, maybe use
@@ -65,19 +65,8 @@ enum ExpectedResult<'a> {
65} 65}
66 66
67fn check(handler: Handler, before: &str, expected: ExpectedResult) { 67fn check(handler: Handler, before: &str, expected: ExpectedResult) {
68 let (text_without_caret, file_with_caret_id, range_or_offset, db) = if before.contains("//-") { 68 let (db, file_with_caret_id, range_or_offset) = RootDatabase::with_range_or_offset(before);
69 let (db, position) = RootDatabase::with_position(before); 69 let text_without_caret = db.file_text(file_with_caret_id).as_ref().to_owned();
70 (
71 db.file_text(position.file_id).as_ref().to_owned(),
72 position.file_id,
73 RangeOrOffset::Offset(position.offset),
74 db,
75 )
76 } else {
77 let (range_or_offset, text_without_caret) = extract_range_or_offset(before);
78 let (db, file_id) = with_single_file(&text_without_caret);
79 (text_without_caret, file_id, range_or_offset, db)
80 };
81 70
82 let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() }; 71 let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() };
83 72
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs
index c1ff0de7b..b7c45a619 100644
--- a/crates/ra_assists/src/utils.rs
+++ b/crates/ra_assists/src/utils.rs
@@ -198,8 +198,7 @@ pub(crate) struct FamousDefs<'a, 'b>(pub(crate) &'a Semantics<'b, RootDatabase>,
198#[allow(non_snake_case)] 198#[allow(non_snake_case)]
199impl FamousDefs<'_, '_> { 199impl FamousDefs<'_, '_> {
200 #[cfg(test)] 200 #[cfg(test)]
201 pub(crate) const FIXTURE: &'static str = r#" 201 pub(crate) const FIXTURE: &'static str = r#"//- /libcore.rs crate:core
202//- /libcore.rs crate:core
203pub mod convert { 202pub mod convert {
204 pub trait From<T> { 203 pub trait From<T> {
205 fn from(T) -> Self; 204 fn from(T) -> Self;