aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-10 21:10:59 +0100
committerGitHub <[email protected]>2021-05-10 21:10:59 +0100
commit77f0c92fd8311bccc001ddaf9eb72662d35e9836 (patch)
treebdc532c6318c3378de63649ae65a4f420aa7db2a
parentc7edc38cd0c55ea85356112608bbb928856f6865 (diff)
parent59c2efe4b6de41424a5bfd2a0cb59a43ffc11042 (diff)
Merge #8794
8794: Give MergeBehaviour variants better names r=Veykril a=Veykril I never really liked the variant names I gave this enum from the beginning and then I found out about rustfmt's `imports_granularity` config: > imports_granularity > > How imports should be grouped into use statements. Imports will be merged or split to the configured level of granularity. > > Default value: Preserve > Possible values: Preserve, Crate, Module, Item > Stable: No I personally prefer using `crate` over `full` and `module` over last, they seem more descriptive. Keeping these similar between tooling also seems like a good plus point to me. We might even wanna take over the entire enum at some point if we have a `format/cleanup imports` assists in the future which would probably want to also have the `preserve` and `item` options. Co-authored-by: Lukas Wirth <[email protected]>
-rw-r--r--crates/ide_assists/src/handlers/merge_imports.rs4
-rw-r--r--crates/ide_assists/src/tests.rs2
-rw-r--r--crates/ide_completion/src/test_utils.rs2
-rw-r--r--crates/ide_db/src/helpers/insert_use/tests.rs84
-rw-r--r--crates/ide_db/src/helpers/merge_imports.rs14
-rw-r--r--crates/rust-analyzer/src/config.rs20
-rw-r--r--crates/rust-analyzer/src/integrated_benchmarks.rs4
-rw-r--r--docs/user/generated_config.adoc2
-rw-r--r--editors/code/package.json12
9 files changed, 77 insertions, 67 deletions
diff --git a/crates/ide_assists/src/handlers/merge_imports.rs b/crates/ide_assists/src/handlers/merge_imports.rs
index add7b8e37..3cd090737 100644
--- a/crates/ide_assists/src/handlers/merge_imports.rs
+++ b/crates/ide_assists/src/handlers/merge_imports.rs
@@ -27,14 +27,14 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()
27 if let Some(use_item) = tree.syntax().parent().and_then(ast::Use::cast) { 27 if let Some(use_item) = tree.syntax().parent().and_then(ast::Use::cast) {
28 let (merged, to_remove) = 28 let (merged, to_remove) =
29 next_prev().filter_map(|dir| neighbor(&use_item, dir)).find_map(|use_item2| { 29 next_prev().filter_map(|dir| neighbor(&use_item, dir)).find_map(|use_item2| {
30 try_merge_imports(&use_item, &use_item2, MergeBehavior::Full).zip(Some(use_item2)) 30 try_merge_imports(&use_item, &use_item2, MergeBehavior::Crate).zip(Some(use_item2))
31 })?; 31 })?;
32 32
33 imports = Some((use_item, merged, to_remove)); 33 imports = Some((use_item, merged, to_remove));
34 } else { 34 } else {
35 let (merged, to_remove) = 35 let (merged, to_remove) =
36 next_prev().filter_map(|dir| neighbor(&tree, dir)).find_map(|use_tree| { 36 next_prev().filter_map(|dir| neighbor(&tree, dir)).find_map(|use_tree| {
37 try_merge_trees(&tree, &use_tree, MergeBehavior::Full).zip(Some(use_tree)) 37 try_merge_trees(&tree, &use_tree, MergeBehavior::Crate).zip(Some(use_tree))
38 })?; 38 })?;
39 39
40 uses = Some((tree.clone(), merged, to_remove)) 40 uses = Some((tree.clone(), merged, to_remove))
diff --git a/crates/ide_assists/src/tests.rs b/crates/ide_assists/src/tests.rs
index 9c2847998..0d3969c36 100644
--- a/crates/ide_assists/src/tests.rs
+++ b/crates/ide_assists/src/tests.rs
@@ -21,7 +21,7 @@ pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig {
21 snippet_cap: SnippetCap::new(true), 21 snippet_cap: SnippetCap::new(true),
22 allowed: None, 22 allowed: None,
23 insert_use: InsertUseConfig { 23 insert_use: InsertUseConfig {
24 merge: Some(MergeBehavior::Full), 24 merge: Some(MergeBehavior::Crate),
25 prefix_kind: hir::PrefixKind::Plain, 25 prefix_kind: hir::PrefixKind::Plain,
26 group: true, 26 group: true,
27 }, 27 },
diff --git a/crates/ide_completion/src/test_utils.rs b/crates/ide_completion/src/test_utils.rs
index c9857ec5f..939fb2d47 100644
--- a/crates/ide_completion/src/test_utils.rs
+++ b/crates/ide_completion/src/test_utils.rs
@@ -20,7 +20,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
20 add_call_argument_snippets: true, 20 add_call_argument_snippets: true,
21 snippet_cap: SnippetCap::new(true), 21 snippet_cap: SnippetCap::new(true),
22 insert_use: InsertUseConfig { 22 insert_use: InsertUseConfig {
23 merge: Some(MergeBehavior::Full), 23 merge: Some(MergeBehavior::Crate),
24 prefix_kind: PrefixKind::Plain, 24 prefix_kind: PrefixKind::Plain,
25 group: true, 25 group: true,
26 }, 26 },
diff --git a/crates/ide_db/src/helpers/insert_use/tests.rs b/crates/ide_db/src/helpers/insert_use/tests.rs
index 048c213e2..248227d29 100644
--- a/crates/ide_db/src/helpers/insert_use/tests.rs
+++ b/crates/ide_db/src/helpers/insert_use/tests.rs
@@ -44,7 +44,7 @@ fn insert_not_group_empty() {
44 44
45#[test] 45#[test]
46fn insert_existing() { 46fn insert_existing() {
47 check_full("std::fs", "use std::fs;", "use std::fs;") 47 check_crate("std::fs", "use std::fs;", "use std::fs;")
48} 48}
49 49
50#[test] 50#[test]
@@ -249,7 +249,7 @@ use self::fmt;",
249 249
250#[test] 250#[test]
251fn insert_no_imports() { 251fn insert_no_imports() {
252 check_full( 252 check_crate(
253 "foo::bar", 253 "foo::bar",
254 "fn main() {}", 254 "fn main() {}",
255 r"use foo::bar; 255 r"use foo::bar;
@@ -263,7 +263,7 @@ fn insert_empty_file() {
263 cov_mark::check!(insert_group_empty_file); 263 cov_mark::check!(insert_group_empty_file);
264 // empty files will get two trailing newlines 264 // empty files will get two trailing newlines
265 // this is due to the test case insert_no_imports above 265 // this is due to the test case insert_no_imports above
266 check_full( 266 check_crate(
267 "foo::bar", 267 "foo::bar",
268 "", 268 "",
269 r"use foo::bar; 269 r"use foo::bar;
@@ -290,7 +290,7 @@ fn insert_empty_module() {
290#[test] 290#[test]
291fn insert_after_inner_attr() { 291fn insert_after_inner_attr() {
292 cov_mark::check!(insert_group_empty_inner_attr); 292 cov_mark::check!(insert_group_empty_inner_attr);
293 check_full( 293 check_crate(
294 "foo::bar", 294 "foo::bar",
295 r"#![allow(unused_imports)]", 295 r"#![allow(unused_imports)]",
296 r"#![allow(unused_imports)] 296 r"#![allow(unused_imports)]
@@ -301,7 +301,7 @@ use foo::bar;",
301 301
302#[test] 302#[test]
303fn insert_after_inner_attr2() { 303fn insert_after_inner_attr2() {
304 check_full( 304 check_crate(
305 "foo::bar", 305 "foo::bar",
306 r"#![allow(unused_imports)] 306 r"#![allow(unused_imports)]
307 307
@@ -371,12 +371,12 @@ fn main() {}"#,
371 371
372#[test] 372#[test]
373fn merge_groups() { 373fn merge_groups() {
374 check_last("std::io", r"use std::fmt;", r"use std::{fmt, io};") 374 check_module("std::io", r"use std::fmt;", r"use std::{fmt, io};")
375} 375}
376 376
377#[test] 377#[test]
378fn merge_groups_last() { 378fn merge_groups_last() {
379 check_last( 379 check_module(
380 "std::io", 380 "std::io",
381 r"use std::fmt::{Result, Display};", 381 r"use std::fmt::{Result, Display};",
382 r"use std::fmt::{Result, Display}; 382 r"use std::fmt::{Result, Display};
@@ -386,12 +386,12 @@ use std::io;",
386 386
387#[test] 387#[test]
388fn merge_last_into_self() { 388fn merge_last_into_self() {
389 check_last("foo::bar::baz", r"use foo::bar;", r"use foo::bar::{self, baz};"); 389 check_module("foo::bar::baz", r"use foo::bar;", r"use foo::bar::{self, baz};");
390} 390}
391 391
392#[test] 392#[test]
393fn merge_groups_full() { 393fn merge_groups_full() {
394 check_full( 394 check_crate(
395 "std::io", 395 "std::io",
396 r"use std::fmt::{Result, Display};", 396 r"use std::fmt::{Result, Display};",
397 r"use std::{fmt::{Result, Display}, io};", 397 r"use std::{fmt::{Result, Display}, io};",
@@ -400,17 +400,21 @@ fn merge_groups_full() {
400 400
401#[test] 401#[test]
402fn merge_groups_long_full() { 402fn merge_groups_long_full() {
403 check_full("std::foo::bar::Baz", r"use std::foo::bar::Qux;", r"use std::foo::bar::{Baz, Qux};") 403 check_crate("std::foo::bar::Baz", r"use std::foo::bar::Qux;", r"use std::foo::bar::{Baz, Qux};")
404} 404}
405 405
406#[test] 406#[test]
407fn merge_groups_long_last() { 407fn merge_groups_long_last() {
408 check_last("std::foo::bar::Baz", r"use std::foo::bar::Qux;", r"use std::foo::bar::{Baz, Qux};") 408 check_module(
409 "std::foo::bar::Baz",
410 r"use std::foo::bar::Qux;",
411 r"use std::foo::bar::{Baz, Qux};",
412 )
409} 413}
410 414
411#[test] 415#[test]
412fn merge_groups_long_full_list() { 416fn merge_groups_long_full_list() {
413 check_full( 417 check_crate(
414 "std::foo::bar::Baz", 418 "std::foo::bar::Baz",
415 r"use std::foo::bar::{Qux, Quux};", 419 r"use std::foo::bar::{Qux, Quux};",
416 r"use std::foo::bar::{Baz, Quux, Qux};", 420 r"use std::foo::bar::{Baz, Quux, Qux};",
@@ -419,7 +423,7 @@ fn merge_groups_long_full_list() {
419 423
420#[test] 424#[test]
421fn merge_groups_long_last_list() { 425fn merge_groups_long_last_list() {
422 check_last( 426 check_module(
423 "std::foo::bar::Baz", 427 "std::foo::bar::Baz",
424 r"use std::foo::bar::{Qux, Quux};", 428 r"use std::foo::bar::{Qux, Quux};",
425 r"use std::foo::bar::{Baz, Quux, Qux};", 429 r"use std::foo::bar::{Baz, Quux, Qux};",
@@ -428,7 +432,7 @@ fn merge_groups_long_last_list() {
428 432
429#[test] 433#[test]
430fn merge_groups_long_full_nested() { 434fn merge_groups_long_full_nested() {
431 check_full( 435 check_crate(
432 "std::foo::bar::Baz", 436 "std::foo::bar::Baz",
433 r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};", 437 r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
434 r"use std::foo::bar::{Baz, Qux, quux::{Fez, Fizz}};", 438 r"use std::foo::bar::{Baz, Qux, quux::{Fez, Fizz}};",
@@ -437,7 +441,7 @@ fn merge_groups_long_full_nested() {
437 441
438#[test] 442#[test]
439fn merge_groups_long_last_nested() { 443fn merge_groups_long_last_nested() {
440 check_last( 444 check_module(
441 "std::foo::bar::Baz", 445 "std::foo::bar::Baz",
442 r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};", 446 r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
443 r"use std::foo::bar::Baz; 447 r"use std::foo::bar::Baz;
@@ -447,7 +451,7 @@ use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
447 451
448#[test] 452#[test]
449fn merge_groups_full_nested_deep() { 453fn merge_groups_full_nested_deep() {
450 check_full( 454 check_crate(
451 "std::foo::bar::quux::Baz", 455 "std::foo::bar::quux::Baz",
452 r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};", 456 r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
453 r"use std::foo::bar::{Qux, quux::{Baz, Fez, Fizz}};", 457 r"use std::foo::bar::{Qux, quux::{Baz, Fez, Fizz}};",
@@ -456,7 +460,7 @@ fn merge_groups_full_nested_deep() {
456 460
457#[test] 461#[test]
458fn merge_groups_full_nested_long() { 462fn merge_groups_full_nested_long() {
459 check_full( 463 check_crate(
460 "std::foo::bar::Baz", 464 "std::foo::bar::Baz",
461 r"use std::{foo::bar::Qux};", 465 r"use std::{foo::bar::Qux};",
462 r"use std::{foo::bar::{Baz, Qux}};", 466 r"use std::{foo::bar::{Baz, Qux}};",
@@ -465,7 +469,7 @@ fn merge_groups_full_nested_long() {
465 469
466#[test] 470#[test]
467fn merge_groups_last_nested_long() { 471fn merge_groups_last_nested_long() {
468 check_full( 472 check_crate(
469 "std::foo::bar::Baz", 473 "std::foo::bar::Baz",
470 r"use std::{foo::bar::Qux};", 474 r"use std::{foo::bar::Qux};",
471 r"use std::{foo::bar::{Baz, Qux}};", 475 r"use std::{foo::bar::{Baz, Qux}};",
@@ -474,7 +478,7 @@ fn merge_groups_last_nested_long() {
474 478
475#[test] 479#[test]
476fn merge_groups_skip_pub() { 480fn merge_groups_skip_pub() {
477 check_full( 481 check_crate(
478 "std::io", 482 "std::io",
479 r"pub use std::fmt::{Result, Display};", 483 r"pub use std::fmt::{Result, Display};",
480 r"pub use std::fmt::{Result, Display}; 484 r"pub use std::fmt::{Result, Display};
@@ -484,7 +488,7 @@ use std::io;",
484 488
485#[test] 489#[test]
486fn merge_groups_skip_pub_crate() { 490fn merge_groups_skip_pub_crate() {
487 check_full( 491 check_crate(
488 "std::io", 492 "std::io",
489 r"pub(crate) use std::fmt::{Result, Display};", 493 r"pub(crate) use std::fmt::{Result, Display};",
490 r"pub(crate) use std::fmt::{Result, Display}; 494 r"pub(crate) use std::fmt::{Result, Display};
@@ -494,7 +498,7 @@ use std::io;",
494 498
495#[test] 499#[test]
496fn merge_groups_skip_attributed() { 500fn merge_groups_skip_attributed() {
497 check_full( 501 check_crate(
498 "std::io", 502 "std::io",
499 r#" 503 r#"
500#[cfg(feature = "gated")] use std::fmt::{Result, Display}; 504#[cfg(feature = "gated")] use std::fmt::{Result, Display};
@@ -509,7 +513,7 @@ use std::io;
509#[test] 513#[test]
510#[ignore] // FIXME: Support this 514#[ignore] // FIXME: Support this
511fn split_out_merge() { 515fn split_out_merge() {
512 check_last( 516 check_module(
513 "std::fmt::Result", 517 "std::fmt::Result",
514 r"use std::{fmt, io};", 518 r"use std::{fmt, io};",
515 r"use std::fmt::{self, Result}; 519 r"use std::fmt::{self, Result};
@@ -519,29 +523,33 @@ use std::io;",
519 523
520#[test] 524#[test]
521fn merge_into_module_import() { 525fn merge_into_module_import() {
522 check_full("std::fmt::Result", r"use std::{fmt, io};", r"use std::{fmt::{self, Result}, io};") 526 check_crate("std::fmt::Result", r"use std::{fmt, io};", r"use std::{fmt::{self, Result}, io};")
523} 527}
524 528
525#[test] 529#[test]
526fn merge_groups_self() { 530fn merge_groups_self() {
527 check_full("std::fmt::Debug", r"use std::fmt;", r"use std::fmt::{self, Debug};") 531 check_crate("std::fmt::Debug", r"use std::fmt;", r"use std::fmt::{self, Debug};")
528} 532}
529 533
530#[test] 534#[test]
531fn merge_mod_into_glob() { 535fn merge_mod_into_glob() {
532 check_full("token::TokenKind", r"use token::TokenKind::*;", r"use token::TokenKind::{*, self};") 536 check_crate(
537 "token::TokenKind",
538 r"use token::TokenKind::*;",
539 r"use token::TokenKind::{*, self};",
540 )
533 // FIXME: have it emit `use token::TokenKind::{self, *}`? 541 // FIXME: have it emit `use token::TokenKind::{self, *}`?
534} 542}
535 543
536#[test] 544#[test]
537fn merge_self_glob() { 545fn merge_self_glob() {
538 check_full("self", r"use self::*;", r"use self::{*, self};") 546 check_crate("self", r"use self::*;", r"use self::{*, self};")
539 // FIXME: have it emit `use {self, *}`? 547 // FIXME: have it emit `use {self, *}`?
540} 548}
541 549
542#[test] 550#[test]
543fn merge_glob_nested() { 551fn merge_glob_nested() {
544 check_full( 552 check_crate(
545 "foo::bar::quux::Fez", 553 "foo::bar::quux::Fez",
546 r"use foo::bar::{Baz, quux::*};", 554 r"use foo::bar::{Baz, quux::*};",
547 r"use foo::bar::{Baz, quux::{self::*, Fez}};", 555 r"use foo::bar::{Baz, quux::{self::*, Fez}};",
@@ -550,7 +558,7 @@ fn merge_glob_nested() {
550 558
551#[test] 559#[test]
552fn merge_nested_considers_first_segments() { 560fn merge_nested_considers_first_segments() {
553 check_full( 561 check_crate(
554 "hir_ty::display::write_bounds_like_dyn_trait", 562 "hir_ty::display::write_bounds_like_dyn_trait",
555 r"use hir_ty::{autoderef, display::{HirDisplayError, HirFormatter}, method_resolution};", 563 r"use hir_ty::{autoderef, display::{HirDisplayError, HirFormatter}, method_resolution};",
556 r"use hir_ty::{autoderef, display::{HirDisplayError, HirFormatter, write_bounds_like_dyn_trait}, method_resolution};", 564 r"use hir_ty::{autoderef, display::{HirDisplayError, HirFormatter, write_bounds_like_dyn_trait}, method_resolution};",
@@ -559,7 +567,7 @@ fn merge_nested_considers_first_segments() {
559 567
560#[test] 568#[test]
561fn skip_merge_last_too_long() { 569fn skip_merge_last_too_long() {
562 check_last( 570 check_module(
563 "foo::bar", 571 "foo::bar",
564 r"use foo::bar::baz::Qux;", 572 r"use foo::bar::baz::Qux;",
565 r"use foo::bar; 573 r"use foo::bar;
@@ -569,7 +577,7 @@ use foo::bar::baz::Qux;",
569 577
570#[test] 578#[test]
571fn skip_merge_last_too_long2() { 579fn skip_merge_last_too_long2() {
572 check_last( 580 check_module(
573 "foo::bar::baz::Qux", 581 "foo::bar::baz::Qux",
574 r"use foo::bar;", 582 r"use foo::bar;",
575 r"use foo::bar; 583 r"use foo::bar;
@@ -592,7 +600,7 @@ fn merge_last_fail() {
592 check_merge_only_fail( 600 check_merge_only_fail(
593 r"use foo::bar::{baz::{Qux, Fez}};", 601 r"use foo::bar::{baz::{Qux, Fez}};",
594 r"use foo::bar::{baaz::{Quux, Feez}};", 602 r"use foo::bar::{baaz::{Quux, Feez}};",
595 MergeBehavior::Last, 603 MergeBehavior::Module,
596 ); 604 );
597} 605}
598 606
@@ -601,7 +609,7 @@ fn merge_last_fail1() {
601 check_merge_only_fail( 609 check_merge_only_fail(
602 r"use foo::bar::{baz::{Qux, Fez}};", 610 r"use foo::bar::{baz::{Qux, Fez}};",
603 r"use foo::bar::baaz::{Quux, Feez};", 611 r"use foo::bar::baaz::{Quux, Feez};",
604 MergeBehavior::Last, 612 MergeBehavior::Module,
605 ); 613 );
606} 614}
607 615
@@ -610,7 +618,7 @@ fn merge_last_fail2() {
610 check_merge_only_fail( 618 check_merge_only_fail(
611 r"use foo::bar::baz::{Qux, Fez};", 619 r"use foo::bar::baz::{Qux, Fez};",
612 r"use foo::bar::{baaz::{Quux, Feez}};", 620 r"use foo::bar::{baaz::{Quux, Feez}};",
613 MergeBehavior::Last, 621 MergeBehavior::Module,
614 ); 622 );
615} 623}
616 624
@@ -619,7 +627,7 @@ fn merge_last_fail3() {
619 check_merge_only_fail( 627 check_merge_only_fail(
620 r"use foo::bar::baz::{Qux, Fez};", 628 r"use foo::bar::baz::{Qux, Fez};",
621 r"use foo::bar::baaz::{Quux, Feez};", 629 r"use foo::bar::baaz::{Quux, Feez};",
622 MergeBehavior::Last, 630 MergeBehavior::Module,
623 ); 631 );
624} 632}
625 633
@@ -648,12 +656,12 @@ fn check(
648 assert_eq_text!(ra_fixture_after, &result); 656 assert_eq_text!(ra_fixture_after, &result);
649} 657}
650 658
651fn check_full(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) { 659fn check_crate(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
652 check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehavior::Full), false, true) 660 check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehavior::Crate), false, true)
653} 661}
654 662
655fn check_last(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) { 663fn check_module(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
656 check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehavior::Last), false, true) 664 check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehavior::Module), false, true)
657} 665}
658 666
659fn check_none(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) { 667fn check_none(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
diff --git a/crates/ide_db/src/helpers/merge_imports.rs b/crates/ide_db/src/helpers/merge_imports.rs
index 148297279..af2a51a4d 100644
--- a/crates/ide_db/src/helpers/merge_imports.rs
+++ b/crates/ide_db/src/helpers/merge_imports.rs
@@ -9,19 +9,19 @@ use syntax::ast::{
9/// What type of merges are allowed. 9/// What type of merges are allowed.
10#[derive(Copy, Clone, Debug, PartialEq, Eq)] 10#[derive(Copy, Clone, Debug, PartialEq, Eq)]
11pub enum MergeBehavior { 11pub enum MergeBehavior {
12 /// Merge everything together creating deeply nested imports. 12 /// Merge imports from the same crate into a single use statement.
13 Full, 13 Crate,
14 /// Only merge the last import level, doesn't allow import nesting. 14 /// Merge imports from the same module into a single use statement.
15 Last, 15 Module,
16} 16}
17 17
18impl MergeBehavior { 18impl MergeBehavior {
19 #[inline] 19 #[inline]
20 fn is_tree_allowed(&self, tree: &ast::UseTree) -> bool { 20 fn is_tree_allowed(&self, tree: &ast::UseTree) -> bool {
21 match self { 21 match self {
22 MergeBehavior::Full => true, 22 MergeBehavior::Crate => true,
23 // only simple single segment paths are allowed 23 // only simple single segment paths are allowed
24 MergeBehavior::Last => { 24 MergeBehavior::Module => {
25 tree.use_tree_list().is_none() && tree.path().map(path_len) <= Some(1) 25 tree.use_tree_list().is_none() && tree.path().map(path_len) <= Some(1)
26 } 26 }
27 } 27 }
@@ -153,7 +153,7 @@ fn recursive_merge(
153 } 153 }
154 } 154 }
155 Err(_) 155 Err(_)
156 if merge == MergeBehavior::Last 156 if merge == MergeBehavior::Module
157 && use_trees.len() > 0 157 && use_trees.len() > 0
158 && rhs_t.use_tree_list().is_some() => 158 && rhs_t.use_tree_list().is_some() =>
159 { 159 {
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 8879a9161..d83670bda 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -36,7 +36,7 @@ config_data! {
36 struct ConfigData { 36 struct ConfigData {
37 /// The strategy to use when inserting new imports or merging imports. 37 /// The strategy to use when inserting new imports or merging imports.
38 assist_importMergeBehavior | 38 assist_importMergeBehavior |
39 assist_importMergeBehaviour: MergeBehaviorDef = "\"full\"", 39 assist_importMergeBehaviour: MergeBehaviorDef = "\"crate\"",
40 /// The path structure for newly inserted paths to use. 40 /// The path structure for newly inserted paths to use.
41 assist_importPrefix: ImportPrefixDef = "\"plain\"", 41 assist_importPrefix: ImportPrefixDef = "\"plain\"",
42 /// Group inserted imports by the [following order](https://rust-analyzer.github.io/manual.html#auto-import). Groups are separated by newlines. 42 /// Group inserted imports by the [following order](https://rust-analyzer.github.io/manual.html#auto-import). Groups are separated by newlines.
@@ -604,8 +604,8 @@ impl Config {
604 InsertUseConfig { 604 InsertUseConfig {
605 merge: match self.data.assist_importMergeBehavior { 605 merge: match self.data.assist_importMergeBehavior {
606 MergeBehaviorDef::None => None, 606 MergeBehaviorDef::None => None,
607 MergeBehaviorDef::Full => Some(MergeBehavior::Full), 607 MergeBehaviorDef::Crate => Some(MergeBehavior::Crate),
608 MergeBehaviorDef::Last => Some(MergeBehavior::Last), 608 MergeBehaviorDef::Module => Some(MergeBehavior::Module),
609 }, 609 },
610 prefix_kind: match self.data.assist_importPrefix { 610 prefix_kind: match self.data.assist_importPrefix {
611 ImportPrefixDef::Plain => PrefixKind::Plain, 611 ImportPrefixDef::Plain => PrefixKind::Plain,
@@ -709,8 +709,10 @@ enum ManifestOrProjectJson {
709#[serde(rename_all = "snake_case")] 709#[serde(rename_all = "snake_case")]
710enum MergeBehaviorDef { 710enum MergeBehaviorDef {
711 None, 711 None,
712 Full, 712 #[serde(alias = "full")]
713 Last, 713 Crate,
714 #[serde(alias = "last")]
715 Module,
714} 716}
715 717
716#[derive(Deserialize, Debug, Clone)] 718#[derive(Deserialize, Debug, Clone)]
@@ -867,11 +869,11 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
867 }, 869 },
868 "MergeBehaviorDef" => set! { 870 "MergeBehaviorDef" => set! {
869 "type": "string", 871 "type": "string",
870 "enum": ["none", "full", "last"], 872 "enum": ["none", "crate", "module"],
871 "enumDescriptions": [ 873 "enumDescriptions": [
872 "No merging", 874 "Do not merge imports at all.",
873 "Merge all layers of the import trees", 875 "Merge imports from the same crate into a single `use` statement.",
874 "Only merge the last layer of the import trees" 876 "Merge imports from the same module into a single `use` statement."
875 ], 877 ],
876 }, 878 },
877 "ImportPrefixDef" => set! { 879 "ImportPrefixDef" => set! {
diff --git a/crates/rust-analyzer/src/integrated_benchmarks.rs b/crates/rust-analyzer/src/integrated_benchmarks.rs
index 3dcbe397a..56de9681c 100644
--- a/crates/rust-analyzer/src/integrated_benchmarks.rs
+++ b/crates/rust-analyzer/src/integrated_benchmarks.rs
@@ -133,7 +133,7 @@ fn integrated_completion_benchmark() {
133 add_call_argument_snippets: true, 133 add_call_argument_snippets: true,
134 snippet_cap: SnippetCap::new(true), 134 snippet_cap: SnippetCap::new(true),
135 insert_use: InsertUseConfig { 135 insert_use: InsertUseConfig {
136 merge: Some(MergeBehavior::Full), 136 merge: Some(MergeBehavior::Crate),
137 prefix_kind: hir::PrefixKind::ByCrate, 137 prefix_kind: hir::PrefixKind::ByCrate,
138 group: true, 138 group: true,
139 }, 139 },
@@ -166,7 +166,7 @@ fn integrated_completion_benchmark() {
166 add_call_argument_snippets: true, 166 add_call_argument_snippets: true,
167 snippet_cap: SnippetCap::new(true), 167 snippet_cap: SnippetCap::new(true),
168 insert_use: InsertUseConfig { 168 insert_use: InsertUseConfig {
169 merge: Some(MergeBehavior::Full), 169 merge: Some(MergeBehavior::Crate),
170 prefix_kind: hir::PrefixKind::ByCrate, 170 prefix_kind: hir::PrefixKind::ByCrate,
171 group: true, 171 group: true,
172 }, 172 },
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index e28423e99..f70558200 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -1,4 +1,4 @@
1[[rust-analyzer.assist.importMergeBehavior]]rust-analyzer.assist.importMergeBehavior (default: `"full"`):: 1[[rust-analyzer.assist.importMergeBehavior]]rust-analyzer.assist.importMergeBehavior (default: `"crate"`)::
2+ 2+
3-- 3--
4The strategy to use when inserting new imports or merging imports. 4The strategy to use when inserting new imports or merging imports.
diff --git a/editors/code/package.json b/editors/code/package.json
index 0cc265aa4..f35d30898 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -382,17 +382,17 @@
382 "$generated-start": false, 382 "$generated-start": false,
383 "rust-analyzer.assist.importMergeBehavior": { 383 "rust-analyzer.assist.importMergeBehavior": {
384 "markdownDescription": "The strategy to use when inserting new imports or merging imports.", 384 "markdownDescription": "The strategy to use when inserting new imports or merging imports.",
385 "default": "full", 385 "default": "crate",
386 "type": "string", 386 "type": "string",
387 "enum": [ 387 "enum": [
388 "none", 388 "none",
389 "full", 389 "crate",
390 "last" 390 "module"
391 ], 391 ],
392 "enumDescriptions": [ 392 "enumDescriptions": [
393 "No merging", 393 "Do not merge imports at all.",
394 "Merge all layers of the import trees", 394 "Merge imports from the same crate into a single `use` statement.",
395 "Only merge the last layer of the import trees" 395 "Merge imports from the same module into a single `use` statement."
396 ] 396 ]
397 }, 397 },
398 "rust-analyzer.assist.importPrefix": { 398 "rust-analyzer.assist.importPrefix": {