提交 e0af906a 编写于 作者: I Ivan Basov

code review feedback

上级 b87e2db6

// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Roslyn.Utilities;
using System;
using Microsoft.CodeAnalysis.Completion;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncCompletion
{
internal struct FilterResult
internal struct FilterResult : IComparable<FilterResult>
{
public readonly CompletionItem CompletionItem;
public readonly bool MatchedFilterText;
......@@ -19,50 +20,43 @@ public FilterResult(CompletionItem completionItem, string filterText, bool match
FilterText = filterText;
}
public static int Compare(FilterResult result1, FilterResult result2)
public int CompareTo(FilterResult other)
{
var item1 = result1.CompletionItem;
var item2 = result2.CompletionItem;
var item1 = this.CompletionItem;
var item2 = other.CompletionItem;
var prefixLength1 = item1.FilterText.GetCaseInsensitivePrefixLength(result1.FilterText);
var prefixLength2 = item2.FilterText.GetCaseInsensitivePrefixLength(result2.FilterText);
var prefixLength1 = item1.FilterText.GetCaseInsensitivePrefixLength(this.FilterText);
var prefixLength2 = item2.FilterText.GetCaseInsensitivePrefixLength(other.FilterText);
// Prefer the item that matches a longer prefix of the filter text.
if (prefixLength1 != prefixLength2)
{
return prefixLength1.CompareTo(prefixLength2);
}
else
{
// If the lengths are the same, prefer the one with the higher match priority.
// But only if it's an item that would have been hard selected. We don't want
// to aggressively select an item that was only going to be softly offered.
var item1Priority = item1.Rules.SelectionBehavior == CompletionItemSelectionBehavior.HardSelection
? item1.Rules.MatchPriority : MatchPriority.Default;
var item2Priority = item2.Rules.SelectionBehavior == CompletionItemSelectionBehavior.HardSelection
? item2.Rules.MatchPriority : MatchPriority.Default;
if (item1Priority != item2Priority)
{
return item1Priority > item2Priority ? 1 : -1;
}
// If the lengths are the same, prefer the one with the higher match priority.
// But only if it's an item that would have been hard selected. We don't want
// to aggressively select an item that was only going to be softly offered.
var item1Priority = item1.Rules.SelectionBehavior == CompletionItemSelectionBehavior.HardSelection
? item1.Rules.MatchPriority : MatchPriority.Default;
var item2Priority = item2.Rules.SelectionBehavior == CompletionItemSelectionBehavior.HardSelection
? item2.Rules.MatchPriority : MatchPriority.Default;
prefixLength1 = item1.FilterText.GetCaseSensitivePrefixLength(result1.FilterText);
prefixLength2 = item2.FilterText.GetCaseSensitivePrefixLength(result2.FilterText);
// If there are "Abc" vs "abc", we should prefer the case typed by user.
if (prefixLength1 != prefixLength2)
{
return prefixLength1 > prefixLength2 ? 1 : -1;
}
if (item1Priority != item2Priority)
{
return item1Priority.CompareTo(item2Priority);
}
if (result1.CompletionItem.IsPreferredItem() != result2.CompletionItem.IsPreferredItem())
{
return result1.CompletionItem.IsPreferredItem() ? 1 : -1;
}
prefixLength1 = item1.FilterText.GetCaseSensitivePrefixLength(this.FilterText);
prefixLength2 = item2.FilterText.GetCaseSensitivePrefixLength(other.FilterText);
return 0;
// If there are "Abc" vs "abc", we should prefer the case typed by user.
if (prefixLength1 != prefixLength2)
{
return prefixLength1.CompareTo(prefixLength2);
}
return this.CompletionItem.IsPreferredItem().CompareTo(other.CompletionItem.IsPreferredItem());
}
}
}
......@@ -365,7 +365,7 @@ private static bool IsAfterDot(ITextSnapshot snapshot, ITrackingSpan applicableT
}
else
{
var match = FilterResult.Compare(currentFilterResult.FilterResult, bestFilterResult.Value.FilterResult);
var match = currentFilterResult.FilterResult.CompareTo(bestFilterResult.Value.FilterResult);
if (match > 0)
{
moreThanOneMatchWithSamePriority = false;
......@@ -540,7 +540,7 @@ internal static int GetRecentItemIndex(ImmutableArray<string> recentItems, Rosly
}
internal static bool IsBetterDeletionMatch(FilterResult result1, FilterResult result2)
=> FilterResult.Compare(result1, result2) > 0;
=> result1.CompareTo(result2) > 0;
internal static bool MatchesFilterText(
CompletionHelper helper, RoslynCompletionItem item,
......@@ -582,7 +582,6 @@ internal static bool IsBetterDeletionMatch(FilterResult result1, FilterResult re
return helper.MatchesPattern(item.FilterText, filterText, CultureInfo.CurrentCulture);
}
internal static bool IsHardSelection(
string fullFilterText,
CompletionTriggerKind initialTriggerKind,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册