@@ -254,22 +254,39 @@ protected async Task HandleShowHelpRequest(
254254 [String]$CommandName
255255 )
256256 try {
257- $null = Microsoft.PowerShell.Core\Get-Command $CommandName -ErrorAction Stop
257+ $command = Microsoft.PowerShell.Core\Get-Command $CommandName -ErrorAction Stop
258258 } catch [System.Management.Automation.CommandNotFoundException] {
259259 $PSCmdlet.ThrowTerminatingError($PSItem)
260260 }
261261 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+ " ;
266281
267282 if ( string . IsNullOrEmpty ( helpParams ) ) { helpParams = "Get-Help" ; }
268283
269284 PSCommand checkHelpPSCommand = new PSCommand ( )
270285 . AddScript ( CheckHelpScript , useLocalScope : true )
271286 . AddArgument ( helpParams ) ;
272287
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)
273290 await editorSession . PowerShellContext . ExecuteCommand < PSObject > ( checkHelpPSCommand , sendOutputToHost : true ) ;
274291 await requestContext . SendResult ( null ) ;
275292 }
0 commit comments