Skip to content

Commit 339f629

Browse files
committed
Reduce the default autoimport exclusion list
1 parent a02a1af commit 339f629

File tree

3 files changed

+90
-142
lines changed

3 files changed

+90
-142
lines changed

crates/ide-completion/src/tests/expression.rs

Lines changed: 83 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,19 +1430,22 @@ fn foo() {
14301430
}
14311431
"#,
14321432
expect![[r#"
1433-
me inherent() fn(&self)
1434-
sn box Box::new(expr)
1435-
sn call function(expr)
1436-
sn dbg dbg!(expr)
1437-
sn dbgr dbg!(&expr)
1438-
sn deref *expr
1439-
sn let let
1440-
sn letm let mut
1441-
sn match match expr {}
1442-
sn ref &expr
1443-
sn refm &mut expr
1444-
sn return return expr
1445-
sn unsafe unsafe {}
1433+
me bar() (as ExcludedTrait) fn(&self)
1434+
me baz() (as ExcludedTrait) fn(&self)
1435+
me foo() (as ExcludedTrait) fn(&self)
1436+
me inherent() fn(&self)
1437+
sn box Box::new(expr)
1438+
sn call function(expr)
1439+
sn dbg dbg!(expr)
1440+
sn dbgr dbg!(&expr)
1441+
sn deref *expr
1442+
sn let let
1443+
sn letm let mut
1444+
sn match match expr {}
1445+
sn ref &expr
1446+
sn refm &mut expr
1447+
sn return return expr
1448+
sn unsafe unsafe {}
14461449
"#]],
14471450
);
14481451
}
@@ -1468,18 +1471,18 @@ fn foo(v: &dyn ExcludedTrait) {
14681471
me bar() (as ExcludedTrait) fn(&self)
14691472
me baz() (as ExcludedTrait) fn(&self)
14701473
me foo() (as ExcludedTrait) fn(&self)
1471-
sn box Box::new(expr)
1472-
sn call function(expr)
1473-
sn dbg dbg!(expr)
1474+
sn box Box::new(expr)
1475+
sn call function(expr)
1476+
sn dbg dbg!(expr)
14741477
sn dbgr dbg!(&expr)
1475-
sn deref *expr
1476-
sn let let
1477-
sn letm let mut
1478-
sn match match expr {}
1479-
sn ref &expr
1480-
sn refm &mut expr
1478+
sn deref *expr
1479+
sn let let
1480+
sn letm let mut
1481+
sn match match expr {}
1482+
sn ref &expr
1483+
sn refm &mut expr
14811484
sn return return expr
1482-
sn unsafe unsafe {}
1485+
sn unsafe unsafe {}
14831486
"#]],
14841487
);
14851488
check_with_config(
@@ -1501,18 +1504,18 @@ fn foo(v: impl ExcludedTrait) {
15011504
me bar() (as ExcludedTrait) fn(&self)
15021505
me baz() (as ExcludedTrait) fn(&self)
15031506
me foo() (as ExcludedTrait) fn(&self)
1504-
sn box Box::new(expr)
1505-
sn call function(expr)
1506-
sn dbg dbg!(expr)
1507+
sn box Box::new(expr)
1508+
sn call function(expr)
1509+
sn dbg dbg!(expr)
15071510
sn dbgr dbg!(&expr)
1508-
sn deref *expr
1509-
sn let let
1510-
sn letm let mut
1511-
sn match match expr {}
1512-
sn ref &expr
1513-
sn refm &mut expr
1511+
sn deref *expr
1512+
sn let let
1513+
sn letm let mut
1514+
sn match match expr {}
1515+
sn ref &expr
1516+
sn refm &mut expr
15141517
sn return return expr
1515-
sn unsafe unsafe {}
1518+
sn unsafe unsafe {}
15161519
"#]],
15171520
);
15181521
check_with_config(
@@ -1534,18 +1537,18 @@ fn foo<T: ExcludedTrait>(v: T) {
15341537
me bar() (as ExcludedTrait) fn(&self)
15351538
me baz() (as ExcludedTrait) fn(&self)
15361539
me foo() (as ExcludedTrait) fn(&self)
1537-
sn box Box::new(expr)
1538-
sn call function(expr)
1539-
sn dbg dbg!(expr)
1540+
sn box Box::new(expr)
1541+
sn call function(expr)
1542+
sn dbg dbg!(expr)
15401543
sn dbgr dbg!(&expr)
1541-
sn deref *expr
1542-
sn let let
1543-
sn letm let mut
1544-
sn match match expr {}
1545-
sn ref &expr
1546-
sn refm &mut expr
1544+
sn deref *expr
1545+
sn let let
1546+
sn letm let mut
1547+
sn match match expr {}
1548+
sn ref &expr
1549+
sn refm &mut expr
15471550
sn return return expr
1548-
sn unsafe unsafe {}
1551+
sn unsafe unsafe {}
15491552
"#]],
15501553
);
15511554
}
@@ -1578,19 +1581,22 @@ fn foo() {
15781581
}
15791582
"#,
15801583
expect![[r#"
1581-
me inherent() fn(&self)
1582-
sn box Box::new(expr)
1583-
sn call function(expr)
1584-
sn dbg dbg!(expr)
1585-
sn dbgr dbg!(&expr)
1586-
sn deref *expr
1587-
sn let let
1588-
sn letm let mut
1589-
sn match match expr {}
1590-
sn ref &expr
1591-
sn refm &mut expr
1592-
sn return return expr
1593-
sn unsafe unsafe {}
1584+
me bar() (use module2::ExcludedTrait) fn(&self)
1585+
me baz() (use module2::ExcludedTrait) fn(&self)
1586+
me foo() (use module2::ExcludedTrait) fn(&self)
1587+
me inherent() fn(&self)
1588+
sn box Box::new(expr)
1589+
sn call function(expr)
1590+
sn dbg dbg!(expr)
1591+
sn dbgr dbg!(&expr)
1592+
sn deref *expr
1593+
sn let let
1594+
sn letm let mut
1595+
sn match match expr {}
1596+
sn ref &expr
1597+
sn refm &mut expr
1598+
sn return return expr
1599+
sn unsafe unsafe {}
15941600
"#]],
15951601
);
15961602
}
@@ -1623,19 +1629,22 @@ fn foo() {
16231629
}
16241630
"#,
16251631
expect![[r#"
1626-
me inherent() fn(&self)
1627-
sn box Box::new(expr)
1628-
sn call function(expr)
1629-
sn dbg dbg!(expr)
1630-
sn dbgr dbg!(&expr)
1631-
sn deref *expr
1632-
sn let let
1633-
sn letm let mut
1634-
sn match match expr {}
1635-
sn ref &expr
1636-
sn refm &mut expr
1637-
sn return return expr
1638-
sn unsafe unsafe {}
1632+
me bar() (use module2::ExcludedTrait) fn(&self)
1633+
me baz() (use module2::ExcludedTrait) fn(&self)
1634+
me foo() (use module2::ExcludedTrait) fn(&self)
1635+
me inherent() fn(&self)
1636+
sn box Box::new(expr)
1637+
sn call function(expr)
1638+
sn dbg dbg!(expr)
1639+
sn dbgr dbg!(&expr)
1640+
sn deref *expr
1641+
sn let let
1642+
sn letm let mut
1643+
sn match match expr {}
1644+
sn ref &expr
1645+
sn refm &mut expr
1646+
sn return return expr
1647+
sn unsafe unsafe {}
16391648
"#]],
16401649
);
16411650
}
@@ -1663,8 +1672,11 @@ fn foo() {
16631672
}
16641673
"#,
16651674
expect![[r#"
1666-
me inherent(…) fn(&self)
1667-
"#]],
1675+
me bar(…) (as ExcludedTrait) fn(&self)
1676+
me baz(…) (as ExcludedTrait) fn(&self)
1677+
me foo(…) (as ExcludedTrait) fn(&self)
1678+
me inherent(…) fn(&self)
1679+
"#]],
16681680
);
16691681
}
16701682

crates/rust-analyzer/src/config.rs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -442,50 +442,18 @@ config_data! {
442442
completion_autoimport_enable: bool = true,
443443
/// A list of full paths to traits to exclude from flyimport.
444444
///
445-
/// Traits in this list won't be suggested to be imported by flyimport for their methods. Methods from them won't be available in flyimport completion. They will still be available if in scope.
446-
///
447-
/// Note that the trait themselves can still be suggested by flyimport.
445+
/// Traits in this list won't have their methods suggested in completions unless the trait
446+
/// is in scope.
448447
///
449448
/// This setting also inherits `#rust-analyzer.completion.excludeTraits#`.
450449
///
451-
/// This setting defaults to:
450+
/// This setting defaults to the following unless overwritten:
452451
///
453452
/// - [`core::borrow::Borrow`](https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html)
454453
/// - [`core::borrow::BorrowMut`](https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html)
455-
/// - [`core::cmp::PartialEq`](https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html)
456-
/// - All operator traits (in [`core::ops`](https://doc.rust-lang.org/nightly/core/ops))
457-
///
458-
/// Note that if you override this setting, those traits won't be automatically inserted, so you may want to insert them manually.
459454
completion_autoimport_excludeTraits: Vec<String> = vec![
460455
"core::borrow::Borrow".to_owned(),
461456
"core::borrow::BorrowMut".to_owned(),
462-
"core::cmp::PartialEq".to_owned(),
463-
"core::ops::Add".to_owned(),
464-
"core::ops::AddAssign".to_owned(),
465-
"core::ops::BitAnd".to_owned(),
466-
"core::ops::BitAndAssign".to_owned(),
467-
"core::ops::BitOr".to_owned(),
468-
"core::ops::BitOrAssign".to_owned(),
469-
"core::ops::BitXor".to_owned(),
470-
"core::ops::BitXorAssign".to_owned(),
471-
"core::ops::Div".to_owned(),
472-
"core::ops::DivAssign".to_owned(),
473-
"core::ops::Mul".to_owned(),
474-
"core::ops::MulAssign".to_owned(),
475-
"core::ops::Rem".to_owned(),
476-
"core::ops::RemAssign".to_owned(),
477-
"core::ops::Shl".to_owned(),
478-
"core::ops::ShlAssign".to_owned(),
479-
"core::ops::Shr".to_owned(),
480-
"core::ops::ShrAssign".to_owned(),
481-
"core::ops::Sub".to_owned(),
482-
"core::ops::SubAssign".to_owned(),
483-
"core::ops::Neg".to_owned(),
484-
"core::ops::Not".to_owned(),
485-
"core::ops::Index".to_owned(),
486-
"core::ops::IndexMut".to_owned(),
487-
"core::ops::Deref".to_owned(),
488-
"core::ops::DerefMut".to_owned(),
489457
],
490458
/// Toggles the additional completions that automatically show method calls and field accesses
491459
/// with `self` prefixed to them when inside a method.

docs/user/generated_config.adoc

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -293,52 +293,20 @@ Default:
293293
----
294294
[
295295
"core::borrow::Borrow",
296-
"core::borrow::BorrowMut",
297-
"core::cmp::PartialEq",
298-
"core::ops::Add",
299-
"core::ops::AddAssign",
300-
"core::ops::BitAnd",
301-
"core::ops::BitAndAssign",
302-
"core::ops::BitOr",
303-
"core::ops::BitOrAssign",
304-
"core::ops::BitXor",
305-
"core::ops::BitXorAssign",
306-
"core::ops::Div",
307-
"core::ops::DivAssign",
308-
"core::ops::Mul",
309-
"core::ops::MulAssign",
310-
"core::ops::Rem",
311-
"core::ops::RemAssign",
312-
"core::ops::Shl",
313-
"core::ops::ShlAssign",
314-
"core::ops::Shr",
315-
"core::ops::ShrAssign",
316-
"core::ops::Sub",
317-
"core::ops::SubAssign",
318-
"core::ops::Neg",
319-
"core::ops::Not",
320-
"core::ops::Index",
321-
"core::ops::IndexMut",
322-
"core::ops::Deref",
323-
"core::ops::DerefMut"
296+
"core::borrow::BorrowMut"
324297
]
325298
----
326299
A list of full paths to traits to exclude from flyimport.
327300

328-
Traits in this list won't be suggested to be imported by flyimport for their methods. Methods from them won't be available in flyimport completion. They will still be available if in scope.
329-
330-
Note that the trait themselves can still be suggested by flyimport.
301+
Traits in this list won't have their methods suggested in completions unless the trait
302+
is in scope.
331303

332304
This setting also inherits `#rust-analyzer.completion.excludeTraits#`.
333305

334-
This setting defaults to:
306+
This setting defaults to the following unless overwritten:
335307

336308
- [`core::borrow::Borrow`](https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html)
337309
- [`core::borrow::BorrowMut`](https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html)
338-
- [`core::cmp::PartialEq`](https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html)
339-
- All operator traits (in [`core::ops`](https://doc.rust-lang.org/nightly/core/ops))
340-
341-
Note that if you override this setting, those traits won't be automatically inserted, so you may want to insert them manually.
342310

343311
--
344312
[[rust-analyzer.completion.autoself.enable]]rust-analyzer.completion.autoself.enable (default: `true`)::

0 commit comments

Comments
 (0)