@@ -76,36 +76,36 @@ public static async Task<string> GetCommandSynopsisAsync(
76
76
CommandInfo commandInfo ,
77
77
PowerShellContextService powerShellContext )
78
78
{
79
+ Validate . IsNotNull ( nameof ( commandInfo ) , commandInfo ) ;
79
80
Validate . IsNotNull ( nameof ( powerShellContext ) , powerShellContext ) ;
80
81
81
- string synopsisString = string . Empty ;
82
-
83
- if ( commandInfo != null &&
84
- ( commandInfo . CommandType == CommandTypes . Cmdlet ||
85
- commandInfo . CommandType == CommandTypes . Function ||
86
- commandInfo . CommandType == CommandTypes . Filter ) )
82
+ // A small optimization to not run Get-Help on things like DSC resources.
83
+ if ( commandInfo . CommandType != CommandTypes . Cmdlet &&
84
+ commandInfo . CommandType != CommandTypes . Function &&
85
+ commandInfo . CommandType != CommandTypes . Filter )
87
86
{
88
- PSCommand command = new PSCommand ( ) ;
89
- command . AddCommand ( @"Microsoft.PowerShell.Core\Get-Help" ) ;
90
- command . AddArgument ( commandInfo ) ;
91
- command . AddParameter ( "ErrorAction" , "Ignore" ) ;
87
+ return string . Empty ;
88
+ }
92
89
93
- var results = await powerShellContext . ExecuteCommandAsync < PSObject > ( command , sendOutputToHost : false , sendErrorToHost : false ) . ConfigureAwait ( false ) ;
94
- PSObject helpObject = results . FirstOrDefault ( ) ;
90
+ PSCommand command = new PSCommand ( )
91
+ . AddCommand ( @"Microsoft.PowerShell.Core\Get-Help" )
92
+ // We use .Name here instead of just passing in commandInfo because
93
+ // CommandInfo.ToString() duplicates the Prefix if one exists.
94
+ . AddParameter ( "Name" , commandInfo . Name )
95
+ . AddParameter ( "ErrorAction" , "Ignore" ) ;
95
96
96
- if ( helpObject != null )
97
- {
98
- // Extract the synopsis string from the object
99
- synopsisString =
100
- ( string ) helpObject . Properties [ "synopsis" ] . Value ??
101
- string . Empty ;
97
+ var results = await powerShellContext . ExecuteCommandAsync < PSObject > ( command , sendOutputToHost : false , sendErrorToHost : false ) . ConfigureAwait ( false ) ;
98
+ PSObject helpObject = results . FirstOrDefault ( ) ;
102
99
103
- // Ignore the placeholder value for this field
104
- if ( string . Equals ( synopsisString , "SHORT DESCRIPTION" , System . StringComparison . CurrentCultureIgnoreCase ) )
105
- {
106
- synopsisString = string . Empty ;
107
- }
108
- }
100
+ // Extract the synopsis string from the object
101
+ string synopsisString =
102
+ ( string ) helpObject ? . Properties [ "synopsis" ] . Value ??
103
+ string . Empty ;
104
+
105
+ // Ignore the placeholder value for this field
106
+ if ( string . Equals ( synopsisString , "SHORT DESCRIPTION" , System . StringComparison . CurrentCultureIgnoreCase ) )
107
+ {
108
+ return string . Empty ;
109
109
}
110
110
111
111
return synopsisString ;
0 commit comments