1
- // Copyright (c) Microsoft Corporation.
1
+ // Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
4
using System . Collections . Concurrent ;
@@ -17,8 +17,8 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility
17
17
/// </summary>
18
18
internal static class CommandHelpers
19
19
{
20
- private static readonly HashSet < string > s_nounExclusionList = new HashSet < string >
21
- {
20
+ private static readonly HashSet < string > s_nounExclusionList = new ( )
21
+ {
22
22
// PowerShellGet v2 nouns
23
23
"CredsFromCredentialProvider" ,
24
24
"DscResource" ,
@@ -36,8 +36,8 @@ internal static class CommandHelpers
36
36
} ;
37
37
38
38
// This is used when a noun exists in multiple modules (for example, "Command" is used in Microsoft.PowerShell.Core and also PowerShellGet)
39
- private static readonly HashSet < string > s_cmdletExclusionList = new HashSet < string >
40
- {
39
+ private static readonly HashSet < string > s_cmdletExclusionList = new ( )
40
+ {
41
41
// Commands in PowerShellGet with conflicting nouns
42
42
"Find-Command" ,
43
43
"Find-Module" ,
@@ -49,17 +49,16 @@ internal static class CommandHelpers
49
49
"Update-ModuleManifest" ,
50
50
} ;
51
51
52
- private static readonly ConcurrentDictionary < string , CommandInfo > s_commandInfoCache =
53
- new ConcurrentDictionary < string , CommandInfo > ( ) ;
52
+ private static readonly ConcurrentDictionary < string , CommandInfo > s_commandInfoCache = new ( ) ;
54
53
55
- private static readonly ConcurrentDictionary < string , string > s_synopsisCache =
56
- new ConcurrentDictionary < string , string > ( ) ;
54
+ private static readonly ConcurrentDictionary < string , string > s_synopsisCache = new ( ) ;
57
55
58
56
/// <summary>
59
57
/// Gets the CommandInfo instance for a command with a particular name.
60
58
/// </summary>
61
59
/// <param name="commandName">The name of the command.</param>
62
- /// <param name="powerShellContext">The PowerShellContext to use for running Get-Command.</param>
60
+ /// <param name="currentRunspace">The current runspace.</param>
61
+ /// <param name="executionService">The execution service.</param>
63
62
/// <returns>A CommandInfo object with details about the specified command.</returns>
64
63
public static async Task < CommandInfo > GetCommandInfoAsync (
65
64
string commandName ,
@@ -97,7 +96,11 @@ public static async Task<CommandInfo> GetCommandInfoAsync(
97
96
. AddArgument ( commandName )
98
97
. AddParameter ( "ErrorAction" , "Ignore" ) ;
99
98
100
- CommandInfo commandInfo = ( await executionService . ExecutePSCommandAsync < CommandInfo > ( command , CancellationToken . None ) . ConfigureAwait ( false ) ) . FirstOrDefault ( ) ;
99
+ IReadOnlyList < CommandInfo > results = await executionService
100
+ . ExecutePSCommandAsync < CommandInfo > ( command , CancellationToken . None )
101
+ . ConfigureAwait ( false ) ;
102
+
103
+ CommandInfo commandInfo = results . Count > 0 ? results [ 0 ] : null ;
101
104
102
105
// Only cache CmdletInfos since they're exposed in binaries they are likely to not change throughout the session.
103
106
if ( commandInfo ? . CommandType == CommandTypes . Cmdlet )
@@ -112,8 +115,8 @@ public static async Task<CommandInfo> GetCommandInfoAsync(
112
115
/// Gets the command's "Synopsis" documentation section.
113
116
/// </summary>
114
117
/// <param name="commandInfo">The CommandInfo instance for the command.</param>
115
- /// <param name="executionService">The PowerShellContext to use for getting command documentation.</param>
116
- /// <returns></returns>
118
+ /// <param name="executionService">The exeuction service to use for getting command documentation.</param>
119
+ /// <returns>The synopsis. </returns>
117
120
public static async Task < string > GetCommandSynopsisAsync (
118
121
CommandInfo commandInfo ,
119
122
IInternalPowerShellExecutionService executionService )
@@ -146,13 +149,13 @@ public static async Task<string> GetCommandSynopsisAsync(
146
149
. AddParameter ( "Online" , false )
147
150
. AddParameter ( "ErrorAction" , "Ignore" ) ;
148
151
149
- IReadOnlyList < PSObject > results = await executionService . ExecutePSCommandAsync < PSObject > ( command , CancellationToken . None ) . ConfigureAwait ( false ) ;
150
- PSObject helpObject = results . FirstOrDefault ( ) ;
152
+ IReadOnlyList < PSObject > results = await executionService
153
+ . ExecutePSCommandAsync < PSObject > ( command , CancellationToken . None )
154
+ . ConfigureAwait ( false ) ;
151
155
152
156
// Extract the synopsis string from the object
153
- string synopsisString =
154
- ( string ) helpObject ? . Properties [ "synopsis" ] . Value ??
155
- string . Empty ;
157
+ PSObject helpObject = results . Count > 0 ? results [ 0 ] : null ;
158
+ string synopsisString = ( string ) helpObject ? . Properties [ "synopsis" ] . Value ?? string . Empty ;
156
159
157
160
// Only cache cmdlet infos because since they're exposed in binaries, the can never change throughout the session.
158
161
if ( commandInfo . CommandType == CommandTypes . Cmdlet )
0 commit comments