@@ -254,22 +254,39 @@ protected async Task HandleShowHelpRequest(
254
254
[String]$CommandName
255
255
)
256
256
try {
257
- $null = Microsoft.PowerShell.Core\Get-Command $CommandName -ErrorAction Stop
257
+ $command = Microsoft.PowerShell.Core\Get-Command $CommandName -ErrorAction Stop
258
258
} catch [System.Management.Automation.CommandNotFoundException] {
259
259
$PSCmdlet.ThrowTerminatingError($PSItem)
260
260
}
261
261
try {
262
- $null = Microsoft.PowerShell.Core\Get-Help $CommandName -Online
263
- } catch [System.Management.Automation.PSInvalidOperationException] {
264
- Microsoft.PowerShell.Core\Get-Help $CommandName -Full
265
- }" ;
262
+ $helpUri = [Microsoft.PowerShell.Commands.GetHelpCodeMethods]::GetHelpUri($command)
263
+
264
+ $oldSslVersion = [System.Net.ServicePointManager]::SecurityProtocol
265
+ [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
266
+
267
+ # HEAD means we don't need the content itself back, just the response header
268
+ $status = (Microsoft.PowerShell.Utility\Invoke-WebRequest -Method Head -Uri $helpUri -TimeoutSec 5 -ErrorAction Stop).StatusCode
269
+ if ($status -lt 400) {
270
+ $null = Microsoft.PowerShell.Core\Get-Help $CommandName -Online
271
+ return
272
+ }
273
+ } catch {
274
+ # Ignore - we want to drop out to Get-Help -Full
275
+ } finally {
276
+ [System.Net.ServicePointManager]::SecurityProtocol = $oldSslVersion
277
+ }
278
+
279
+ return Microsoft.PowerShell.Core\Get-Help $CommandName -Full
280
+ " ;
266
281
267
282
if ( string . IsNullOrEmpty ( helpParams ) ) { helpParams = "Get-Help" ; }
268
283
269
284
PSCommand checkHelpPSCommand = new PSCommand ( )
270
285
. AddScript ( CheckHelpScript , useLocalScope : true )
271
286
. AddArgument ( helpParams ) ;
272
287
288
+ // TODO: Rather than print the help in the console, we should send the string back
289
+ // to VSCode to display in a help pop-up (or similar)
273
290
await editorSession . PowerShellContext . ExecuteCommand < PSObject > ( checkHelpPSCommand , sendOutputToHost : true ) ;
274
291
await requestContext . SendResult ( null ) ;
275
292
}
0 commit comments