-
Notifications
You must be signed in to change notification settings - Fork 234
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
Changes from 8 commits
c35d13e
75f8afb
55936d1
6ad4e91
51a2ae8
0f65dc6
74f04ff
c772aa0
4090e8e
c481d02
d125d66
f100131
c2ba5ad
504a5a8
004d53d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,21 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server | |
{ | ||
public class LanguageServer | ||
{ | ||
private const string CheckHelpScript = @" | ||
[CmdletBinding()] | ||
param ( | ||
[String]$CommandName | ||
) | ||
Try { | ||
$null = Microsoft.PowerShell.Core\Get-Command $CommandName -ErrorAction Stop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 for module prefixed commands! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this script is only used in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to make sense. As was said in slack: if it's a Unless @tylerl0706 @SeeminglyScience or @rjmholt have any objections I'll move the string back into the function as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reasonable to me! Let's hear what 1 other has to say There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep no issues with that 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the string into the function as const (also creeped the scope a bit by handling both commands that could come in (although not from vscode-powershell...) and marking one as deprecated. |
||
} 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 | ||
}"; | ||
private static CancellationTokenSource existingRequestCancellation; | ||
|
||
private ILogger Logger; | ||
|
@@ -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(); | ||
corbob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
checkHelpPSCommand.AddScript(CheckHelpScript, useLocalScope: true).AddArgument(helpParams); | ||
await editorSession.PowerShellContext.ExecuteCommand<PSObject>(checkHelpPSCommand, sendOutputToHost: true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a newline above the first |
||
await requestContext.SendResult(null); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Below you use a lower case
try
(and everywhere else uses lower case keywords). Probably should tweak that here to be consistent. :-)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll get this corrected after the below comment is replied to so I'm not doing a bunch of extra work :)