@@ -42,6 +42,21 @@ public class LanguageServer
42
42
43
43
private TaskCompletionSource < bool > serverCompletedTask ;
44
44
45
+ private static string checkHelpScript = @"
46
+ [CmdletBinding()]
47
+ param (
48
+ [String]$CommandName
49
+ )
50
+ Try {
51
+ Microsoft.PowerShell.Core\Get-Command $CommandName -ErrorAction Stop | Out-Null
52
+ } catch [System.Management.Automation.CommandNotFoundException] {
53
+ $PSCmdlet.ThrowTerminatingError($PSItem)
54
+ }
55
+ try {
56
+ Microsoft.PowerShell.Core\Get-Help $CommandName -Online | Out-Null
57
+ } catch [System.Management.Automation.PSInvalidOperationException] {
58
+ Microsoft.PowerShell.Core\Get-Help $CommandName -Full
59
+ }" ;
45
60
public IEditorOperations EditorOperations
46
61
{
47
62
get { return this . editorOperations ; }
@@ -230,30 +245,15 @@ await requestContext.SendResult(
230
245
}
231
246
} ) ;
232
247
}
233
-
234
248
protected async Task HandleShowOnlineHelpRequest (
235
249
string helpParams ,
236
250
RequestContext < object > requestContext )
237
251
{
238
252
if ( helpParams == null ) { helpParams = "Get-Help" ; }
239
- string script = @"
240
- [CmdletBinding()]
241
- param (
242
- [String]$CommandName
243
- )
244
- Try {
245
- Microsoft.PowerShell.Core\Get-Command $CommandName -ErrorAction Stop | Out-Null
246
- } catch [System.Management.Automation.CommandNotFoundException] {
247
- $PSCmdlet.ThrowTerminatingError($PSItem)
248
- }
249
- try {
250
- Microsoft.PowerShell.Core\Get-Help $CommandName -Online | Out-Null
251
- } catch [System.Management.Automation.PSInvalidOperationException] {
252
- Microsoft.PowerShell.Core\Get-Help $CommandName -Full
253
- }" ;
254
- PSCommand checkHelpScript = new PSCommand ( ) ;
255
- checkHelpScript . AddScript ( script , true ) . AddArgument ( helpParams ) ;
256
- await editorSession . PowerShellContext . ExecuteCommand < PSObject > ( checkHelpScript , true ) ;
253
+
254
+ PSCommand checkHelpPSCommand = new PSCommand ( ) ;
255
+ checkHelpPSCommand . AddScript ( checkHelpScript , true ) . AddArgument ( helpParams ) ;
256
+ await editorSession . PowerShellContext . ExecuteCommand < PSObject > ( checkHelpPSCommand , true ) ;
257
257
await requestContext . SendResult ( null ) ;
258
258
}
259
259
0 commit comments