提交 027d34a3 编写于 作者: C CyrusNajmabadi

Remove unreachable code.

上级 5b39d9b5
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
......@@ -85,6 +86,7 @@ private SearchQuery(Func<string, bool> predicate)
throw new ArgumentNullException(nameof(predicate));
}
Kind = SearchKind.Custom;
_predicate = predicate;
}
......@@ -152,6 +154,10 @@ public static partial class SymbolFinder
internal static Task<IEnumerable<ISymbol>> FindDeclarationsAsync(
Project project, SearchQuery query, SymbolFilter filter, CancellationToken cancellationToken)
{
// All entrypoints to this function are Find functions that are only searching
// for specific strings (i.e. they never do a custom search).
Debug.Assert(query.Kind != SearchKind.Custom);
if (project == null)
{
throw new ArgumentNullException(nameof(project));
......@@ -171,6 +177,10 @@ public static partial class SymbolFinder
private static async Task<IEnumerable<ISymbol>> FindDeclarationsAsyncImpl(
Project project, SearchQuery query, SymbolFilter criteria, CancellationToken cancellationToken)
{
// All entrypoints to this function are Find functions that are only searching
// for specific strings (i.e. they never do a custom search).
Debug.Assert(query.Kind != SearchKind.Custom);
var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
var list = new List<ISymbol>();
......@@ -267,6 +277,10 @@ private static IEnumerable<ISymbol> TranslateNamespaces(List<ISymbol> symbols, C
Solution solution, IAssemblySymbol assembly, PortableExecutableReference referenceOpt,
SearchQuery query, SymbolFilter filter, List<ISymbol> list, CancellationToken cancellationToken)
{
// All entrypoints to this function are Find functions that are only searching
// for specific strings (i.e. they never do a custom search).
Debug.Assert(query.Kind != SearchKind.Custom);
using (Logger.LogBlock(FunctionId.SymbolFinder_Assembly_AddDeclarationsAsync, cancellationToken))
{
if (referenceOpt != null)
......
......@@ -82,12 +82,20 @@ internal partial class SymbolTreeInfo
public Task<IEnumerable<ISymbol>> FindAsync(
SearchQuery query, IAssemblySymbol assembly, SymbolFilter filter, CancellationToken cancellationToken)
{
// All entrypoints to this function are Find functions that are only searching
// for specific strings (i.e. they never do a custom search).
Debug.Assert(query.Kind != SearchKind.Custom);
return this.FindAsync(query, new AsyncLazy<IAssemblySymbol>(assembly), filter, cancellationToken);
}
public async Task<IEnumerable<ISymbol>> FindAsync(
SearchQuery query, AsyncLazy<IAssemblySymbol> lazyAssembly, SymbolFilter filter, CancellationToken cancellationToken)
{
// All entrypoints to this function are Find functions that are only searching
// for specific strings (i.e. they never do a custom search).
Debug.Assert(query.Kind != SearchKind.Custom);
return SymbolFinder.FilterByCriteria(
await FindAsyncWorker(query, lazyAssembly, cancellationToken).ConfigureAwait(false),
filter);
......@@ -95,6 +103,10 @@ internal partial class SymbolTreeInfo
private Task<IEnumerable<ISymbol>> FindAsyncWorker(SearchQuery query, AsyncLazy<IAssemblySymbol> lazyAssembly, CancellationToken cancellationToken)
{
// All entrypoints to this function are Find functions that are only searching
// for specific strings (i.e. they never do a custom search).
Debug.Assert(query.Kind != SearchKind.Custom);
// If the query has a specific string provided, then call into the SymbolTreeInfo
// helpers optimized for lookup based on an exact name.
switch (query.Kind)
......@@ -105,9 +117,6 @@ private Task<IEnumerable<ISymbol>> FindAsyncWorker(SearchQuery query, AsyncLazy<
return this.FindAsync(lazyAssembly, query.Name, ignoreCase: true, cancellationToken: cancellationToken);
case SearchKind.Fuzzy:
return this.FuzzyFindAsync(lazyAssembly, query.Name, cancellationToken);
case SearchKind.Custom:
// Otherwise, we'll have to do a slow linear search over all possible symbols.
return this.FindAsync(lazyAssembly, query.GetPredicate(), cancellationToken);
}
throw new InvalidOperationException();
......@@ -162,28 +171,6 @@ private Task<IEnumerable<ISymbol>> FindAsyncWorker(SearchQuery query, AsyncLazy<
return result;
}
/// <summary>
/// Slow, linear scan of all the symbols in this assembly to look for matches.
/// </summary>
private async Task<IEnumerable<ISymbol>> FindAsync(AsyncLazy<IAssemblySymbol> lazyAssembly, Func<string, bool> predicate, CancellationToken cancellationToken)
{
var result = new List<ISymbol>();
IAssemblySymbol assembly = null;
for (int i = 0, n = _nodes.Length; i < n; i++)
{
cancellationToken.ThrowIfCancellationRequested();
var node = _nodes[i];
if (predicate(node.Name))
{
assembly = assembly ?? await lazyAssembly.GetValueAsync(cancellationToken).ConfigureAwait(false);
result.AddRange(Bind(i, assembly.GlobalNamespace, cancellationToken));
}
}
return result;
}
private static StringComparer GetComparer(bool ignoreCase)
{
return ignoreCase ? CaseInsensitiveComparison.Comparer : StringComparer.Ordinal;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册