|
13 | 13 | using Newtonsoft.Json.Linq;
|
14 | 14 | using System;
|
15 | 15 | using System.Collections.Generic;
|
| 16 | +using System.Diagnostics; |
16 | 17 | using System.IO;
|
17 | 18 | using System.Linq;
|
18 | 19 | using System.Management.Automation;
|
@@ -138,6 +139,7 @@ public void Start()
|
138 | 139 | this.messageHandlers.SetRequestHandler(ShowHelpRequest.Type, this.HandleShowHelpRequest);
|
139 | 140 |
|
140 | 141 | this.messageHandlers.SetRequestHandler(ExpandAliasRequest.Type, this.HandleExpandAliasRequest);
|
| 142 | + this.messageHandlers.SetRequestHandler(GetCommandRequest.Type, this.HandleGetCommandRequestAsync); |
141 | 143 |
|
142 | 144 | this.messageHandlers.SetRequestHandler(FindModuleRequest.Type, this.HandleFindModuleRequest);
|
143 | 145 | this.messageHandlers.SetRequestHandler(InstallModuleRequest.Type, this.HandleInstallModuleRequest);
|
@@ -525,6 +527,48 @@ function __Expand-Alias {
|
525 | 527 | await requestContext.SendResult(result.First().ToString());
|
526 | 528 | }
|
527 | 529 |
|
| 530 | + private async Task HandleGetCommandRequestAsync( |
| 531 | + string param, |
| 532 | + RequestContext<object> requestContext) |
| 533 | + { |
| 534 | + PSCommand psCommand = new PSCommand(); |
| 535 | + if (!string.IsNullOrEmpty(param)) |
| 536 | + { |
| 537 | + psCommand.AddCommand("Microsoft.PowerShell.Core\\Get-Command").AddArgument(param); |
| 538 | + } |
| 539 | + else |
| 540 | + { |
| 541 | + // Executes the following: |
| 542 | + // Get-Command -CommandType Function,Cmdlet,ExternalScript | Select-Object -Property Name,ModuleName | Sort-Object -Property Name |
| 543 | + psCommand |
| 544 | + .AddCommand("Microsoft.PowerShell.Core\\Get-Command") |
| 545 | + .AddParameter("CommandType", new[]{"Function", "Cmdlet", "ExternalScript"}) |
| 546 | + .AddCommand("Microsoft.PowerShell.Utility\\Select-Object") |
| 547 | + .AddParameter("Property", new[]{"Name", "ModuleName"}) |
| 548 | + .AddCommand("Microsoft.PowerShell.Utility\\Sort-Object") |
| 549 | + .AddParameter("Property", "Name"); |
| 550 | + } |
| 551 | + IEnumerable<PSObject> result = await this.editorSession.PowerShellContext.ExecuteCommand<PSObject>(psCommand); |
| 552 | + var commandList = new List<PSCommandMessage>(); |
| 553 | + |
| 554 | + if (result != null) |
| 555 | + { |
| 556 | + foreach (dynamic command in result) |
| 557 | + { |
| 558 | + commandList.Add(new PSCommandMessage |
| 559 | + { |
| 560 | + Name = command.Name, |
| 561 | + ModuleName = command.ModuleName, |
| 562 | + Parameters = command.Parameters, |
| 563 | + ParameterSets = command.ParameterSets, |
| 564 | + DefaultParameterSet = command.DefaultParameterSet |
| 565 | + }); |
| 566 | + } |
| 567 | + } |
| 568 | + |
| 569 | + await requestContext.SendResult(commandList); |
| 570 | + } |
| 571 | + |
528 | 572 | private async Task HandleFindModuleRequest(
|
529 | 573 | object param,
|
530 | 574 | RequestContext<object> requestContext)
|
|
0 commit comments