diff --git a/src/Features/Core/Portable/CodeFixes/Qualify/AbstractFullyQualifyCodeFixProvider.cs b/src/Features/Core/Portable/CodeFixes/Qualify/AbstractFullyQualifyCodeFixProvider.cs index 33d9f97d6db8226e68252e5c0ad78251ab729d6e..128a94cc9a6926e78249facc9c7fc7a4c90f625c 100644 --- a/src/Features/Core/Portable/CodeFixes/Qualify/AbstractFullyQualifyCodeFixProvider.cs +++ b/src/Features/Core/Portable/CodeFixes/Qualify/AbstractFullyQualifyCodeFixProvider.cs @@ -140,16 +140,18 @@ private async Task ProcessNode(Document document, SyntaxNode node, str var syntaxFacts = project.LanguageServices.GetService(); syntaxFacts.GetNameAndArityOfSimpleName(node, out var name, out var arity); - var symbolAndProjectIds = await DeclarationFinder.FindAllDeclarationsAsync( - project, name, this.IgnoreCase, SymbolFilter.Type, cancellationToken).ConfigureAwait(false); + var symbolAndProjectIds = await DeclarationFinder.FindAllDeclarationsWithNormalQueryAsync( + project, SearchQuery.Create(name, this.IgnoreCase), + SymbolFilter.Type, cancellationToken).ConfigureAwait(false); var symbols = symbolAndProjectIds.SelectAsArray(t => t.Symbol); // also lookup type symbols with the "Attribute" suffix. var inAttributeContext = syntaxFacts.IsAttributeName(node); if (inAttributeContext) { - var attributeSymbolAndProjectIds = await DeclarationFinder.FindAllDeclarationsAsync( - project, name + "Attribute", this.IgnoreCase, SymbolFilter.Type, cancellationToken).ConfigureAwait(false); + var attributeSymbolAndProjectIds = await DeclarationFinder.FindAllDeclarationsWithNormalQueryAsync( + project, SearchQuery.Create(name + "Attribute", this.IgnoreCase), + SymbolFilter.Type, cancellationToken).ConfigureAwait(false); symbols = symbols.Concat(attributeSymbolAndProjectIds.SelectAsArray(t => t.Symbol)); } @@ -189,8 +191,9 @@ private static bool HasValidContainer(ISymbol symbol) return ImmutableArray.Empty; } - var symbolAndProjectIds = await DeclarationFinder.FindAllDeclarationsAsync( - project, name, this.IgnoreCase, SymbolFilter.Namespace, cancellationToken).ConfigureAwait(false); + var symbolAndProjectIds = await DeclarationFinder.FindAllDeclarationsWithNormalQueryAsync( + project, SearchQuery.Create(name, this.IgnoreCase), + SymbolFilter.Namespace, cancellationToken).ConfigureAwait(false); var symbols = symbolAndProjectIds.SelectAsArray(t => t.Symbol); diff --git a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder.cs index 35d4aaa7a8cb472029cca6d1f4e92343442d8828..da95fee4a35c0b3df632442065cc2aacc9d60c36 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Internal.Log; using Microsoft.CodeAnalysis.Shared.Extensions; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.FindSymbols { @@ -16,7 +17,7 @@ internal static partial class DeclarationFinder Project project, SearchQuery query, SymbolFilter filter, ArrayBuilder list, CancellationToken cancellationToken) { - Debug.Assert(query.Kind != SearchKind.Custom); + Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API"); return AddCompilationDeclarationsWithNormalQueryAsync( project, query, filter, list, startingCompilation: null, @@ -33,7 +34,7 @@ internal static partial class DeclarationFinder IAssemblySymbol startingAssembly, CancellationToken cancellationToken) { - Debug.Assert(query.Kind != SearchKind.Custom); + Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API"); using (Logger.LogBlock(FunctionId.SymbolFinder_Project_AddDeclarationsAsync, cancellationToken)) { @@ -67,7 +68,7 @@ internal static partial class DeclarationFinder { // 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); + Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API"); using (Logger.LogBlock(FunctionId.SymbolFinder_Assembly_AddDeclarationsAsync, cancellationToken)) { diff --git a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs index d836071168c2dbef73767a6f1946bdf6eea5b8a8..553dc3c0db5272b96b3cd54aa2f981f031d29052 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/Declarations/DeclarationFinder_AllDeclarations.cs @@ -1,12 +1,10 @@ // 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 System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.Internal.Log; using Microsoft.CodeAnalysis.Remote; using Microsoft.CodeAnalysis.Shared.Extensions; using Roslyn.Utilities; @@ -18,52 +16,12 @@ namespace Microsoft.CodeAnalysis.FindSymbols internal static partial class DeclarationFinder { - /// - /// Find the declared symbols from either source, referenced projects or metadata assemblies with the specified name. - /// - internal static async Task> FindAllDeclarationsAsync( - Project project, string name, bool ignoreCase, CancellationToken cancellationToken) - { - if (name == null) - { - throw new ArgumentNullException(nameof(name)); - } - - if (string.IsNullOrWhiteSpace(name)) - { - return ImmutableArray.Empty; - } - - return await FindAllDeclarationsWithNormalQueryAsync( - project, SearchQuery.Create(name, ignoreCase), SymbolFilter.All, cancellationToken: cancellationToken).ConfigureAwait(false); - } - - /// - /// Find the declared symbols from either source, referenced projects or metadata assemblies with the specified name. - /// - internal static async Task> FindAllDeclarationsAsync( - Project project, string name, bool ignoreCase, SymbolFilter filter, CancellationToken cancellationToken = default(CancellationToken)) - { - if (name == null) - { - throw new ArgumentNullException(nameof(name)); - } - - if (string.IsNullOrWhiteSpace(name)) - { - return ImmutableArray.Empty; - } - - return await FindAllDeclarationsWithNormalQueryAsync( - project, SearchQuery.Create(name, ignoreCase), filter, cancellationToken: cancellationToken).ConfigureAwait(false); - } - - internal static async Task> FindAllDeclarationsWithNormalQueryAsync( + public static async Task> FindAllDeclarationsWithNormalQueryAsync( 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); + Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API"); if (project == null) { diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_AllDeclarations.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_AllDeclarations.cs index b8bc6b3b19bb07f382b62af87f1ecce355dcb06c..9f016feb82cf3acd6a763385c9ecfe2f4aa296f9 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_AllDeclarations.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations_AllDeclarations.cs @@ -1,14 +1,8 @@ // 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 System; using System.Collections.Generic; -using System.Collections.Immutable; -using System.Diagnostics; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.Internal.Log; -using Microsoft.CodeAnalysis.Shared.Extensions; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.FindSymbols { @@ -20,8 +14,8 @@ public static partial class SymbolFinder public static async Task> FindDeclarationsAsync( Project project, string name, bool ignoreCase, CancellationToken cancellationToken = default(CancellationToken)) { - var declarations = await DeclarationFinder.FindAllDeclarationsAsync( - project, name, ignoreCase, cancellationToken).ConfigureAwait(false); + var declarations = await DeclarationFinder.FindAllDeclarationsWithNormalQueryAsync( + project, SearchQuery.Create(name, ignoreCase), SymbolFilter.All, cancellationToken).ConfigureAwait(false); return declarations.SelectAsArray(t => t.Symbol); } @@ -31,8 +25,8 @@ public static partial class SymbolFinder public static async Task> FindDeclarationsAsync( Project project, string name, bool ignoreCase, SymbolFilter filter, CancellationToken cancellationToken = default(CancellationToken)) { - var declarations = await DeclarationFinder.FindAllDeclarationsAsync( - project, name, ignoreCase, filter, cancellationToken).ConfigureAwait(false); + var declarations = await DeclarationFinder.FindAllDeclarationsWithNormalQueryAsync( + project, SearchQuery.Create(name, ignoreCase), filter, cancellationToken).ConfigureAwait(false); return declarations.SelectAsArray(t => t.Symbol); } } diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs index cb0d3d33d0c1339d69e08543abe198d794288458..0e8daa8c9ad1bbe46bc928f305154212bd1edb0c 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs @@ -119,7 +119,7 @@ internal partial class SymbolTreeInfo { // 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); + Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API"); return this.FindAsync( query, new AsyncLazy(assembly), @@ -132,7 +132,7 @@ internal partial class SymbolTreeInfo { // 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); + Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API"); var symbols = await FindAsyncWorker(query, lazyAssembly, cancellationToken).ConfigureAwait(false); @@ -146,7 +146,7 @@ internal partial class SymbolTreeInfo { // 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); + Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API"); // If the query has a specific string provided, then call into the SymbolTreeInfo // helpers optimized for lookup based on an exact name.