Skip to content

Change Get-Help behavior to return local help when no online help available #721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Sep 21, 2018
28 changes: 19 additions & 9 deletions src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ public class LanguageServer

private TaskCompletionSource<bool> serverCompletedTask;

private static string checkHelpScript = @"
[CmdletBinding()]
param (
[String]$CommandName
)
Try {
Microsoft.PowerShell.Core\Get-Command $CommandName -ErrorAction Stop | Out-Null
} catch [System.Management.Automation.CommandNotFoundException] {
$PSCmdlet.ThrowTerminatingError($PSItem)
}
try {
Microsoft.PowerShell.Core\Get-Help $CommandName -Online | Out-Null
} catch [System.Management.Automation.PSInvalidOperationException] {
Microsoft.PowerShell.Core\Get-Help $CommandName -Full
}";
public IEditorOperations EditorOperations
{
get { return this.editorOperations; }
Expand Down Expand Up @@ -230,20 +245,15 @@ await requestContext.SendResult(
}
});
}

protected async Task HandleShowOnlineHelpRequest(
string helpParams,
RequestContext<object> requestContext)
{
if (helpParams == null) { helpParams = "get-help"; }

var psCommand = new PSCommand();
psCommand.AddCommand("Get-Help");
psCommand.AddArgument(helpParams);
psCommand.AddParameter("Online");

await editorSession.PowerShellContext.ExecuteCommand<object>(psCommand);
if (helpParams == null) { helpParams = "Get-Help"; }

PSCommand checkHelpPSCommand = new PSCommand();
checkHelpPSCommand.AddScript(checkHelpScript,true).AddArgument(helpParams);
await editorSession.PowerShellContext.ExecuteCommand<PSObject>(checkHelpPSCommand, true);
await requestContext.SendResult(null);
}

Expand Down