@@ -11,6 +11,7 @@ use std::fmt::Write;
1111
1212use super :: commands;
1313use super :: list_commands;
14+ use super :: third_party_subcommands;
1415use super :: user_defined_aliases;
1516use crate :: command_prelude:: * ;
1617use crate :: util:: is_rustup;
@@ -703,7 +704,9 @@ See '<bright-cyan,bold>cargo help</> <cyan><<command>></>' for more information
703704 . into_iter ( )
704705 . map ( |t| clap_complete:: CompletionCandidate :: new ( t) )
705706 . collect :: < Vec < _ > > ( ) ;
706- candidates. extend ( get_alias_candidates ( ) ) ;
707+ if let Ok ( gctx) = new_gctx_for_completions ( ) {
708+ candidates. extend ( get_command_candidates ( & gctx) ) ;
709+ }
707710 candidates
708711 } ) )
709712 . subcommands ( commands:: builtin ( ) )
@@ -726,33 +729,31 @@ fn get_toolchains_from_rustup() -> Vec<String> {
726729 stdout. lines ( ) . map ( |line| format ! ( "+{}" , line) ) . collect ( )
727730}
728731
729- fn get_alias_candidates ( ) -> Vec < clap_complete:: CompletionCandidate > {
730- if let Ok ( gctx) = new_gctx_for_completions ( ) {
731- let alias_map = user_defined_aliases ( & gctx) ;
732- return alias_map
733- . iter ( )
734- . map ( |( alias, cmd_info) | {
735- let help_text = match cmd_info {
736- CommandInfo :: Alias { target } => {
737- let cmd_str = target
738- . iter ( )
739- . map ( String :: as_str)
740- . collect :: < Vec < _ > > ( )
741- . join ( " " ) ;
742- format ! ( "alias for {}" , cmd_str)
743- }
744- CommandInfo :: BuiltIn { .. } => {
745- unreachable ! ( "BuiltIn command shouldn't appear in alias map" )
746- }
747- CommandInfo :: External { .. } => {
748- unreachable ! ( "External command shouldn't appear in alias map" )
749- }
750- } ;
751- clap_complete:: CompletionCandidate :: new ( alias. clone ( ) ) . help ( Some ( help_text. into ( ) ) )
752- } )
753- . collect ( ) ;
754- }
755- Vec :: new ( )
732+ fn get_command_candidates ( gctx : & GlobalContext ) -> Vec < clap_complete:: CompletionCandidate > {
733+ let mut commands = user_defined_aliases ( gctx) ;
734+ commands. extend ( third_party_subcommands ( gctx) ) ;
735+ commands
736+ . iter ( )
737+ . map ( |( name, cmd_info) | {
738+ let help_text = match cmd_info {
739+ CommandInfo :: Alias { target } => {
740+ let cmd_str = target
741+ . iter ( )
742+ . map ( String :: as_str)
743+ . collect :: < Vec < _ > > ( )
744+ . join ( " " ) ;
745+ format ! ( "alias for {}" , cmd_str)
746+ }
747+ CommandInfo :: BuiltIn { .. } => {
748+ unreachable ! ( "BuiltIn command shouldn't appear in alias map" )
749+ }
750+ CommandInfo :: External { path } => {
751+ format ! ( "from {}" , path. display( ) )
752+ }
753+ } ;
754+ clap_complete:: CompletionCandidate :: new ( name. clone ( ) ) . help ( Some ( help_text. into ( ) ) )
755+ } )
756+ . collect ( )
756757}
757758
758759#[ test]
0 commit comments