Skip to content

Commit 74f04ff

Browse files
committed
Move Script to private static variable
1 parent 0f65dc6 commit 74f04ff

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

+19-19
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ public class LanguageServer
4242

4343
private TaskCompletionSource<bool> serverCompletedTask;
4444

45+
private static string checkHelpScript = @"
46+
[CmdletBinding()]
47+
param (
48+
[String]$CommandName
49+
)
50+
Try {
51+
Microsoft.PowerShell.Core\Get-Command $CommandName -ErrorAction Stop | Out-Null
52+
} catch [System.Management.Automation.CommandNotFoundException] {
53+
$PSCmdlet.ThrowTerminatingError($PSItem)
54+
}
55+
try {
56+
Microsoft.PowerShell.Core\Get-Help $CommandName -Online | Out-Null
57+
} catch [System.Management.Automation.PSInvalidOperationException] {
58+
Microsoft.PowerShell.Core\Get-Help $CommandName -Full
59+
}";
4560
public IEditorOperations EditorOperations
4661
{
4762
get { return this.editorOperations; }
@@ -230,30 +245,15 @@ await requestContext.SendResult(
230245
}
231246
});
232247
}
233-
234248
protected async Task HandleShowOnlineHelpRequest(
235249
string helpParams,
236250
RequestContext<object> requestContext)
237251
{
238252
if (helpParams == null) { helpParams = "Get-Help"; }
239-
string script = @"
240-
[CmdletBinding()]
241-
param (
242-
[String]$CommandName
243-
)
244-
Try {
245-
Microsoft.PowerShell.Core\Get-Command $CommandName -ErrorAction Stop | Out-Null
246-
} catch [System.Management.Automation.CommandNotFoundException] {
247-
$PSCmdlet.ThrowTerminatingError($PSItem)
248-
}
249-
try {
250-
Microsoft.PowerShell.Core\Get-Help $CommandName -Online | Out-Null
251-
} catch [System.Management.Automation.PSInvalidOperationException] {
252-
Microsoft.PowerShell.Core\Get-Help $CommandName -Full
253-
}";
254-
PSCommand checkHelpScript = new PSCommand();
255-
checkHelpScript.AddScript(script,true).AddArgument(helpParams);
256-
await editorSession.PowerShellContext.ExecuteCommand<PSObject>(checkHelpScript, true);
253+
254+
PSCommand checkHelpPSCommand = new PSCommand();
255+
checkHelpPSCommand.AddScript(checkHelpScript,true).AddArgument(helpParams);
256+
await editorSession.PowerShellContext.ExecuteCommand<PSObject>(checkHelpPSCommand, true);
257257
await requestContext.SendResult(null);
258258
}
259259

0 commit comments

Comments
 (0)