提交 459e4aad 编写于 作者: C CyrusNajmabadi

Single instance the completion helpers so we can cache data across completion calls.

上级 51bca88e
......@@ -208,6 +208,16 @@ internal partial class Session
return HandleDeletionTrigger(model, filterResults);
}
return HandleNormalFiltering(model, filterReason, textSnapshot, document, helper, recentItems, itemToFilterText, filterResults);
}
private Model HandleNormalFiltering(
Model model, CompletionFilterReason filterReason,
ITextSnapshot textSnapshot, Document document,
CompletionHelper helper, ImmutableArray<string> recentItems,
Dictionary<CompletionItem, string> itemToFilterText,
List<FilterResult> filterResults)
{
// Not deletion. Defer to the language to decide which item it thinks best
// matches the text typed so far.
......@@ -238,8 +248,8 @@ internal partial class Session
// like "WriteLine" since no filter text has actually been provided. HOwever,
// if "Console.WriteL$$" is typed, then we do want "WriteLine" to be committed.
var matchingItemCount = filterResults.Where(t => t.MatchedFilterText).Count();
var isUnique = bestCompletionItem != null &&
matchingItemCount == 1 &&
var isUnique = bestCompletionItem != null &&
matchingItemCount == 1 &&
itemToFilterText[bestCompletionItem].Length > 0;
var result = model.WithFilteredItems(filterResults.Select(r => r.PresentationItem).AsImmutable())
......
......@@ -10,35 +10,33 @@
namespace Microsoft.CodeAnalysis.Completion
{
internal class CompletionHelper
internal sealed class CompletionHelper
{
private static readonly CompletionHelper CaseSensitiveInstance = new CompletionHelper(isCaseSensitive: true);
private static readonly CompletionHelper CaseInsensitiveInstance = new CompletionHelper(isCaseSensitive: false);
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>();
private static readonly CultureInfo EnUSCultureInfo = new CultureInfo("en-US");
private readonly bool _isCaseSensitive;
protected CompletionHelper(bool isCaseSensitive)
private CompletionHelper(bool isCaseSensitive)
{
_isCaseSensitive = isCaseSensitive;
}
public static CompletionHelper GetHelper(Workspace workspace, string language)
{
var isCaseSensitive = true;
var ls = workspace.Services.GetLanguageServices(language);
if (ls != null)
{
var factory = ls.GetService<CompletionHelperFactory>();
if (factory != null)
{
return factory.CreateCompletionHelper();
}
var syntaxFacts = ls.GetService<ISyntaxFactsService>();
return new CompletionHelper(syntaxFacts?.IsCaseSensitive ?? true);
isCaseSensitive = syntaxFacts?.IsCaseSensitive ?? true;
}
return null;
return isCaseSensitive ? CaseSensitiveInstance : CaseInsensitiveInstance;
}
public static CompletionHelper GetHelper(Document document)
......@@ -62,12 +60,6 @@ public bool MatchesFilterText(CompletionItem item, string filterText)
return GetMatch(item, filterText) != null;
}
private static int GetRecentItemIndex(ImmutableArray<string> recentItems, CompletionItem item)
{
var index = recentItems.IndexOf(item.DisplayText);
return -index;
}
private PatternMatch? GetMatch(CompletionItem item, string filterText)
{
return GetMatch(item, filterText, includeMatchSpans: false);
......
// 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 Microsoft.CodeAnalysis.Host;
namespace Microsoft.CodeAnalysis.Completion
{
internal abstract class CompletionHelperFactory : ILanguageService
{
public abstract CompletionHelper CreateCompletionHelper();
}
}
\ No newline at end of file
......@@ -168,7 +168,6 @@
<Compile Include="Completion\CompletionDescription.cs" />
<Compile Include="Completion\CompletionFilterReason.cs" />
<Compile Include="Completion\CompletionHelper.cs" />
<Compile Include="Completion\CompletionHelperFactory.cs" />
<Compile Include="Completion\CompletionItem.cs" />
<Compile Include="Completion\CompletionItemFilter.cs" />
<Compile Include="Completion\CompletionItemRules.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册