You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Command Explorer doesn't sort like Show-Command #1993
The original intent behind Command Explorer was to mimic Show-Command. I noticed today that Show-Command sorts with the hyphens being of higher sort value than other letters. While the Sort-Object that we use in the Command Explorer seems to strip out the hyphens and sorts based on the result. So you'll see some Convert-Toxxx and then ConvertTo-yyy followed by Convert-Tozzz.
System Details
This happens with Windows PowerShell 5.1 on Windows 10 1709 and insiders build 18898 as well as PowerShell Core 6.2. As such, I'm going to forego the vscode version and PSES.
Issue Description
Example of 4 made up functions:
PS> function ConvertTo-Lkj {}
PS> function Convert-ToLkj {}
PS> function Convert-Lkj {}
PS> function ConvertLkj {}
When running Show-Command and then sorting for lkj:
When running the equivalent Get-Command code Get-Command *lkj | select name | Sort name | ogv:
I have also tested this in pwsh with the same behavior:
PS> function ConvertTo-Lkj {}
PS> function Convert-ToLkj {}
PS> function Convert-Lkj {}
PS> function ConvertLkj {}
PS>get-command*lkj | select name | sort name
Name
----
ConvertLkj
Convert-LkjConvertTo-LkjConvert-ToLkj
🤔 it looks like it's .Net's way of sorting is not what I was expecting. When I use CSI to do some impromptu C# sorting (and type stuff wrong and such) I see that it appears to sort in the same way:
Whereas the way I expected it to sort is along the lines of JavaScript:
Where the hyphens are treated as being higher in order than letters so all of the a-* are grouped together.
Perhaps this is an easy fix of sorting on the vscode side with TypeScript (which presumably sorts the same way as JavaScript ¯\(ツ)/¯ ).
Or alternatively we accept that it sorts differently and leave it as is.
Formally the sort appears to be called Ordinal in the StringComparer class... It feels like it's probably a little more complicated for us because we have a List<PSCommandMessage> instead of List<String>.
I think the easiest way to outline the difference I'm seeing is this screenshot:
Here you can see PowerShell on the left sorting the commands and you have Convert-Path, Convert-PSUObject, Convert-String in the middle, while Show-Command on the right puts them first. It feels as though PowerShell decided it was comparing ConvertFromStringData and ConvertPath instead of ConvertFrom-StringData and Convert-Path.
So the point I'm now at, after stewing over it and trying to wrap my head around how to describe what it's doing and what I think it should be doing is this: does it matter that much? As I stated originally, the intent was to mimic Show-Command as much as possible. However, now I wonder if we should instead be looking to move past Show-Command and make it our own. Perhaps we let the sort be unless there are other users that encounter it and think it's an issue (honestly, I'm probably the only person currently using it because I'm working on a WebView to insert the command with parameters).
Activity
rjmholt commentedon May 29, 2019
Cory Knox (@corbob) What do you mean by hyphens included? As in Show-Command ignores hyphens?
This probably wouldn’t be considered a bug in Sort-Object but probably means we want to write our own sorting key function.
corbob commentedon May 30, 2019
🤔 it looks like it's .Net's way of sorting is not what I was expecting. When I use CSI to do some impromptu C# sorting (and type stuff wrong and such) I see that it appears to sort in the same way:

Whereas the way I expected it to sort is along the lines of JavaScript:

Where the hyphens are treated as being higher in order than letters so all of the
a-*are grouped together.Perhaps this is an easy fix of sorting on the vscode side with TypeScript (which presumably sorts the same way as JavaScript ¯\(ツ)/¯ ).
Or alternatively we accept that it sorts differently and leave it as is.
rjmholt commentedon May 30, 2019
I'd suggest something like this:
rjmholt commentedon May 30, 2019
(That can be improved if we want, so that new strings aren't allocated for the comparison. But it's more logic to maintain)
rjmholt commentedon May 30, 2019
Oh I see that's not quite the sort order you're looking for.
Can you describe formally what the sort order you want is?
Is it just a system where
-has a lower ordinal than alphanumerics?In any case, the fix is pretty straightforward, we just need to specify exactly what sort order you expect.
corbob commentedon May 31, 2019
Formally the sort appears to be called Ordinal in the StringComparer class... It feels like it's probably a little more complicated for us because we have a
List<PSCommandMessage>instead ofList<String>.I think the easiest way to outline the difference I'm seeing is this screenshot:
Here you can see PowerShell on the left sorting the commands and you have
Convert-Path,Convert-PSUObject,Convert-Stringin the middle, while Show-Command on the right puts them first. It feels as though PowerShell decided it was comparingConvertFromStringDataandConvertPathinstead ofConvertFrom-StringDataandConvert-Path.So the point I'm now at, after stewing over it and trying to wrap my head around how to describe what it's doing and what I think it should be doing is this: does it matter that much? As I stated originally, the intent was to mimic
Show-Commandas much as possible. However, now I wonder if we should instead be looking to move pastShow-Commandand make it our own. Perhaps we let the sort be unless there are other users that encounter it and think it's an issue (honestly, I'm probably the only person currently using it because I'm working on a WebView to insert the command with parameters).