@@ -76,36 +76,36 @@ public static async Task<string> GetCommandSynopsisAsync(
7676 CommandInfo commandInfo ,
7777 PowerShellContextService powerShellContext )
7878 {
79+ Validate . IsNotNull ( nameof ( commandInfo ) , commandInfo ) ;
7980 Validate . IsNotNull ( nameof ( powerShellContext ) , powerShellContext ) ;
8081
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 )
8786 {
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+ }
9289
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" ) ;
9596
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 ( ) ;
10299
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 ;
109109 }
110110
111111 return synopsisString ;
0 commit comments