aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers/fix_visibility.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/handlers/fix_visibility.rs')
-rw-r--r--crates/ra_assists/src/handlers/fix_visibility.rs157
1 files changed, 80 insertions, 77 deletions
diff --git a/crates/ra_assists/src/handlers/fix_visibility.rs b/crates/ra_assists/src/handlers/fix_visibility.rs
index 531b3560f..54601d1f3 100644
--- a/crates/ra_assists/src/handlers/fix_visibility.rs
+++ b/crates/ra_assists/src/handlers/fix_visibility.rs
@@ -255,15 +255,14 @@ mod tests {
255 check_assist( 255 check_assist(
256 fix_visibility, 256 fix_visibility,
257 r" 257 r"
258 //- /main.rs 258//- /main.rs
259 mod foo; 259mod foo;
260 fn main() { foo::Foo<|> } 260fn main() { foo::Foo<|> }
261 261
262 //- /foo.rs 262//- /foo.rs
263 struct Foo; 263struct Foo;
264 ", 264",
265 r"$0pub(crate) struct Foo; 265 r"$0pub(crate) struct Foo;
266
267", 266",
268 ); 267 );
269 } 268 }
@@ -279,14 +278,14 @@ mod tests {
279 ); 278 );
280 check_assist( 279 check_assist(
281 fix_visibility, 280 fix_visibility,
282 r"//- /lib.rs 281 r"
283 mod foo; 282//- /lib.rs
284 fn main() { foo::Foo { <|>bar: () }; } 283mod foo;
285 //- /foo.rs 284fn main() { foo::Foo { <|>bar: () }; }
286 pub struct Foo { bar: () } 285//- /foo.rs
287 ", 286pub struct Foo { bar: () }
287",
288 r"pub struct Foo { $0pub(crate) bar: () } 288 r"pub struct Foo { $0pub(crate) bar: () }
289
290", 289",
291 ); 290 );
292 check_assist_not_applicable( 291 check_assist_not_applicable(
@@ -296,12 +295,13 @@ mod tests {
296 ); 295 );
297 check_assist_not_applicable( 296 check_assist_not_applicable(
298 fix_visibility, 297 fix_visibility,
299 r"//- /lib.rs 298 r"
300 mod foo; 299//- /lib.rs
301 fn main() { foo::Foo { <|>bar: () }; } 300mod foo;
302 //- /foo.rs 301fn main() { foo::Foo { <|>bar: () }; }
303 pub struct Foo { pub bar: () } 302//- /foo.rs
304 ", 303pub struct Foo { pub bar: () }
304",
305 ); 305 );
306 } 306 }
307 307
@@ -316,14 +316,14 @@ mod tests {
316 ); 316 );
317 check_assist( 317 check_assist(
318 fix_visibility, 318 fix_visibility,
319 r"//- /lib.rs 319 r"
320 mod foo; 320//- /lib.rs
321 fn main() { foo::Foo::Bar { <|>bar: () }; } 321mod foo;
322 //- /foo.rs 322fn main() { foo::Foo::Bar { <|>bar: () }; }
323 pub enum Foo { Bar { bar: () } } 323//- /foo.rs
324 ", 324pub enum Foo { Bar { bar: () } }
325",
325 r"pub enum Foo { Bar { $0pub(crate) bar: () } } 326 r"pub enum Foo { Bar { $0pub(crate) bar: () } }
326
327", 327",
328 ); 328 );
329 check_assist_not_applicable( 329 check_assist_not_applicable(
@@ -333,12 +333,13 @@ mod tests {
333 ); 333 );
334 check_assist_not_applicable( 334 check_assist_not_applicable(
335 fix_visibility, 335 fix_visibility,
336 r"//- /lib.rs 336 r"
337 mod foo; 337//- /lib.rs
338 fn main() { foo::Foo { <|>bar: () }; } 338mod foo;
339 //- /foo.rs 339fn main() { foo::Foo { <|>bar: () }; }
340 pub struct Foo { pub bar: () } 340//- /foo.rs
341 ", 341pub struct Foo { pub bar: () }
342",
342 ); 343 );
343 } 344 }
344 345
@@ -355,14 +356,14 @@ mod tests {
355 ); 356 );
356 check_assist( 357 check_assist(
357 fix_visibility, 358 fix_visibility,
358 r"//- /lib.rs 359 r"
359 mod foo; 360//- /lib.rs
360 fn main() { foo::Foo { <|>bar: () }; } 361mod foo;
361 //- /foo.rs 362fn main() { foo::Foo { <|>bar: () }; }
362 pub union Foo { bar: () } 363//- /foo.rs
363 ", 364pub union Foo { bar: () }
365",
364 r"pub union Foo { $0pub(crate) bar: () } 366 r"pub union Foo { $0pub(crate) bar: () }
365
366", 367",
367 ); 368 );
368 check_assist_not_applicable( 369 check_assist_not_applicable(
@@ -372,12 +373,13 @@ mod tests {
372 ); 373 );
373 check_assist_not_applicable( 374 check_assist_not_applicable(
374 fix_visibility, 375 fix_visibility,
375 r"//- /lib.rs 376 r"
376 mod foo; 377//- /lib.rs
377 fn main() { foo::Foo { <|>bar: () }; } 378mod foo;
378 //- /foo.rs 379fn main() { foo::Foo { <|>bar: () }; }
379 pub union Foo { pub bar: () } 380//- /foo.rs
380 ", 381pub union Foo { pub bar: () }
382",
381 ); 383 );
382 } 384 }
383 385
@@ -458,19 +460,18 @@ mod tests {
458 check_assist( 460 check_assist(
459 fix_visibility, 461 fix_visibility,
460 r" 462 r"
461 //- /main.rs 463//- /main.rs
462 mod foo; 464mod foo;
463 fn main() { foo::bar<|>::baz(); } 465fn main() { foo::bar<|>::baz(); }
464 466
465 //- /foo.rs 467//- /foo.rs
466 mod bar { 468mod bar {
467 pub fn baz() {} 469 pub fn baz() {}
468 } 470}
469 ", 471",
470 r"$0pub(crate) mod bar { 472 r"$0pub(crate) mod bar {
471 pub fn baz() {} 473 pub fn baz() {}
472} 474}
473
474", 475",
475 ); 476 );
476 477
@@ -486,17 +487,15 @@ mod tests {
486 check_assist( 487 check_assist(
487 fix_visibility, 488 fix_visibility,
488 r" 489 r"
489 //- /main.rs 490//- /main.rs
490 mod foo; 491mod foo;
491 fn main() { foo::bar<|>::baz(); } 492fn main() { foo::bar<|>::baz(); }
492 493
493 //- /foo.rs 494//- /foo.rs
494 mod bar; 495mod bar;
495 496//- /foo/bar.rs
496 //- /foo/bar.rs 497pub fn baz() {}
497 pub fn baz() {} 498",
498 }
499 ",
500 r"$0pub(crate) mod bar; 499 r"$0pub(crate) mod bar;
501", 500",
502 ); 501 );
@@ -506,14 +505,16 @@ mod tests {
506 fn fix_visibility_of_module_declaration_in_other_file() { 505 fn fix_visibility_of_module_declaration_in_other_file() {
507 check_assist( 506 check_assist(
508 fix_visibility, 507 fix_visibility,
509 r"//- /main.rs 508 r"
510 mod foo; 509//- /main.rs
511 fn main() { foo::bar<|>>::baz(); } 510mod foo;
511fn main() { foo::bar<|>>::baz(); }
512 512
513 //- /foo.rs 513//- /foo.rs
514 mod bar { 514mod bar {
515 pub fn baz() {} 515 pub fn baz() {}
516 }", 516}
517",
517 r"$0pub(crate) mod bar { 518 r"$0pub(crate) mod bar {
518 pub fn baz() {} 519 pub fn baz() {}
519} 520}
@@ -525,10 +526,12 @@ mod tests {
525 fn adds_pub_when_target_is_in_another_crate() { 526 fn adds_pub_when_target_is_in_another_crate() {
526 check_assist( 527 check_assist(
527 fix_visibility, 528 fix_visibility,
528 r"//- /main.rs crate:a deps:foo 529 r"
529 foo::Bar<|> 530//- /main.rs crate:a deps:foo
530 //- /lib.rs crate:foo 531foo::Bar<|>
531 struct Bar;", 532//- /lib.rs crate:foo
533struct Bar;
534",
532 r"$0pub struct Bar; 535 r"$0pub struct Bar;
533", 536",
534 ) 537 )