提交 33cd7fdf 编写于 作者: C CyrusNajmabadi

Merge pull request #11834 from CyrusNajmabadi/CompletionHelperWork

Remove turkish specialization.
......@@ -117,8 +117,8 @@ protected static bool IsAllDigits(string filterText)
protected PatternMatch? GetMatch(CompletionItem item, string filterText, bool includeMatchSpans)
{
var patternMatcher = this.GetPatternMatcher(GetCultureSpecificQuirks(filterText), CultureInfo.CurrentCulture);
var match = patternMatcher.GetFirstMatch(GetCultureSpecificQuirks(item.FilterText), includeMatchSpans);
var patternMatcher = this.GetPatternMatcher(filterText, CultureInfo.CurrentCulture);
var match = patternMatcher.GetFirstMatch(item.FilterText, includeMatchSpans);
if (match != null)
{
......@@ -128,8 +128,8 @@ protected static bool IsAllDigits(string filterText)
// Start with the culture-specific comparison, and fall back to en-US.
if (!CultureInfo.CurrentCulture.Equals(EnUSCultureInfo))
{
patternMatcher = this.GetFallbackPatternMatcher(GetCultureSpecificQuirks(filterText));
match = patternMatcher.GetFirstMatch(GetCultureSpecificQuirks(item.FilterText));
patternMatcher = this.GetEnUSPatternMatcher(filterText);
match = patternMatcher.GetFirstMatch(item.FilterText);
if (match != null)
{
return match;
......@@ -139,52 +139,37 @@ protected static bool IsAllDigits(string filterText)
return null;
}
/// <summary>
/// Apply any culture-specific quirks to the given text for the purposes of pattern matching.
/// For example, in the Turkish locale, capital 'i's should be treated specially in Visual Basic.
/// </summary>
protected virtual string GetCultureSpecificQuirks(string candidate)
{
return candidate;
}
private readonly object _gate = new object();
private readonly Dictionary<string, PatternMatcher> _patternMatcherMap = new Dictionary<string, PatternMatcher>();
private readonly Dictionary<string, PatternMatcher> _fallbackPatternMatcherMap = new Dictionary<string, PatternMatcher>();
internal static readonly CultureInfo EnUSCultureInfo = new CultureInfo("en-US");
protected PatternMatcher GetPatternMatcher(string value, CultureInfo culture)
private PatternMatcher GetPatternMatcher(
string value, CultureInfo culture, Dictionary<string, PatternMatcher> map)
{
lock (_gate)
{
PatternMatcher patternMatcher;
if (!_patternMatcherMap.TryGetValue(value, out patternMatcher))
if (!map.TryGetValue(value, out patternMatcher))
{
patternMatcher = new PatternMatcher(value, culture,
verbatimIdentifierPrefixIsWordCharacter: true,
patternMatcher = new PatternMatcher(value, culture,
verbatimIdentifierPrefixIsWordCharacter: true,
allowFuzzyMatching: false);
_patternMatcherMap.Add(value, patternMatcher);
map.Add(value, patternMatcher);
}
return patternMatcher;
}
}
private PatternMatcher GetFallbackPatternMatcher(string value)
protected PatternMatcher GetPatternMatcher(string value, CultureInfo culture)
{
lock (_gate)
{
PatternMatcher patternMatcher;
if (!_fallbackPatternMatcherMap.TryGetValue(value, out patternMatcher))
{
patternMatcher = new PatternMatcher(
value, EnUSCultureInfo, verbatimIdentifierPrefixIsWordCharacter: true,
allowFuzzyMatching: false);
_fallbackPatternMatcherMap.Add(value, patternMatcher);
}
return GetPatternMatcher(value, culture, _patternMatcherMap);
}
return patternMatcher;
}
private PatternMatcher GetEnUSPatternMatcher(string value)
{
return GetPatternMatcher(value, EnUSCultureInfo, _fallbackPatternMatcherMap);
}
/// <summary>
......@@ -193,8 +178,8 @@ private PatternMatcher GetFallbackPatternMatcher(string value)
/// </summary>
public virtual bool IsBetterFilterMatch(CompletionItem item1, CompletionItem item2, string filterText, CompletionTrigger trigger, CompletionFilterReason filterReason, ImmutableArray<string> recentItems = default(ImmutableArray<string>))
{
var match1 = GetMatch(item1, GetCultureSpecificQuirks(filterText));
var match2 = GetMatch(item2, GetCultureSpecificQuirks(filterText));
var match1 = GetMatch(item1, filterText);
var match2 = GetMatch(item2, filterText);
if (match1 != null && match2 != null)
{
......
......@@ -52,15 +52,6 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Completion
Return MyBase.MatchesFilterText(item, filterText, trigger, filterReason, recentItems)
End Function
Protected Overrides Function GetCultureSpecificQuirks(candidate As String) As String
' TODO: define way to identify this case w/o language specific check
If CultureInfo.CurrentCulture.Name = "tr-TR" Then
Return candidate.Replace("I"c, "İ"c)
End If
Return candidate
End Function
Public Overrides Function IsBetterFilterMatch(item1 As CompletionItem, item2 As CompletionItem, filterText As String, trigger As CompletionTrigger, filterReason As CompletionFilterReason, Optional recentItems As ImmutableArray(Of String) = Nothing) As Boolean
If filterReason = CompletionFilterReason.BackspaceOrDelete Then
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册