From 2ef6a121f3b66c5ec4ebe50cfdb6fa2d5293a4bc Mon Sep 17 00:00:00 2001 From: corbob Date: Thu, 5 Jul 2018 20:31:18 -0700 Subject: [PATCH 01/14] Adding Get Command for Command Explorer --- .../LanguageServer/GetCommandsRequest.cs | 16 ++++++++++++++++ .../Server/LanguageServer.cs | 15 +++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs new file mode 100644 index 000000000..898f1e920 --- /dev/null +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs @@ -0,0 +1,16 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; + +namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer +{ + public class GetCommandsRequest + { + public static readonly + RequestType Type = + RequestType.Create("powerShell/getCommands"); + } +} diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index ab3e7a040..5ae957744 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -136,6 +136,7 @@ public void Start() this.messageHandlers.SetRequestHandler(ShowHelpRequest.Type, this.HandleShowHelpRequest); this.messageHandlers.SetRequestHandler(ExpandAliasRequest.Type, this.HandleExpandAliasRequest); + this.messageHandlers.SetRequestHandler(GetCommandsRequest.Type, this.HandleGetCommandsRequest); this.messageHandlers.SetRequestHandler(FindModuleRequest.Type, this.HandleFindModuleRequest); this.messageHandlers.SetRequestHandler(InstallModuleRequest.Type, this.HandleInstallModuleRequest); @@ -523,6 +524,20 @@ function __Expand-Alias { await requestContext.SendResult(result.First().ToString()); } + private async Task HandleGetCommandsRequest( + string content, + RequestContext requestContext) + { + var script = @" + Get-Command Get-Command | ConvertTo-Json +"; + var psCommand = new PSCommand(); + psCommand.AddScript("Get-Command Get-Command | Select-Object Name,Parameters,ParameterSets | ConvertTo-Json"); + var result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); + + await requestContext.SendResult(result.First().ToString()); + } + private async Task HandleFindModuleRequest( object param, RequestContext requestContext) From 9b5dc33f89753d5769632cfbe2536488b17d3d34 Mon Sep 17 00:00:00 2001 From: corbob Date: Fri, 6 Jul 2018 07:07:01 -0700 Subject: [PATCH 02/14] Return PowerShell Commands Return all commands but aliases. We're returning the same as show-command --- .../LanguageServer/GetCommandsRequest.cs | 15 ++++++++-- .../Server/LanguageServer.cs | 29 ++++++++++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs index 898f1e920..1b67bf846 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs @@ -4,13 +4,24 @@ // using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; +using System.Collections.Generic; namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer { public class GetCommandsRequest { public static readonly - RequestType Type = - RequestType.Create("powerShell/getCommands"); + RequestType, object, object, object> Type = + RequestType, object, object, object>.Create("powerShell/getCommands"); + } + + public class PSCommandMessage + { + public string Name { get; set; } + public string ModuleName { get; set; } + public string DefaultParameterSet { get; set; } + public System.Management.Automation.CommandTypes CommandType { get; set; } + public Dictionary Parameters { get; set; } + public System.Collections.ObjectModel.ReadOnlyCollection ParameterSets { get; set; } } } diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 5ae957744..f9e7a656e 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -525,17 +525,30 @@ function __Expand-Alias { } private async Task HandleGetCommandsRequest( - string content, - RequestContext requestContext) + object param, + RequestContext requestContext) { - var script = @" - Get-Command Get-Command | ConvertTo-Json -"; var psCommand = new PSCommand(); - psCommand.AddScript("Get-Command Get-Command | Select-Object Name,Parameters,ParameterSets | ConvertTo-Json"); - var result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); + psCommand.AddScript("Get-Command -CommandType Function, Cmdlet, ExternalScript"); + var result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); - await requestContext.SendResult(result.First().ToString()); + var commandList = new List(); + + if (result != null) + { + foreach (dynamic c in result) + { + commandList.Add(new PSCommandMessage { + Name = c.Name, + ModuleName = c.ModuleName, + Parameters = c.Parameters, + ParameterSets = c.ParameterSets, + DefaultParameterSet = c.DefaultParameterSet, + CommandType = c.CommandType }); + } + } + + await requestContext.SendResult(commandList); } private async Task HandleFindModuleRequest( From ac120d1ef7adc123c8dcdb26d713e88dd44535fd Mon Sep 17 00:00:00 2001 From: corbob Date: Sun, 8 Jul 2018 19:30:45 -0700 Subject: [PATCH 03/14] Sort the commands in PowerShell Sorted in PowerShell seems to have a negligible performance cost. This benefits us greatly as it means we don't need to sort in TypeScript. We can still sort if we want, but it's the default sort. --- src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index f9e7a656e..b1e2d241b 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -529,7 +529,7 @@ private async Task HandleGetCommandsRequest( RequestContext requestContext) { var psCommand = new PSCommand(); - psCommand.AddScript("Get-Command -CommandType Function, Cmdlet, ExternalScript"); + psCommand.AddScript("Get-Command -CommandType Function, Cmdlet, ExternalScript | Sort-Object Name"); var result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); var commandList = new List(); From b84bda8bed2b8e811698ff795504b0aded32e31a Mon Sep 17 00:00:00 2001 From: corbob Date: Thu, 12 Jul 2018 20:30:34 -0700 Subject: [PATCH 04/14] Using SMA Add using for System.Management.Automation --- .../LanguageServer/GetCommandsRequest.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs index 1b67bf846..79055c763 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs @@ -5,6 +5,7 @@ using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; using System.Collections.Generic; +using System.Management.Automation; namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer { @@ -20,8 +21,8 @@ public class PSCommandMessage public string Name { get; set; } public string ModuleName { get; set; } public string DefaultParameterSet { get; set; } - public System.Management.Automation.CommandTypes CommandType { get; set; } - public Dictionary Parameters { get; set; } - public System.Collections.ObjectModel.ReadOnlyCollection ParameterSets { get; set; } + public CommandTypes CommandType { get; set; } + public Dictionary Parameters { get; set; } + public System.Collections.ObjectModel.ReadOnlyCollection ParameterSets { get; set; } } } From 8452e6e44fc0696b8fc33d28e4bcdbc21c9d32d4 Mon Sep 17 00:00:00 2001 From: corbob Date: Sat, 21 Jul 2018 06:49:01 -0700 Subject: [PATCH 05/14] Add Get Command request type and handler --- .../LanguageServer/GetCommandsRequest.cs | 20 +++++-- .../Server/LanguageServer.cs | 52 ++++++++++++++++--- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs index 79055c763..3ba5df241 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs @@ -9,11 +9,18 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer { - public class GetCommandsRequest + public class GetAllCommandsRequest { public static readonly - RequestType, object, object, object> Type = - RequestType, object, object, object>.Create("powerShell/getCommands"); + RequestType, object, object, object> Type = + RequestType, object, object, object>.Create("powerShell/getAllCommands"); + } + + public class GetCommandRequest + { + public static readonly + RequestType Type = + RequestType.Create("powerShell/getCommand"); } public class PSCommandMessage @@ -21,8 +28,13 @@ public class PSCommandMessage public string Name { get; set; } public string ModuleName { get; set; } public string DefaultParameterSet { get; set; } - public CommandTypes CommandType { get; set; } public Dictionary Parameters { get; set; } public System.Collections.ObjectModel.ReadOnlyCollection ParameterSets { get; set; } } + + public class PSAllCommandsMessage + { + public string Name { get; set; } + public string ModuleName { get; set; } + } } diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index b1e2d241b..24a8416fb 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -13,6 +13,7 @@ using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Management.Automation; @@ -136,7 +137,8 @@ public void Start() this.messageHandlers.SetRequestHandler(ShowHelpRequest.Type, this.HandleShowHelpRequest); this.messageHandlers.SetRequestHandler(ExpandAliasRequest.Type, this.HandleExpandAliasRequest); - this.messageHandlers.SetRequestHandler(GetCommandsRequest.Type, this.HandleGetCommandsRequest); + this.messageHandlers.SetRequestHandler(GetAllCommandsRequest.Type, this.HandleGetAllCommandsRequest); + this.messageHandlers.SetRequestHandler(GetCommandRequest.Type, this.HandleGetCommandRequest); this.messageHandlers.SetRequestHandler(FindModuleRequest.Type, this.HandleFindModuleRequest); this.messageHandlers.SetRequestHandler(InstallModuleRequest.Type, this.HandleInstallModuleRequest); @@ -524,28 +526,66 @@ function __Expand-Alias { await requestContext.SendResult(result.First().ToString()); } - private async Task HandleGetCommandsRequest( + private async Task HandleGetAllCommandsRequest( object param, RequestContext requestContext) { var psCommand = new PSCommand(); - psCommand.AddScript("Get-Command -CommandType Function, Cmdlet, ExternalScript | Sort-Object Name"); + psCommand.AddScript("Get-Command -CommandType Function, Cmdlet, ExternalScript | Select-Object Name,ModuleName | Sort-Object Name"); + Logger.Write(LogLevel.Verbose, $"Calling {psCommand.Commands}"); + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); var result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); + stopwatch.Stop(); + Logger.Write(LogLevel.Verbose, $"Returned from Get-Command with {result.Count()} results in {stopwatch.ElapsedMilliseconds}ms"); + var commandList = new List(); + if (result != null) + { + Logger.Write(LogLevel.Verbose, "Starting conversion of results"); + foreach (dynamic c in result) + { + commandList.Add(new PSAllCommandsMessage + { + Name = c.Name, + ModuleName = c.ModuleName, + }); + } + Logger.Write(LogLevel.Verbose, "Finished conversion of results"); + } + + await requestContext.SendResult(commandList); + } + + private async Task HandleGetCommandRequest( + string param, + RequestContext requestContext) + { + var psCommand = new PSCommand(); + psCommand.AddCommand("Get-Command").AddArgument(param); + Logger.Write(LogLevel.Verbose, $"Calling {psCommand.Commands}"); + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + var result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); + stopwatch.Stop(); + Logger.Write(LogLevel.Verbose, $"Returned from Get-Command with {result.Count()} results in {stopwatch.ElapsedMilliseconds}ms"); var commandList = new List(); if (result != null) { + Logger.Write(LogLevel.Verbose, "Starting conversion of results"); foreach (dynamic c in result) { - commandList.Add(new PSCommandMessage { + commandList.Add(new PSCommandMessage + { Name = c.Name, ModuleName = c.ModuleName, Parameters = c.Parameters, ParameterSets = c.ParameterSets, - DefaultParameterSet = c.DefaultParameterSet, - CommandType = c.CommandType }); + DefaultParameterSet = c.DefaultParameterSet + }); } + Logger.Write(LogLevel.Verbose, "Finished conversion of results"); } await requestContext.SendResult(commandList); From 7ce82bd211b507f86f9501fa72eb8f545ff646ba Mon Sep 17 00:00:00 2001 From: corbob Date: Tue, 31 Jul 2018 20:13:47 -0700 Subject: [PATCH 06/14] Add comments documenting the purpose of the message and requests --- .../LanguageServer/GetCommandsRequest.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs index 3ba5df241..d400bd702 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs @@ -9,6 +9,9 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer { + /// + /// Defines a class that describes the request to get all PowerShell Commands from the current session + /// public class GetAllCommandsRequest { public static readonly @@ -16,6 +19,10 @@ public static readonly RequestType, object, object, object>.Create("powerShell/getAllCommands"); } + /// + /// Defines a class that describes the request to get the details for a single PowerShell Command + /// from the current session. + /// public class GetCommandRequest { public static readonly @@ -23,6 +30,10 @@ public static readonly RequestType.Create("powerShell/getCommand"); } + /// + /// Defines a class that describes the message to get the details for a single PowerShell Command + /// from the current session + /// public class PSCommandMessage { public string Name { get; set; } @@ -32,6 +43,9 @@ public class PSCommandMessage public System.Collections.ObjectModel.ReadOnlyCollection ParameterSets { get; set; } } + /// + /// Defines a class that describes the message to get all PowerShell Commands from the current session + /// public class PSAllCommandsMessage { public string Name { get; set; } From 1e995f69fc334da4569d2b62665d0917b0d7422f Mon Sep 17 00:00:00 2001 From: corbob Date: Mon, 13 Aug 2018 20:30:50 -0700 Subject: [PATCH 07/14] Remove extra logging. Be explicit with types. --- .../Server/LanguageServer.cs | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 24a8416fb..f0e0a67b2 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -530,19 +530,14 @@ private async Task HandleGetAllCommandsRequest( object param, RequestContext requestContext) { - var psCommand = new PSCommand(); + PSCommand psCommand = new PSCommand(); psCommand.AddScript("Get-Command -CommandType Function, Cmdlet, ExternalScript | Select-Object Name,ModuleName | Sort-Object Name"); - Logger.Write(LogLevel.Verbose, $"Calling {psCommand.Commands}"); - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - var result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); - stopwatch.Stop(); - Logger.Write(LogLevel.Verbose, $"Returned from Get-Command with {result.Count()} results in {stopwatch.ElapsedMilliseconds}ms"); - var commandList = new List(); + IEnumerable result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); + + List commandList = new List(); if (result != null) { - Logger.Write(LogLevel.Verbose, "Starting conversion of results"); foreach (dynamic c in result) { commandList.Add(new PSAllCommandsMessage @@ -551,7 +546,6 @@ private async Task HandleGetAllCommandsRequest( ModuleName = c.ModuleName, }); } - Logger.Write(LogLevel.Verbose, "Finished conversion of results"); } await requestContext.SendResult(commandList); @@ -561,19 +555,13 @@ private async Task HandleGetCommandRequest( string param, RequestContext requestContext) { - var psCommand = new PSCommand(); + PSCommand psCommand = new PSCommand(); psCommand.AddCommand("Get-Command").AddArgument(param); - Logger.Write(LogLevel.Verbose, $"Calling {psCommand.Commands}"); - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - var result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); - stopwatch.Stop(); - Logger.Write(LogLevel.Verbose, $"Returned from Get-Command with {result.Count()} results in {stopwatch.ElapsedMilliseconds}ms"); - var commandList = new List(); + IEnumerable result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); + List commandList = new List(); if (result != null) { - Logger.Write(LogLevel.Verbose, "Starting conversion of results"); foreach (dynamic c in result) { commandList.Add(new PSCommandMessage From 0e15f40da4ed22222f910481faa0c76ae69510c6 Mon Sep 17 00:00:00 2001 From: corbob Date: Mon, 3 Sep 2018 07:47:48 -0700 Subject: [PATCH 08/14] Remove GetAllCommands. >> Refactor into a single command. If nothing is passed, it will return all objects. --- .../LanguageServer/GetCommandsRequest.cs | 18 ---------- .../Server/LanguageServer.cs | 34 +++---------------- 2 files changed, 5 insertions(+), 47 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs index d400bd702..8cd156a1b 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs @@ -9,15 +9,6 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer { - /// - /// Defines a class that describes the request to get all PowerShell Commands from the current session - /// - public class GetAllCommandsRequest - { - public static readonly - RequestType, object, object, object> Type = - RequestType, object, object, object>.Create("powerShell/getAllCommands"); - } /// /// Defines a class that describes the request to get the details for a single PowerShell Command @@ -42,13 +33,4 @@ public class PSCommandMessage public Dictionary Parameters { get; set; } public System.Collections.ObjectModel.ReadOnlyCollection ParameterSets { get; set; } } - - /// - /// Defines a class that describes the message to get all PowerShell Commands from the current session - /// - public class PSAllCommandsMessage - { - public string Name { get; set; } - public string ModuleName { get; set; } - } } diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index f0e0a67b2..a9b117be8 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -137,7 +137,6 @@ public void Start() this.messageHandlers.SetRequestHandler(ShowHelpRequest.Type, this.HandleShowHelpRequest); this.messageHandlers.SetRequestHandler(ExpandAliasRequest.Type, this.HandleExpandAliasRequest); - this.messageHandlers.SetRequestHandler(GetAllCommandsRequest.Type, this.HandleGetAllCommandsRequest); this.messageHandlers.SetRequestHandler(GetCommandRequest.Type, this.HandleGetCommandRequest); this.messageHandlers.SetRequestHandler(FindModuleRequest.Type, this.HandleFindModuleRequest); @@ -525,38 +524,16 @@ function __Expand-Alias { await requestContext.SendResult(result.First().ToString()); } - - private async Task HandleGetAllCommandsRequest( - object param, - RequestContext requestContext) - { - PSCommand psCommand = new PSCommand(); - psCommand.AddScript("Get-Command -CommandType Function, Cmdlet, ExternalScript | Select-Object Name,ModuleName | Sort-Object Name"); - IEnumerable result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); - - List commandList = new List(); - - if (result != null) - { - foreach (dynamic c in result) - { - commandList.Add(new PSAllCommandsMessage - { - Name = c.Name, - ModuleName = c.ModuleName, - }); - } - } - - await requestContext.SendResult(commandList); - } - private async Task HandleGetCommandRequest( string param, RequestContext requestContext) { PSCommand psCommand = new PSCommand(); - psCommand.AddCommand("Get-Command").AddArgument(param); + if(param != "") { + psCommand.AddCommand("Get-Command").AddArgument(param); + } else { + psCommand.AddScript("Get-Command -CommandType Function, Cmdlet, ExternalScript | Select-Object Name,ModuleName | Sort-Object Name"); + } IEnumerable result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); List commandList = new List(); @@ -573,7 +550,6 @@ private async Task HandleGetCommandRequest( DefaultParameterSet = c.DefaultParameterSet }); } - Logger.Write(LogLevel.Verbose, "Finished conversion of results"); } await requestContext.SendResult(commandList); From 8d91d173be0896e947e0abfe80ee7519d2e93302 Mon Sep 17 00:00:00 2001 From: corbob Date: Fri, 28 Sep 2018 22:11:13 -0700 Subject: [PATCH 09/14] Qualify the things --- .../Server/LanguageServer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index a9b117be8..69c7a28dc 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -530,9 +530,9 @@ private async Task HandleGetCommandRequest( { PSCommand psCommand = new PSCommand(); if(param != "") { - psCommand.AddCommand("Get-Command").AddArgument(param); + psCommand.AddCommand("Microsoft.PowerShell.Core\\Get-Command").AddArgument(param); } else { - psCommand.AddScript("Get-Command -CommandType Function, Cmdlet, ExternalScript | Select-Object Name,ModuleName | Sort-Object Name"); + psCommand.AddScript("Microsoft.PowerShell.Core\\Get-Command -CommandType Function, Cmdlet, ExternalScript | Select-Object Name,ModuleName | Sort-Object Name"); } IEnumerable result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); List commandList = new List(); From f363d87141d2ac8da77f9e7f2a8176486349ac22 Mon Sep 17 00:00:00 2001 From: corbob Date: Mon, 29 Oct 2018 20:50:17 -0700 Subject: [PATCH 10/14] cleanup of some things --- .../Server/LanguageServer.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 69c7a28dc..5742990fb 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -524,14 +524,17 @@ function __Expand-Alias { await requestContext.SendResult(result.First().ToString()); } + private async Task HandleGetCommandRequest( string param, RequestContext requestContext) { PSCommand psCommand = new PSCommand(); - if(param != "") { + if (param != "") { psCommand.AddCommand("Microsoft.PowerShell.Core\\Get-Command").AddArgument(param); - } else { + } + else + { psCommand.AddScript("Microsoft.PowerShell.Core\\Get-Command -CommandType Function, Cmdlet, ExternalScript | Select-Object Name,ModuleName | Sort-Object Name"); } IEnumerable result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); From 0a795d53966252f50f58a3d79a6dcd61506d18b9 Mon Sep 17 00:00:00 2001 From: corbob Date: Wed, 31 Oct 2018 21:54:57 -0700 Subject: [PATCH 11/14] Update summary for classes. --- .../{GetCommandsRequest.cs => GetCommandRequest.cs} | 5 ++--- .../Server/LanguageServer.cs | 12 ++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) rename src/PowerShellEditorServices.Protocol/LanguageServer/{GetCommandsRequest.cs => GetCommandRequest.cs} (82%) diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandRequest.cs similarity index 82% rename from src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs rename to src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandRequest.cs index 8cd156a1b..8705cfa8d 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandsRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandRequest.cs @@ -11,8 +11,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer { /// - /// Defines a class that describes the request to get the details for a single PowerShell Command - /// from the current session. + /// Describes the request to get the details for PowerShell Commands from the current session. /// public class GetCommandRequest { @@ -22,7 +21,7 @@ public static readonly } /// - /// Defines a class that describes the message to get the details for a single PowerShell Command + /// Describes the message to get the details for a single PowerShell Command /// from the current session /// public class PSCommandMessage diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 5742990fb..b55674939 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -542,15 +542,15 @@ private async Task HandleGetCommandRequest( if (result != null) { - foreach (dynamic c in result) + foreach (dynamic command in result) { commandList.Add(new PSCommandMessage { - Name = c.Name, - ModuleName = c.ModuleName, - Parameters = c.Parameters, - ParameterSets = c.ParameterSets, - DefaultParameterSet = c.DefaultParameterSet + Name = command.Name, + ModuleName = command.ModuleName, + Parameters = command.Parameters, + ParameterSets = command.ParameterSets, + DefaultParameterSet = command.DefaultParameterSet }); } } From cda81cd7db9fd57425c25bb17d2e0f3ff8c3f4b8 Mon Sep 17 00:00:00 2001 From: corbob Date: Wed, 21 Nov 2018 21:51:44 -0800 Subject: [PATCH 12/14] Eliminate AddScript (among other things) --- .../LanguageServer/GetCommandRequest.cs | 1 - .../Server/LanguageServer.cs | 12 +++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandRequest.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandRequest.cs index 8705cfa8d..df847dcbe 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandRequest.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/GetCommandRequest.cs @@ -9,7 +9,6 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer { - /// /// Describes the request to get the details for PowerShell Commands from the current session. /// diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index b55674939..2880b74f0 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -530,15 +530,21 @@ private async Task HandleGetCommandRequest( RequestContext requestContext) { PSCommand psCommand = new PSCommand(); - if (param != "") { + if (!string.IsNullOrEmpty(param)) { psCommand.AddCommand("Microsoft.PowerShell.Core\\Get-Command").AddArgument(param); } else { - psCommand.AddScript("Microsoft.PowerShell.Core\\Get-Command -CommandType Function, Cmdlet, ExternalScript | Select-Object Name,ModuleName | Sort-Object Name"); + psCommand.AddCommand("Microsoft.PowerShell.Core\\Get-Command") + .AddParameter("CommandType", new[]{"Function", "Cmdlet", "ExternalScript"}) + .AddCommand("Select-Object") + .AddParameter("Property", new[]{"Name", "ModuleName"}) + .AddCommand("Sort-Object") + .AddParameter("Property", "Name"); + // psCommand.AddScript("Microsoft.PowerShell.Core\\Get-Command -CommandType Function, Cmdlet, ExternalScript | Select-Object Name,ModuleName | Sort-Object Name"); } IEnumerable result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); - List commandList = new List(); + var commandList = new List(); if (result != null) { From 097c48b90276bc71134cf16be60dde1bc80197ff Mon Sep 17 00:00:00 2001 From: corbob Date: Thu, 22 Nov 2018 21:52:12 -0800 Subject: [PATCH 13/14] Clean up some commented code. Fully Qualify the namespace of stuffs... Something about Async... --- .../Server/LanguageServer.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 2880b74f0..669d71c3c 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -137,7 +137,7 @@ public void Start() this.messageHandlers.SetRequestHandler(ShowHelpRequest.Type, this.HandleShowHelpRequest); this.messageHandlers.SetRequestHandler(ExpandAliasRequest.Type, this.HandleExpandAliasRequest); - this.messageHandlers.SetRequestHandler(GetCommandRequest.Type, this.HandleGetCommandRequest); + this.messageHandlers.SetRequestHandler(GetCommandRequest.Type, this.HandleGetCommandRequestAsync); this.messageHandlers.SetRequestHandler(FindModuleRequest.Type, this.HandleFindModuleRequest); this.messageHandlers.SetRequestHandler(InstallModuleRequest.Type, this.HandleInstallModuleRequest); @@ -525,7 +525,7 @@ function __Expand-Alias { await requestContext.SendResult(result.First().ToString()); } - private async Task HandleGetCommandRequest( + private async Task HandleGetCommandRequestAsync( string param, RequestContext requestContext) { @@ -537,11 +537,10 @@ private async Task HandleGetCommandRequest( { psCommand.AddCommand("Microsoft.PowerShell.Core\\Get-Command") .AddParameter("CommandType", new[]{"Function", "Cmdlet", "ExternalScript"}) - .AddCommand("Select-Object") + .AddCommand("Microsoft.PowerShell.Utility\\Select-Object") .AddParameter("Property", new[]{"Name", "ModuleName"}) - .AddCommand("Sort-Object") + .AddCommand("Microsoft.PowerShell.Utility\\Sort-Object") .AddParameter("Property", "Name"); - // psCommand.AddScript("Microsoft.PowerShell.Core\\Get-Command -CommandType Function, Cmdlet, ExternalScript | Select-Object Name,ModuleName | Sort-Object Name"); } IEnumerable result = await this.editorSession.PowerShellContext.ExecuteCommand(psCommand); var commandList = new List(); From 4956c7edcc6ef83f72b056f838f68abf318f4eb1 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Tue, 27 Nov 2018 16:23:57 -0800 Subject: [PATCH 14/14] Indentation and format changes --- .../Server/LanguageServer.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 669d71c3c..cb5ea17cd 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -530,12 +530,16 @@ private async Task HandleGetCommandRequestAsync( RequestContext requestContext) { PSCommand psCommand = new PSCommand(); - if (!string.IsNullOrEmpty(param)) { + if (!string.IsNullOrEmpty(param)) + { psCommand.AddCommand("Microsoft.PowerShell.Core\\Get-Command").AddArgument(param); } else { - psCommand.AddCommand("Microsoft.PowerShell.Core\\Get-Command") + // Executes the following: + // Get-Command -CommandType Function,Cmdlet,ExternalScript | Select-Object -Property Name,ModuleName | Sort-Object -Property Name + psCommand + .AddCommand("Microsoft.PowerShell.Core\\Get-Command") .AddParameter("CommandType", new[]{"Function", "Cmdlet", "ExternalScript"}) .AddCommand("Microsoft.PowerShell.Utility\\Select-Object") .AddParameter("Property", new[]{"Name", "ModuleName"})