提交 fcf213ac 编写于 作者: G Gen Lu

Use stable sorting to preserve existing alphabetical order

上级 44c2895d
......@@ -153,7 +153,7 @@ internal ItemManager(RecentItemsManager recentItemsManager)
var completionRules = completionService?.GetRules() ?? CompletionRules.Default;
var completionHelper = document != null ? CompletionHelper.GetHelper(document) : _defaultCompletionHelper;
var initialListOfItemsToBeIncludedBuilder = ArrayBuilder<ExtendedFilterResult>.GetInstance();
var builder = ArrayBuilder<ExtendedFilterResult>.GetInstance();
foreach (var item in data.InitialSortedList)
{
cancellationToken.ThrowIfCancellationRequested();
......@@ -179,7 +179,7 @@ internal ItemManager(RecentItemsManager recentItemsManager)
if (MatchesFilterText(completionHelper, roslynItem, filterText, initialRoslynTriggerKind, filterReason, _recentItemsManager.RecentItems, out var patternMatch))
{
initialListOfItemsToBeIncludedBuilder.Add(new ExtendedFilterResult(item, new FilterResult(roslynItem, filterText, matchedFilterText: true, patternMatch)));
builder.Add(new ExtendedFilterResult(item, new FilterResult(roslynItem, filterText, matchedFilterText: true, patternMatch)));
}
else
{
......@@ -196,7 +196,7 @@ internal ItemManager(RecentItemsManager recentItemsManager)
initialRoslynTriggerKind == CompletionTriggerKind.Invoke ||
filterText.Length <= 1)
{
initialListOfItemsToBeIncludedBuilder.Add(new ExtendedFilterResult(item, new FilterResult(roslynItem, filterText, matchedFilterText: false, patternMatch)));
builder.Add(new ExtendedFilterResult(item, new FilterResult(roslynItem, filterText, matchedFilterText: false, patternMatch)));
}
}
}
......@@ -212,19 +212,20 @@ internal ItemManager(RecentItemsManager recentItemsManager)
return null;
}
if (initialListOfItemsToBeIncludedBuilder.Count == 0)
if (builder.Count == 0)
{
return HandleAllItemsFilteredOut(reason, data.SelectedFilters, completionRules);
}
var initialListOfItemsToBeIncluded = builder.ToImmutableArray();
var experimentationService = document.Project.Solution.Workspace.Services.GetService<IExperimentationService>();
if (experimentationService.IsExperimentEnabled(WellKnownExperimentNames.SortCompletionListByMatch))
{
initialListOfItemsToBeIncludedBuilder.Sort(new NullablePatternMatchComparer());
// Need a stable sorting algorithm to preserve the original order for items with same pattern match score.
initialListOfItemsToBeIncluded = initialListOfItemsToBeIncluded.OrderBy(new NullablePatternMatchComparer()).ToImmutableArray();
}
var initialListOfItemsToBeIncluded = initialListOfItemsToBeIncludedBuilder.ToImmutableAndFree();
var options = document?.Project.Solution.Options;
var highlightMatchingPortions = options?.GetOption(CompletionOptions.HighlightMatchingPortionsOfCompletionListItems, document.Project.Language) ?? true;
var showCompletionItemFilters = options?.GetOption(CompletionOptions.ShowCompletionItemFilters, document.Project.Language) ?? true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册