@@ -48,29 +48,53 @@ public async Task<List<PSCommandMessage>> Handle(GetCommandParams request, Cance
4848 PSCommand psCommand = new PSCommand ( ) ;
4949
5050 // Executes the following:
51- // Get-Command -CommandType Function,Cmdlet,ExternalScript | Select-Object -Property Name,ModuleName | Sort-Object -Property Name
51+ // Get-Command -CommandType Function,Cmdlet,ExternalScript | Sort-Object -Property Name
5252 psCommand
5353 . AddCommand ( "Microsoft.PowerShell.Core\\ Get-Command" )
5454 . AddParameter ( "CommandType" , new [ ] { "Function" , "Cmdlet" , "ExternalScript" } )
55- . AddCommand ( "Microsoft.PowerShell.Utility\\ Select-Object" )
56- . AddParameter ( "Property" , new [ ] { "Name" , "ModuleName" } )
5755 . AddCommand ( "Microsoft.PowerShell.Utility\\ Sort-Object" )
5856 . AddParameter ( "Property" , "Name" ) ;
5957
60- IEnumerable < PSObject > result = await _powerShellContextService . ExecuteCommandAsync < PSObject > ( psCommand ) . ConfigureAwait ( false ) ;
58+ IEnumerable < CommandInfo > result = await _powerShellContextService . ExecuteCommandAsync < CommandInfo > ( psCommand ) . ConfigureAwait ( false ) ;
6159
6260 var commandList = new List < PSCommandMessage > ( ) ;
6361 if ( result != null )
6462 {
65- foreach ( dynamic command in result )
63+ foreach ( CommandInfo command in result )
6664 {
65+ // Some info objects have a quicker way to get the DefaultParameterSet. These
66+ // are also the most likely to show up so win-win.
67+ string defaultParameterSet = null ;
68+ switch ( command )
69+ {
70+ case CmdletInfo info :
71+ defaultParameterSet = info . DefaultParameterSet ;
72+ break ;
73+ case FunctionInfo info :
74+ defaultParameterSet = info . DefaultParameterSet ;
75+ break ;
76+ }
77+
78+ if ( defaultParameterSet == null )
79+ {
80+ // Try to get the default ParameterSet if it isn't streamlined (ExternalScriptInfo for example)
81+ foreach ( CommandParameterSetInfo parameterSetInfo in command . ParameterSets )
82+ {
83+ if ( parameterSetInfo . IsDefault )
84+ {
85+ defaultParameterSet = parameterSetInfo . Name ;
86+ break ;
87+ }
88+ }
89+ }
90+
6791 commandList . Add ( new PSCommandMessage
6892 {
6993 Name = command . Name ,
7094 ModuleName = command . ModuleName ,
7195 Parameters = command . Parameters ,
7296 ParameterSets = command . ParameterSets ,
73- DefaultParameterSet = command . DefaultParameterSet
97+ DefaultParameterSet = defaultParameterSet
7498 } ) ;
7599 }
76100 }
0 commit comments