diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/ShowOnlineHelpRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/ShowHelpRequest.cs similarity index 63% rename from src/PowerShellEditorServices.Protocol/LanguageServer/ShowOnlineHelpRequest.cs rename to src/PowerShellEditorServices.Protocol/LanguageServer/ShowHelpRequest.cs index 1e65df93d..bce097aa6 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/ShowOnlineHelpRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/ShowHelpRequest.cs @@ -4,13 +4,22 @@ // using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; +using System; namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer { + + [Obsolete("This class is deprecated. Use ShowHelpRequest instead.")] public class ShowOnlineHelpRequest { public static readonly RequestType Type = RequestType.Create("powerShell/showOnlineHelp"); } + public class ShowHelpRequest + { + public static readonly + RequestType Type = + RequestType.Create("powerShell/showHelp"); + } } diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 7f8f223b4..0ac51dd6b 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -122,6 +122,8 @@ public void Start() this.HandleDocumentRangeFormattingRequest); this.messageHandlers.SetRequestHandler(ShowOnlineHelpRequest.Type, this.HandleShowOnlineHelpRequest); + this.messageHandlers.SetRequestHandler(ShowHelpRequest.Type, this.HandleShowHelpRequest); + this.messageHandlers.SetRequestHandler(ExpandAliasRequest.Type, this.HandleExpandAliasRequest); this.messageHandlers.SetRequestHandler(FindModuleRequest.Type, this.HandleFindModuleRequest); @@ -231,22 +233,49 @@ await requestContext.SendResult( }); } - protected async Task HandleShowOnlineHelpRequest( + protected async Task HandleShowHelpRequest( string helpParams, RequestContext requestContext) { - if (helpParams == null) { helpParams = "get-help"; } + const string CheckHelpScript = @" + [CmdletBinding()] + param ( + [String]$CommandName + ) + try { + $null = 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 + }"; - var psCommand = new PSCommand(); - psCommand.AddCommand("Get-Help"); - psCommand.AddArgument(helpParams); - psCommand.AddParameter("Online"); + if (string.IsNullOrEmpty(helpParams)) { helpParams = "Get-Help"; } - await editorSession.PowerShellContext.ExecuteCommand(psCommand); + PSCommand checkHelpPSCommand = new PSCommand() + .AddScript(CheckHelpScript, useLocalScope: true) + .AddArgument(helpParams); + await editorSession.PowerShellContext.ExecuteCommand(checkHelpPSCommand, sendOutputToHost: true); await requestContext.SendResult(null); } + protected async Task HandleShowOnlineHelpRequest( + string helpParams, + RequestContext requestContext + ) + { + PSCommand commandDeprecated = new PSCommand() + .AddCommand("Microsoft.PowerShell.Utility\\Write-Verbose") + .AddParameter("Message", "'powerShell/showOnlineHelp' has been deprecated. Use 'powerShell/showHelp' instead."); + + await editorSession.PowerShellContext.ExecuteCommand(commandDeprecated, sendOutputToHost: true); + await this.HandleShowHelpRequest(helpParams, requestContext); + } + private async Task HandleSetPSSARulesRequest( object param, RequestContext requestContext)