diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/ShowHelpRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/ShowHelpRequest.cs index bce097aa6..ae2922ebd 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/ShowHelpRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/ShowHelpRequest.cs @@ -3,8 +3,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; using System; +using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer { @@ -16,6 +16,7 @@ public static readonly RequestType Type = RequestType.Create("powerShell/showOnlineHelp"); } + public class ShowHelpRequest { public static readonly diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 5056ec1c3..7f74c2a91 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -254,15 +254,30 @@ protected async Task HandleShowHelpRequest( [String]$CommandName ) try { - $null = Microsoft.PowerShell.Core\Get-Command $CommandName -ErrorAction Stop + $command = Microsoft.PowerShell.Core\Get-Command $CommandName -ErrorAction Stop } catch [System.Management.Automation.CommandNotFoundException] { $PSCmdlet.ThrowTerminatingError($PSItem) } try { - $null = Microsoft.PowerShell.Core\Get-Help $CommandName -Online - } catch [System.Management.Automation.PSInvalidOperationException] { - Microsoft.PowerShell.Core\Get-Help $CommandName -Full - }"; + $helpUri = [Microsoft.PowerShell.Commands.GetHelpCodeMethods]::GetHelpUri($command) + + $oldSslVersion = [System.Net.ServicePointManager]::SecurityProtocol + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 + + # HEAD means we don't need the content itself back, just the response header + $status = (Microsoft.PowerShell.Utility\Invoke-WebRequest -Method Head -Uri $helpUri -TimeoutSec 5 -ErrorAction Stop).StatusCode + if ($status -lt 400) { + $null = Microsoft.PowerShell.Core\Get-Help $CommandName -Online + return + } + } catch { + # Ignore - we want to drop out to Get-Help -Full + } finally { + [System.Net.ServicePointManager]::SecurityProtocol = $oldSslVersion + } + + return Microsoft.PowerShell.Core\Get-Help $CommandName -Full + "; if (string.IsNullOrEmpty(helpParams)) { helpParams = "Get-Help"; } @@ -270,6 +285,8 @@ protected async Task HandleShowHelpRequest( .AddScript(CheckHelpScript, useLocalScope: true) .AddArgument(helpParams); + // TODO: Rather than print the help in the console, we should send the string back + // to VSCode to display in a help pop-up (or similar) await editorSession.PowerShellContext.ExecuteCommand(checkHelpPSCommand, sendOutputToHost: true); await requestContext.SendResult(null); }