Skip to content

Commit 65e0b68

Browse files
kimsey0jonsequitur
authored andcommitted
Sort suggestions by match index, then alphabetically
1 parent d622598 commit 65e0b68

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/System.CommandLine/Parsing/StringExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ public static class StringExtensions
1515
private static readonly string[] _optionPrefixStrings = { "--", "-", "/" };
1616

1717
internal static bool ContainsCaseInsensitive(
18+
this string source,
19+
string value) =>
20+
source.IndexOfCaseInsensitive(value) >= 0;
21+
22+
internal static int IndexOfCaseInsensitive(
1823
this string source,
1924
string value) =>
2025
CultureInfo.InvariantCulture
2126
.CompareInfo
2227
.IndexOf(source,
2328
value ?? "",
24-
CompareOptions.OrdinalIgnoreCase) >= 0;
29+
CompareOptions.OrdinalIgnoreCase);
2530

2631
internal static string RemovePrefix(this string rawAlias)
2732
{

src/System.CommandLine/Symbol.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ public virtual IEnumerable<string> GetSuggestions(string textToMatch = null)
146146
return this.ChildSymbolAliases()
147147
.Concat(argumentSuggestions)
148148
.Distinct()
149-
.OrderBy(symbol => symbol, StringComparer.OrdinalIgnoreCase)
150-
.Containing(textToMatch);
149+
.Containing(textToMatch)
150+
.OrderBy(symbol => symbol.IndexOfCaseInsensitive(textToMatch))
151+
.ThenBy(symbol => symbol, StringComparer.OrdinalIgnoreCase);
151152
}
152153

153154
public override string ToString() => $"{GetType().Name}: {Name}";

0 commit comments

Comments
 (0)