aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/lib.rs')
-rw-r--r--crates/ra_assists/src/lib.rs40
1 files changed, 21 insertions, 19 deletions
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index 38599d4f1..39c1c283f 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -9,6 +9,8 @@ mod assist_ctx;
9mod marks; 9mod marks;
10#[cfg(test)] 10#[cfg(test)]
11mod doc_tests; 11mod doc_tests;
12#[cfg(test)]
13mod test_db;
12 14
13use hir::db::HirDatabase; 15use hir::db::HirDatabase;
14use ra_db::FileRange; 16use ra_db::FileRange;
@@ -146,20 +148,19 @@ mod assists {
146 148
147#[cfg(test)] 149#[cfg(test)]
148mod helpers { 150mod helpers {
149 use hir::mock::MockDatabase; 151 use ra_db::{fixture::WithFixture, FileRange};
150 use ra_db::FileRange;
151 use ra_syntax::TextRange; 152 use ra_syntax::TextRange;
152 use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range}; 153 use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range};
153 154
154 use crate::{Assist, AssistCtx}; 155 use crate::{test_db::TestDB, Assist, AssistCtx};
155 156
156 pub(crate) fn check_assist( 157 pub(crate) fn check_assist(
157 assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>, 158 assist: fn(AssistCtx<TestDB>) -> Option<Assist>,
158 before: &str, 159 before: &str,
159 after: &str, 160 after: &str,
160 ) { 161 ) {
161 let (before_cursor_pos, before) = extract_offset(before); 162 let (before_cursor_pos, before) = extract_offset(before);
162 let (db, _source_root, file_id) = MockDatabase::with_single_file(&before); 163 let (db, file_id) = TestDB::with_single_file(&before);
163 let frange = 164 let frange =
164 FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; 165 FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) };
165 let assist = 166 let assist =
@@ -182,12 +183,12 @@ mod helpers {
182 } 183 }
183 184
184 pub(crate) fn check_assist_range( 185 pub(crate) fn check_assist_range(
185 assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>, 186 assist: fn(AssistCtx<TestDB>) -> Option<Assist>,
186 before: &str, 187 before: &str,
187 after: &str, 188 after: &str,
188 ) { 189 ) {
189 let (range, before) = extract_range(before); 190 let (range, before) = extract_range(before);
190 let (db, _source_root, file_id) = MockDatabase::with_single_file(&before); 191 let (db, file_id) = TestDB::with_single_file(&before);
191 let frange = FileRange { file_id, range }; 192 let frange = FileRange { file_id, range };
192 let assist = 193 let assist =
193 AssistCtx::with_ctx(&db, frange, true, assist).expect("code action is not applicable"); 194 AssistCtx::with_ctx(&db, frange, true, assist).expect("code action is not applicable");
@@ -204,12 +205,12 @@ mod helpers {
204 } 205 }
205 206
206 pub(crate) fn check_assist_target( 207 pub(crate) fn check_assist_target(
207 assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>, 208 assist: fn(AssistCtx<TestDB>) -> Option<Assist>,
208 before: &str, 209 before: &str,
209 target: &str, 210 target: &str,
210 ) { 211 ) {
211 let (before_cursor_pos, before) = extract_offset(before); 212 let (before_cursor_pos, before) = extract_offset(before);
212 let (db, _source_root, file_id) = MockDatabase::with_single_file(&before); 213 let (db, file_id) = TestDB::with_single_file(&before);
213 let frange = 214 let frange =
214 FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; 215 FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) };
215 let assist = 216 let assist =
@@ -224,12 +225,12 @@ mod helpers {
224 } 225 }
225 226
226 pub(crate) fn check_assist_range_target( 227 pub(crate) fn check_assist_range_target(
227 assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>, 228 assist: fn(AssistCtx<TestDB>) -> Option<Assist>,
228 before: &str, 229 before: &str,
229 target: &str, 230 target: &str,
230 ) { 231 ) {
231 let (range, before) = extract_range(before); 232 let (range, before) = extract_range(before);
232 let (db, _source_root, file_id) = MockDatabase::with_single_file(&before); 233 let (db, file_id) = TestDB::with_single_file(&before);
233 let frange = FileRange { file_id, range }; 234 let frange = FileRange { file_id, range };
234 let assist = 235 let assist =
235 AssistCtx::with_ctx(&db, frange, true, assist).expect("code action is not applicable"); 236 AssistCtx::with_ctx(&db, frange, true, assist).expect("code action is not applicable");
@@ -243,11 +244,11 @@ mod helpers {
243 } 244 }
244 245
245 pub(crate) fn check_assist_not_applicable( 246 pub(crate) fn check_assist_not_applicable(
246 assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>, 247 assist: fn(AssistCtx<TestDB>) -> Option<Assist>,
247 before: &str, 248 before: &str,
248 ) { 249 ) {
249 let (before_cursor_pos, before) = extract_offset(before); 250 let (before_cursor_pos, before) = extract_offset(before);
250 let (db, _source_root, file_id) = MockDatabase::with_single_file(&before); 251 let (db, file_id) = TestDB::with_single_file(&before);
251 let frange = 252 let frange =
252 FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; 253 FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) };
253 let assist = AssistCtx::with_ctx(&db, frange, true, assist); 254 let assist = AssistCtx::with_ctx(&db, frange, true, assist);
@@ -255,11 +256,11 @@ mod helpers {
255 } 256 }
256 257
257 pub(crate) fn check_assist_range_not_applicable( 258 pub(crate) fn check_assist_range_not_applicable(
258 assist: fn(AssistCtx<MockDatabase>) -> Option<Assist>, 259 assist: fn(AssistCtx<TestDB>) -> Option<Assist>,
259 before: &str, 260 before: &str,
260 ) { 261 ) {
261 let (range, before) = extract_range(before); 262 let (range, before) = extract_range(before);
262 let (db, _source_root, file_id) = MockDatabase::with_single_file(&before); 263 let (db, file_id) = TestDB::with_single_file(&before);
263 let frange = FileRange { file_id, range }; 264 let frange = FileRange { file_id, range };
264 let assist = AssistCtx::with_ctx(&db, frange, true, assist); 265 let assist = AssistCtx::with_ctx(&db, frange, true, assist);
265 assert!(assist.is_none()); 266 assert!(assist.is_none());
@@ -268,16 +269,17 @@ mod helpers {
268 269
269#[cfg(test)] 270#[cfg(test)]
270mod tests { 271mod tests {
271 use hir::mock::MockDatabase; 272 use ra_db::{fixture::WithFixture, FileRange};
272 use ra_db::FileRange;
273 use ra_syntax::TextRange; 273 use ra_syntax::TextRange;
274 use test_utils::{extract_offset, extract_range}; 274 use test_utils::{extract_offset, extract_range};
275 275
276 use crate::test_db::TestDB;
277
276 #[test] 278 #[test]
277 fn assist_order_field_struct() { 279 fn assist_order_field_struct() {
278 let before = "struct Foo { <|>bar: u32 }"; 280 let before = "struct Foo { <|>bar: u32 }";
279 let (before_cursor_pos, before) = extract_offset(before); 281 let (before_cursor_pos, before) = extract_offset(before);
280 let (db, _source_root, file_id) = MockDatabase::with_single_file(&before); 282 let (db, file_id) = TestDB::with_single_file(&before);
281 let frange = 283 let frange =
282 FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; 284 FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) };
283 let assists = super::assists(&db, frange); 285 let assists = super::assists(&db, frange);
@@ -298,7 +300,7 @@ mod tests {
298 } 300 }
299 }"; 301 }";
300 let (range, before) = extract_range(before); 302 let (range, before) = extract_range(before);
301 let (db, _source_root, file_id) = MockDatabase::with_single_file(&before); 303 let (db, file_id) = TestDB::with_single_file(&before);
302 let frange = FileRange { file_id, range }; 304 let frange = FileRange { file_id, range };
303 let assists = super::assists(&db, frange); 305 let assists = super::assists(&db, frange);
304 let mut assists = assists.iter(); 306 let mut assists = assists.iter();