@@ -11,6 +11,7 @@ use std::fmt::Write;
11
11
12
12
use super :: commands;
13
13
use super :: list_commands;
14
+ use super :: third_party_subcommands;
14
15
use super :: user_defined_aliases;
15
16
use crate :: command_prelude:: * ;
16
17
use crate :: util:: is_rustup;
@@ -703,7 +704,9 @@ See '<bright-cyan,bold>cargo help</> <cyan><<command>></>' for more information
703
704
. into_iter ( )
704
705
. map ( |t| clap_complete:: CompletionCandidate :: new ( t) )
705
706
. 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
+ }
707
710
candidates
708
711
} ) )
709
712
. subcommands ( commands:: builtin ( ) )
@@ -726,33 +729,31 @@ fn get_toolchains_from_rustup() -> Vec<String> {
726
729
stdout. lines ( ) . map ( |line| format ! ( "+{}" , line) ) . collect ( )
727
730
}
728
731
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 ( )
756
757
}
757
758
758
759
#[ test]
0 commit comments