aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-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
-rw-r--r--crates/ra_db/src/fixture.rs20
-rw-r--r--crates/test_utils/src/fixture.rs4
8 files changed, 65 insertions, 60 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;
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs
index 3959d7efe..541815fe7 100644
--- a/crates/ra_db/src/fixture.rs
+++ b/crates/ra_db/src/fixture.rs
@@ -61,7 +61,7 @@ use std::{str::FromStr, sync::Arc};
61 61
62use ra_cfg::CfgOptions; 62use ra_cfg::CfgOptions;
63use rustc_hash::FxHashMap; 63use rustc_hash::FxHashMap;
64use test_utils::{extract_offset, Fixture, CURSOR_MARKER}; 64use test_utils::{extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER};
65use vfs::{file_set::FileSet, VfsPath}; 65use vfs::{file_set::FileSet, VfsPath};
66 66
67use crate::{ 67use crate::{
@@ -86,9 +86,19 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static {
86 } 86 }
87 87
88 fn with_position(ra_fixture: &str) -> (Self, FilePosition) { 88 fn with_position(ra_fixture: &str) -> (Self, FilePosition) {
89 let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture);
90 let offset = match range_or_offset {
91 RangeOrOffset::Range(_) => panic!(),
92 RangeOrOffset::Offset(it) => it,
93 };
94 (db, FilePosition { file_id, offset })
95 }
96
97 fn with_range_or_offset(ra_fixture: &str) -> (Self, FileId, RangeOrOffset) {
89 let mut db = Self::default(); 98 let mut db = Self::default();
90 let (pos, _) = with_files(&mut db, ra_fixture); 99 let (pos, _) = with_files(&mut db, ra_fixture);
91 (db, pos.unwrap()) 100 let (file_id, range_or_offset) = pos.unwrap();
101 (db, file_id, range_or_offset)
92 } 102 }
93 103
94 fn test_crate(&self) -> CrateId { 104 fn test_crate(&self) -> CrateId {
@@ -151,7 +161,7 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId
151fn with_files( 161fn with_files(
152 db: &mut dyn SourceDatabaseExt, 162 db: &mut dyn SourceDatabaseExt,
153 fixture: &str, 163 fixture: &str,
154) -> (Option<FilePosition>, Vec<FileId>) { 164) -> (Option<(FileId, RangeOrOffset)>, Vec<FileId>) {
155 let fixture = Fixture::parse(fixture); 165 let fixture = Fixture::parse(fixture);
156 166
157 let mut files = Vec::new(); 167 let mut files = Vec::new();
@@ -193,9 +203,9 @@ fn with_files(
193 } 203 }
194 204
195 let text = if entry.text.contains(CURSOR_MARKER) { 205 let text = if entry.text.contains(CURSOR_MARKER) {
196 let (offset, text) = extract_offset(&entry.text); 206 let (range_or_offset, text) = extract_range_or_offset(&entry.text);
197 assert!(file_position.is_none()); 207 assert!(file_position.is_none());
198 file_position = Some(FilePosition { file_id, offset }); 208 file_position = Some((file_id, range_or_offset));
199 text.to_string() 209 text.to_string()
200 } else { 210 } else {
201 entry.text.to_string() 211 entry.text.to_string()
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs
index 8747fa4a5..7e93fbcd6 100644
--- a/crates/test_utils/src/fixture.rs
+++ b/crates/test_utils/src/fixture.rs
@@ -30,7 +30,9 @@ impl Fixture {
30 30
31 let mut res: Vec<Fixture> = Vec::new(); 31 let mut res: Vec<Fixture> = Vec::new();
32 32
33 for (ix, line) in lines_with_ends(&fixture).enumerate() { 33 let default = if ra_fixture.contains("//-") { None } else { Some("//- /main.rs") };
34
35 for (ix, line) in default.into_iter().chain(lines_with_ends(&fixture)).enumerate() {
34 if line.contains("//-") { 36 if line.contains("//-") {
35 assert!( 37 assert!(
36 line.starts_with("//-"), 38 line.starts_with("//-"),