@@ -440,22 +440,27 @@ config_data! {
440
440
/// Toggles the additional completions that automatically add imports when completed.
441
441
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
442
442
completion_autoimport_enable: bool = true ,
443
- /// A list of full paths to traits to exclude from flyimport .
443
+ /// A list of full paths to items to exclude from auto-importing completions .
444
444
///
445
445
/// Traits in this list won't have their methods suggested in completions unless the trait
446
446
/// is in scope.
447
447
///
448
+ /// You can either specify a string path which defaults to type "always" or use the more verbose
449
+ /// form `{ "path": "path::to::item", type: "always" }`.
450
+ ///
451
+ /// For traits the type "methods" can be used to only exclude the methods but not the trait itself.
452
+ ///
448
453
/// This setting also inherits `#rust-analyzer.completion.excludeTraits#`.
449
- completion_autoimport_excludeTraits : Vec <String > = vec![
450
- "core::borrow::Borrow" . to_owned( ) ,
451
- "core::borrow::BorrowMut" . to_owned( ) ,
454
+ completion_autoimport_exclude : Vec <AutoImportExclusion > = vec![
455
+ AutoImportExclusion :: Verbose { path : "core::borrow::Borrow" . to_owned( ) , r#type : AutoImportExclusionType :: Methods } ,
456
+ AutoImportExclusion :: Verbose { path : "core::borrow::BorrowMut" . to_owned( ) , r#type : AutoImportExclusionType :: Methods } ,
452
457
] ,
453
458
/// Toggles the additional completions that automatically show method calls and field accesses
454
459
/// with `self` prefixed to them when inside a method.
455
460
completion_autoself_enable: bool = true ,
456
461
/// Whether to add parenthesis and argument snippets when completing function.
457
462
completion_callable_snippets: CallableCompletionDef = CallableCompletionDef :: FillArguments ,
458
- /// A list of full paths to traits to exclude from completion.
463
+ /// A list of full paths to traits whose methods to exclude from completion.
459
464
///
460
465
/// Methods from these traits won't be completed, even if the trait is in scope. However, they will still be suggested on expressions whose type is `dyn Trait`, `impl Trait` or `T where T: Trait`.
461
466
///
@@ -1478,7 +1483,26 @@ impl Config {
1478
1483
} else {
1479
1484
CompletionFieldsToResolve :: from_client_capabilities ( & client_capability_fields)
1480
1485
} ,
1481
- exclude_flyimport_traits : self . completion_autoimport_excludeTraits ( source_root) ,
1486
+ exclude_flyimport : self
1487
+ . completion_autoimport_exclude ( source_root)
1488
+ . iter ( )
1489
+ . map ( |it| match it {
1490
+ AutoImportExclusion :: Path ( path) => {
1491
+ ( path. clone ( ) , ide_completion:: AutoImportExclusionType :: Always )
1492
+ }
1493
+ AutoImportExclusion :: Verbose { path, r#type } => (
1494
+ path. clone ( ) ,
1495
+ match r#type {
1496
+ AutoImportExclusionType :: Always => {
1497
+ ide_completion:: AutoImportExclusionType :: Always
1498
+ }
1499
+ AutoImportExclusionType :: Methods => {
1500
+ ide_completion:: AutoImportExclusionType :: Methods
1501
+ }
1502
+ } ,
1503
+ ) ,
1504
+ } )
1505
+ . collect ( ) ,
1482
1506
exclude_traits : self . completion_excludeTraits ( source_root) ,
1483
1507
}
1484
1508
}
@@ -2419,6 +2443,21 @@ enum ExprFillDefaultDef {
2419
2443
Default ,
2420
2444
}
2421
2445
2446
+ #[ derive( Serialize , Deserialize , Debug , Clone ) ]
2447
+ #[ serde( untagged) ]
2448
+ #[ serde( rename_all = "snake_case" ) ]
2449
+ pub enum AutoImportExclusion {
2450
+ Path ( String ) ,
2451
+ Verbose { path : String , r#type : AutoImportExclusionType } ,
2452
+ }
2453
+
2454
+ #[ derive( Serialize , Deserialize , Debug , Clone ) ]
2455
+ #[ serde( rename_all = "snake_case" ) ]
2456
+ pub enum AutoImportExclusionType {
2457
+ Always ,
2458
+ Methods ,
2459
+ }
2460
+
2422
2461
#[ derive( Serialize , Deserialize , Debug , Clone ) ]
2423
2462
#[ serde( rename_all = "snake_case" ) ]
2424
2463
enum ImportGranularityDef {
@@ -3490,6 +3529,32 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
3490
3529
}
3491
3530
]
3492
3531
} ,
3532
+ "Vec<AutoImportExclusion>" => set ! {
3533
+ "type" : "array" ,
3534
+ "items" : {
3535
+ "anyOf" : [
3536
+ {
3537
+ "type" : "string" ,
3538
+ } ,
3539
+ {
3540
+ "type" : "object" ,
3541
+ "properties" : {
3542
+ "path" : {
3543
+ "type" : "string" ,
3544
+ } ,
3545
+ "type" : {
3546
+ "type" : "string" ,
3547
+ "enum" : [ "always" , "methods" ] ,
3548
+ "enumDescriptions" : [
3549
+ "Do not show this item or its methods (if it is a trait) in auto-import completions." ,
3550
+ "Do not show this traits methods in auto-import completions."
3551
+ ] ,
3552
+ } ,
3553
+ }
3554
+ }
3555
+ ]
3556
+ }
3557
+ } ,
3493
3558
_ => panic ! ( "missing entry for {ty}: {default} (field {field})" ) ,
3494
3559
}
3495
3560
0 commit comments