@@ -440,22 +440,27 @@ config_data! {
440440 /// Toggles the additional completions that automatically add imports when completed.
441441 /// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
442442 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 .
444444 ///
445445 /// Traits in this list won't have their methods suggested in completions unless the trait
446446 /// is in scope.
447447 ///
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+ ///
448453 /// 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 } ,
452457 ] ,
453458 /// Toggles the additional completions that automatically show method calls and field accesses
454459 /// with `self` prefixed to them when inside a method.
455460 completion_autoself_enable: bool = true ,
456461 /// Whether to add parenthesis and argument snippets when completing function.
457462 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.
459464 ///
460465 /// 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`.
461466 ///
@@ -1478,7 +1483,26 @@ impl Config {
14781483 } else {
14791484 CompletionFieldsToResolve :: from_client_capabilities ( & client_capability_fields)
14801485 } ,
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 ( ) ,
14821506 exclude_traits : self . completion_excludeTraits ( source_root) ,
14831507 }
14841508 }
@@ -2419,6 +2443,21 @@ enum ExprFillDefaultDef {
24192443 Default ,
24202444}
24212445
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+
24222461#[ derive( Serialize , Deserialize , Debug , Clone ) ]
24232462#[ serde( rename_all = "snake_case" ) ]
24242463enum ImportGranularityDef {
@@ -3490,6 +3529,32 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
34903529 }
34913530 ]
34923531 } ,
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+ } ,
34933558 _ => panic ! ( "missing entry for {ty}: {default} (field {field})" ) ,
34943559 }
34953560
0 commit comments