提交 04fec0bb 编写于 作者: C CyrusNajmabadi

Use immutable arrays in more places.

上级 bff8f821
......@@ -421,6 +421,11 @@ public void AddRange(ImmutableArray<T> items, int length)
_builder.AddRange(items, length);
}
public void AddRange<S>(ImmutableArray<S> items) where S : class, T
{
AddRange(ImmutableArray<T>.CastUp(items));
}
public void AddRange(T[] items, int start, int length)
{
for (int i = start, end = start + length; i < end; i++)
......
......@@ -150,7 +150,8 @@ private static bool IsCrefQualifiedNameContext(SyntaxToken token)
&& token.Parent.IsKind(SyntaxKind.QualifiedCref);
}
private static IEnumerable<ISymbol> GetSymbols(SyntaxToken token, SemanticModel semanticModel, CancellationToken cancellationToken)
private static ImmutableArray<ISymbol> GetSymbols(
SyntaxToken token, SemanticModel semanticModel, CancellationToken cancellationToken)
{
if (IsCrefStartContext(token))
{
......@@ -165,15 +166,14 @@ private static IEnumerable<ISymbol> GetSymbols(SyntaxToken token, SemanticModel
return GetQualifiedSymbols((QualifiedCrefSyntax)token.Parent, token, semanticModel, cancellationToken);
}
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
private static IEnumerable<ISymbol> GetUnqualifiedSymbols(SyntaxToken token, SemanticModel semanticModel, CancellationToken cancellationToken)
private static ImmutableArray<ISymbol> GetUnqualifiedSymbols(
SyntaxToken token, SemanticModel semanticModel, CancellationToken cancellationToken)
{
foreach (var symbol in semanticModel.LookupSymbols(token.SpanStart))
{
yield return symbol;
}
var result = ArrayBuilder<ISymbol>.GetInstance();
result.AddRange(semanticModel.LookupSymbols(token.SpanStart));
// LookupSymbols doesn't return indexers or operators because they can't be referred to by name.
// So, try to find the innermost type declaration and return its operators and indexers
......@@ -190,34 +190,34 @@ private static IEnumerable<ISymbol> GetUnqualifiedSymbols(SyntaxToken token, Sem
if ((member.IsIndexer() || member.IsUserDefinedOperator()) &&
member.IsAccessibleWithin(type))
{
yield return member;
result.Add(member);
}
}
}
}
}
return result.ToImmutableAndFree();
}
private static IEnumerable<ISymbol> GetQualifiedSymbols(QualifiedCrefSyntax parent, SyntaxToken token, SemanticModel semanticModel, CancellationToken cancellationToken)
private static ImmutableArray<ISymbol> GetQualifiedSymbols(
QualifiedCrefSyntax parent, SyntaxToken token, SemanticModel semanticModel, CancellationToken cancellationToken)
{
var leftType = semanticModel.GetTypeInfo(parent.Container, cancellationToken).Type;
var leftSymbol = semanticModel.GetSymbolInfo(parent.Container, cancellationToken).Symbol;
var container = (leftSymbol ?? leftType) as INamespaceOrTypeSymbol;
foreach (var symbol in semanticModel.LookupSymbols(token.SpanStart, container))
{
yield return symbol;
}
var result = ArrayBuilder<ISymbol>.GetInstance();
result.AddRange(semanticModel.LookupSymbols(token.SpanStart, container));
var namedTypeContainer = container as INamedTypeSymbol;
if (namedTypeContainer != null)
{
foreach (var instanceConstructor in namedTypeContainer.InstanceConstructors)
{
yield return instanceConstructor;
}
result.AddRange(namedTypeContainer.InstanceConstructors);
}
return result.ToImmutableAndFree();
}
private static TextSpan GetCompletionItemSpan(SourceText text, int position)
......
......@@ -82,7 +82,7 @@ public override async Task ProvideCompletionsAsync(CompletionContext context)
var members = semanticModel.LookupSymbols(
position: name.SpanStart,
container: symbol)
.Where(s => !s.IsStatic)
.WhereAsArray(s => !s.IsStatic)
.FilterToVisibleAndBrowsableSymbols(options.GetOption(CompletionOptions.HideAdvancedMembers, semanticModel.Language), semanticModel.Compilation);
// We're going to create a entry for each one, including the signature
......
......@@ -56,7 +56,7 @@ protected override async Task<SyntaxContext> CreateContext(Document document, in
return CSharpSyntaxContext.CreateContext(document.Project.Solution.Workspace, semanticModel, position, cancellationToken);
}
protected override async Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
protected override async Task<ImmutableArray<ISymbol>> GetPreselectedSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
{
var result = await base.GetPreselectedSymbolsWorker(context, position, options, cancellationToken).ConfigureAwait(false);
if (result.Any())
......@@ -65,7 +65,7 @@ protected override async Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(
var alias = await type.FindApplicableAlias(position, context.SemanticModel, cancellationToken).ConfigureAwait(false);
if (alias != null)
{
return SpecializedCollections.SingletonEnumerable(alias);
return ImmutableArray.Create(alias);
}
}
......
......@@ -20,9 +20,10 @@ namespace Microsoft.CodeAnalysis.CSharp.Completion.Providers
{
internal partial class SymbolCompletionProvider : AbstractRecommendationServiceBasedCompletionProvider
{
protected override Task<IEnumerable<ISymbol>> GetSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
protected override Task<ImmutableArray<ISymbol>> GetSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
{
return Recommender.GetRecommendedSymbolsAtPositionAsync(context.SemanticModel, position, context.Workspace, options, cancellationToken);
return Recommender.GetImmutableRecommendedSymbolsAtPositionAsync(
context.SemanticModel, position, context.Workspace, options, cancellationToken);
}
protected override bool IsInstrinsic(ISymbol s)
......
......@@ -82,7 +82,7 @@ protected override async Task<SignatureHelpItems> GetItemsWorkerAsync(Document d
var symbolDisplayService = document.Project.LanguageServices.GetService<ISymbolDisplayService>();
var accessibleConstructors = attributeType.InstanceConstructors
.Where(c => c.IsAccessibleWithin(within))
.WhereAsArray(c => c.IsAccessibleWithin(within))
.FilterToVisibleAndBrowsableSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation)
.Sort(symbolDisplayService, semanticModel, attribute.SpanStart);
......
......@@ -90,8 +90,8 @@ protected override async Task<SignatureHelpItems> GetItemsWorkerAsync(Document d
var symbolDisplayService = document.Project.LanguageServices.GetService<ISymbolDisplayService>();
var accessibleConstructors = type.InstanceConstructors
.Where(c => c.IsAccessibleWithin(within))
.Where(c => c.IsEditorBrowsable(document.ShouldHideAdvancedMembers(), semanticModel.Compilation))
.WhereAsArray(c => c.IsAccessibleWithin(within))
.WhereAsArray(c => c.IsEditorBrowsable(document.ShouldHideAdvancedMembers(), semanticModel.Compilation))
.Sort(symbolDisplayService, semanticModel, constructorInitializer.SpanStart);
if (!accessibleConstructors.Any())
......@@ -104,7 +104,7 @@ protected override async Task<SignatureHelpItems> GetItemsWorkerAsync(Document d
var textSpan = SignatureHelpUtilities.GetSignatureHelpSpan(constructorInitializer.ArgumentList);
var syntaxFacts = document.GetLanguageService<ISyntaxFactsService>();
return CreateSignatureHelpItems(accessibleConstructors.Select(c =>
return CreateSignatureHelpItems(accessibleConstructors.SelectAsArray(c =>
Convert(c, constructorInitializer.ArgumentList.OpenParenToken, semanticModel, symbolDisplayService, anonymousTypeDisplayService, documentationCommentFormattingService, cancellationToken)).ToList(),
textSpan, GetCurrentArgumentState(root, position, syntaxFacts, textSpan, cancellationToken));
}
......
// 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.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Threading;
......@@ -77,7 +78,7 @@ protected override async Task<SignatureHelpItems> GetItemsWorkerAsync(Document d
return null;
}
IEnumerable<IPropertySymbol> indexers;
ImmutableArray<IPropertySymbol> indexers;
ITypeSymbol expressionType;
if (!TryGetIndexers(position, semanticModel, expression, cancellationToken, out indexers, out expressionType) &&
......@@ -92,7 +93,8 @@ protected override async Task<SignatureHelpItems> GetItemsWorkerAsync(Document d
return null;
}
var accessibleIndexers = indexers.Where(m => m.IsAccessibleWithin(within, throughTypeOpt: expressionType));
var accessibleIndexers = indexers.WhereAsArray(
m => m.IsAccessibleWithin(within, throughTypeOpt: expressionType));
if (!accessibleIndexers.Any())
{
return null;
......@@ -182,9 +184,13 @@ public override SignatureHelpState GetCurrentArgumentState(SyntaxNode root, int
return SignatureHelpUtilities.GetSignatureHelpState(argumentList, position);
}
private bool TryGetComIndexers(SemanticModel semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken, out IEnumerable<IPropertySymbol> indexers, out ITypeSymbol expressionType)
private bool TryGetComIndexers(
SemanticModel semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken,
out ImmutableArray<IPropertySymbol> indexers, out ITypeSymbol expressionType)
{
indexers = semanticModel.GetMemberGroup(expression, cancellationToken).OfType<IPropertySymbol>();
indexers = semanticModel.GetMemberGroup(expression, cancellationToken)
.OfType<IPropertySymbol>()
.ToImmutableArray();
if (indexers.Any() && expression is MemberAccessExpressionSyntax)
{
......@@ -196,13 +202,15 @@ private bool TryGetComIndexers(SemanticModel semanticModel, ExpressionSyntax exp
return false;
}
private bool TryGetIndexers(int position, SemanticModel semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken, out IEnumerable<IPropertySymbol> indexers, out ITypeSymbol expressionType)
private bool TryGetIndexers(
int position, SemanticModel semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken,
out ImmutableArray<IPropertySymbol> indexers, out ITypeSymbol expressionType)
{
expressionType = semanticModel.GetTypeInfo(expression, cancellationToken).Type;
if (expressionType == null)
{
indexers = null;
indexers = ImmutableArray<IPropertySymbol>.Empty;
return false;
}
......@@ -214,7 +222,9 @@ private bool TryGetIndexers(int position, SemanticModel semanticModel, Expressio
?? semanticModel.GetSymbolInfo(expression).GetAnySymbol().GetSymbolType();
}
indexers = semanticModel.LookupSymbols(position, expressionType, WellKnownMemberNames.Indexer).OfType<IPropertySymbol>();
indexers = semanticModel.LookupSymbols(position, expressionType, WellKnownMemberNames.Indexer)
.OfType<IPropertySymbol>()
.ToImmutableArray();
return true;
}
......
......@@ -115,8 +115,8 @@ protected override async Task<SignatureHelpItems> GetItemsWorkerAsync(Document d
var symbolDisplayService = document.Project.LanguageServices.GetService<ISymbolDisplayService>();
var accessibleSymbols =
symbols.Where(s => s.GetArity() > 0)
.Where(s => s is INamedTypeSymbol || s is IMethodSymbol)
symbols.WhereAsArray(s => s.GetArity() > 0)
.WhereAsArray(s => s is INamedTypeSymbol || s is IMethodSymbol)
.FilterToVisibleAndBrowsableSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation)
.Sort(symbolDisplayService, semanticModel, genericIdentifier.SpanStart);
......
// 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.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Threading;
......@@ -75,6 +76,7 @@ protected override async Task<SignatureHelpItems> GetItemsWorkerAsync(Document d
var symbolDisplayService = document.Project.LanguageServices.GetService<ISymbolDisplayService>();
var methodGroup = semanticModel.GetMemberGroup(invocationExpression.Expression, cancellationToken)
.OfType<IMethodSymbol>()
.ToImmutableArray()
.FilterToVisibleAndBrowsableSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation);
// try to bind to the actual method
......@@ -84,10 +86,11 @@ protected override async Task<SignatureHelpItems> GetItemsWorkerAsync(Document d
// if the symbol could be bound, replace that item in the symbol list
if (matchedMethodSymbol != null && matchedMethodSymbol.IsGenericMethod)
{
methodGroup = methodGroup.Select(m => matchedMethodSymbol.OriginalDefinition == m ? matchedMethodSymbol : m);
methodGroup = methodGroup.SelectAsArray(m => matchedMethodSymbol.OriginalDefinition == m ? matchedMethodSymbol : m);
}
methodGroup = methodGroup.Sort(symbolDisplayService, semanticModel, invocationExpression.SpanStart);
methodGroup = methodGroup.Sort(
symbolDisplayService, semanticModel, invocationExpression.SpanStart);
var expressionType = semanticModel.GetTypeInfo(invocationExpression.Expression, cancellationToken).Type as INamedTypeSymbol;
......
......@@ -27,12 +27,12 @@ internal partial class ObjectCreationExpressionSignatureHelpProvider
CancellationToken cancellationToken)
{
var accessibleConstructors = normalType.InstanceConstructors
.Where(c => c.IsAccessibleWithin(within))
.Where(s => s.IsEditorBrowsable(document.ShouldHideAdvancedMembers(), semanticModel.Compilation))
.WhereAsArray(c => c.IsAccessibleWithin(within))
.WhereAsArray(s => s.IsEditorBrowsable(document.ShouldHideAdvancedMembers(), semanticModel.Compilation))
.Sort(symbolDisplayService, semanticModel, objectCreationExpression.SpanStart);
return accessibleConstructors.Select(c =>
ConvertNormalTypeConstructor(c, objectCreationExpression, semanticModel, symbolDisplayService, anonymousTypeDisplayService, documentationCommentFormattingService, cancellationToken)).ToList();
return accessibleConstructors.SelectAsArray(c =>
ConvertNormalTypeConstructor(c, objectCreationExpression, semanticModel, symbolDisplayService, anonymousTypeDisplayService, documentationCommentFormattingService, cancellationToken));
}
private SignatureHelpItem ConvertNormalTypeConstructor(
......
......@@ -41,17 +41,18 @@ internal abstract class AbstractObjectCreationCompletionProvider : AbstractSymbo
rules: GetCompletionItemRules(symbols, context));
}
protected override Task<IEnumerable<ISymbol>> GetSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
protected override Task<ImmutableArray<ISymbol>> GetSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyEnumerable<ISymbol>();
return SpecializedTasks.EmptyImmutableArray<ISymbol>();
}
protected override Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
protected override Task<ImmutableArray<ISymbol>> GetPreselectedSymbolsWorker(
SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
{
var newExpression = this.GetObjectCreationNewExpression(context.SyntaxTree, position, cancellationToken);
if (newExpression == null)
{
return SpecializedTasks.EmptyEnumerable<ISymbol>();
return SpecializedTasks.EmptyImmutableArray<ISymbol>();
}
var typeInferenceService = context.GetLanguageService<ITypeInferenceService>();
......@@ -69,7 +70,7 @@ protected override Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(Syntax
if (type == null)
{
return SpecializedTasks.EmptyEnumerable<ISymbol>();
return SpecializedTasks.EmptyImmutableArray<ISymbol>();
}
// Unwrap nullable
......@@ -80,17 +81,17 @@ protected override Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(Syntax
if (type.SpecialType == SpecialType.System_Void)
{
return SpecializedTasks.EmptyEnumerable<ISymbol>();
return SpecializedTasks.EmptyImmutableArray<ISymbol>();
}
if (type.ContainsAnonymousType())
{
return SpecializedTasks.EmptyEnumerable<ISymbol>();
return SpecializedTasks.EmptyImmutableArray<ISymbol>();
}
if (!type.CanBeReferencedByName)
{
return SpecializedTasks.EmptyEnumerable<ISymbol>();
return SpecializedTasks.EmptyImmutableArray<ISymbol>();
}
// Normally the user can't say things like "new IList". Except for "IList[] x = new |".
......@@ -103,22 +104,22 @@ protected override Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(Syntax
type.TypeKind == TypeKind.Dynamic ||
type.IsAbstract)
{
return SpecializedTasks.EmptyEnumerable<ISymbol>();
return SpecializedTasks.EmptyImmutableArray<ISymbol>();
}
if (type.TypeKind == TypeKind.TypeParameter &&
!((ITypeParameterSymbol)type).HasConstructorConstraint)
{
return SpecializedTasks.EmptyEnumerable<ISymbol>();
return SpecializedTasks.EmptyImmutableArray<ISymbol>();
}
}
if (!type.IsEditorBrowsable(options.GetOption(RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language), context.SemanticModel.Compilation))
{
return SpecializedTasks.EmptyEnumerable<ISymbol>();
return SpecializedTasks.EmptyImmutableArray<ISymbol>();
}
return Task.FromResult(SpecializedCollections.SingletonEnumerable((ISymbol)type));
return Task.FromResult(ImmutableArray.Create((ISymbol)type));
}
protected override ValueTuple<string, string> GetDisplayAndInsertionText(
......
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
......@@ -14,13 +15,13 @@ namespace Microsoft.CodeAnalysis.Completion.Providers
{
internal abstract class AbstractRecommendationServiceBasedCompletionProvider : AbstractSymbolCompletionProvider
{
protected override Task<IEnumerable<ISymbol>> GetSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
protected override Task<ImmutableArray<ISymbol>> GetSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
{
var recommender = context.GetLanguageService<IRecommendationService>();
return recommender.GetRecommendedSymbolsAtPositionAsync(context.Workspace, context.SemanticModel, position, options, cancellationToken);
}
protected override async Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
protected override async Task<ImmutableArray<ISymbol>> GetPreselectedSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
{
var recommender = context.GetLanguageService<IRecommendationService>();
var typeInferrer = context.GetLanguageService<ITypeInferenceService>();
......@@ -30,7 +31,7 @@ protected override async Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(
.ToSet();
if (inferredTypes.Count == 0)
{
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
var symbols = await recommender.GetRecommendedSymbolsAtPositionAsync(
......@@ -41,7 +42,7 @@ protected override async Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(
cancellationToken).ConfigureAwait(false);
// Don't preselect intrinsic type symbols so we can preselect their keywords instead.
return symbols.Where(s => inferredTypes.Contains(GetSymbolType(s)) && !IsInstrinsic(s));
return symbols.WhereAsArray(s => inferredTypes.Contains(GetSymbolType(s)) && !IsInstrinsic(s));
}
private ITypeSymbol GetSymbolType(ISymbol symbol)
......
......@@ -146,11 +146,11 @@ protected virtual string GetFilterText(ISymbol symbol, string displayText, Synta
: symbol.Name;
}
protected abstract Task<IEnumerable<ISymbol>> GetSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken);
protected abstract Task<ImmutableArray<ISymbol>> GetSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken);
protected virtual Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
protected virtual Task<ImmutableArray<ISymbol>> GetPreselectedSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyEnumerable<ISymbol>();
return SpecializedTasks.EmptyImmutableArray<ISymbol>();
}
public override async Task ProvideCompletionsAsync(CompletionContext context)
......@@ -239,14 +239,14 @@ protected virtual Task<bool> IsSemanticTriggerCharacterAsync(Document document,
return SpecializedTasks.True;
}
private Task<IEnumerable<ISymbol>> GetSymbolsWorker(int position, bool preselect, SyntaxContext context, OptionSet options, CancellationToken cancellationToken)
private Task<ImmutableArray<ISymbol>> GetSymbolsWorker(int position, bool preselect, SyntaxContext context, OptionSet options, CancellationToken cancellationToken)
{
return preselect
? GetPreselectedSymbolsWorker(context, position, options, cancellationToken)
: GetSymbolsWorker(context, position, options, cancellationToken);
}
private HashSet<ISymbol> UnionSymbols(List<Tuple<DocumentId, SyntaxContext, IEnumerable<ISymbol>>> linkedContextSymbolLists, out Dictionary<ISymbol, SyntaxContext> originDictionary)
private HashSet<ISymbol> UnionSymbols(List<Tuple<DocumentId, SyntaxContext, ImmutableArray<ISymbol>>> linkedContextSymbolLists, out Dictionary<ISymbol, SyntaxContext> originDictionary)
{
// To correctly map symbols back to their SyntaxContext, we do care about assembly identity.
originDictionary = new Dictionary<ISymbol, SyntaxContext>(LinkedFilesSymbolEquivalenceComparer.Instance);
......@@ -269,9 +269,9 @@ private HashSet<ISymbol> UnionSymbols(List<Tuple<DocumentId, SyntaxContext, IEnu
return set;
}
protected async Task<List<Tuple<DocumentId, SyntaxContext, IEnumerable<ISymbol>>>> GetPerContextSymbols(Document document, int position, OptionSet options, IEnumerable<DocumentId> relatedDocuments, bool preselect, CancellationToken cancellationToken)
protected async Task<List<Tuple<DocumentId, SyntaxContext, ImmutableArray<ISymbol>>>> GetPerContextSymbols(Document document, int position, OptionSet options, IEnumerable<DocumentId> relatedDocuments, bool preselect, CancellationToken cancellationToken)
{
var perContextSymbols = new List<Tuple<DocumentId, SyntaxContext, IEnumerable<ISymbol>>>();
var perContextSymbols = new List<Tuple<DocumentId, SyntaxContext, ImmutableArray<ISymbol>>>();
foreach (var relatedDocumentId in relatedDocuments)
{
var relatedDocument = document.Project.Solution.GetDocument(relatedDocumentId);
......@@ -280,7 +280,7 @@ private HashSet<ISymbol> UnionSymbols(List<Tuple<DocumentId, SyntaxContext, IEnu
if (IsCandidateProject(context, cancellationToken))
{
var symbols = await GetSymbolsWorker(position, preselect, context, options, cancellationToken).ConfigureAwait(false);
perContextSymbols.Add(Tuple.Create(relatedDocument.Id, context, symbols ?? SpecializedCollections.EmptyEnumerable<ISymbol>()));
perContextSymbols.Add(Tuple.Create(relatedDocument.Id, context, symbols));
}
}
......@@ -319,7 +319,9 @@ private Task<SyntaxContext> GetOrCreateContext(Document document, int position,
/// <param name="expectedSymbols">The symbols recommended in the active context.</param>
/// <param name="linkedContextSymbolLists">The symbols recommended in linked documents</param>
/// <returns>The list of projects each recommended symbol did NOT appear in.</returns>
protected Dictionary<ISymbol, List<ProjectId>> FindSymbolsMissingInLinkedContexts(HashSet<ISymbol> expectedSymbols, IEnumerable<Tuple<DocumentId, SyntaxContext, IEnumerable<ISymbol>>> linkedContextSymbolLists)
protected Dictionary<ISymbol, List<ProjectId>> FindSymbolsMissingInLinkedContexts(
HashSet<ISymbol> expectedSymbols,
IEnumerable<Tuple<DocumentId, SyntaxContext, ImmutableArray<ISymbol>>> linkedContextSymbolLists)
{
var missingSymbols = new Dictionary<ISymbol, List<ProjectId>>(LinkedFilesSymbolEquivalenceComparer.Instance);
......
......@@ -13,8 +13,8 @@ namespace Microsoft.CodeAnalysis.Shared.Extensions
{
internal partial class ISymbolExtensions2
{
public static IList<TSymbol> Sort<TSymbol>(
this IEnumerable<TSymbol> symbols,
public static ImmutableArray<TSymbol> Sort<TSymbol>(
this ImmutableArray<TSymbol> symbols,
ISymbolDisplayService symbolDisplayService,
SemanticModel semanticModel,
int position)
......@@ -23,7 +23,8 @@ internal partial class ISymbolExtensions2
var symbolToParameterTypeNames = new ConcurrentDictionary<TSymbol, string[]>();
Func<TSymbol, string[]> getParameterTypeNames = s => GetParameterTypeNames(s, symbolDisplayService, semanticModel, position);
return symbols.OrderBy((s1, s2) => Compare(s1, s2, symbolToParameterTypeNames, getParameterTypeNames)).ToList();
return symbols.OrderBy((s1, s2) => Compare(s1, s2, symbolToParameterTypeNames, getParameterTypeNames))
.ToImmutableArray();
}
private static INamedTypeSymbol GetNamedType(ITypeSymbol type)
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Completion
Imports Microsoft.CodeAnalysis.Completion.Providers
......@@ -12,36 +13,36 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
Friend Class CompletionListTagCompletionProvider
Inherits EnumCompletionProvider
Protected Overrides Function GetPreselectedSymbolsWorker(context As SyntaxContext, position As Integer, options As OptionSet, cancellationToken As CancellationToken) As Task(Of IEnumerable(Of ISymbol))
Protected Overrides Function GetPreselectedSymbolsWorker(context As SyntaxContext, position As Integer, options As OptionSet, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of ISymbol))
If context.SyntaxTree.IsObjectCreationTypeContext(position, cancellationToken) OrElse
context.SyntaxTree.IsInNonUserCode(position, cancellationToken) Then
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End If
Dim typeInferenceService = context.GetLanguageService(Of ITypeInferenceService)()
Dim inferredType = typeInferenceService.InferType(context.SemanticModel, position, objectAsDefault:=True, cancellationToken:=cancellationToken)
If inferredType Is Nothing Then
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End If
Dim within = context.SemanticModel.GetEnclosingNamedType(position, cancellationToken)
Dim completionListType = GetCompletionListType(inferredType, within, context.SemanticModel.Compilation)
If completionListType Is Nothing Then
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End If
Dim hideAdvancedMembers = options.GetOption(CodeAnalysis.Recommendations.RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language)
Return Task.FromResult(completionListType.GetAccessibleMembersInThisAndBaseTypes(Of ISymbol)(within) _
.Where(Function(m) m.MatchesKind(SymbolKind.Field, SymbolKind.Property) AndAlso
.WhereAsArray(Function(m) m.MatchesKind(SymbolKind.Field, SymbolKind.Property) AndAlso
m.IsStatic AndAlso
m.IsAccessibleWithin(within) AndAlso
m.IsEditorBrowsable(hideAdvancedMembers, context.SemanticModel.Compilation)))
End Function
Protected Overrides Function GetSymbolsWorker(context As SyntaxContext, position As Integer, options As OptionSet, cancellationToken As CancellationToken) As Task(Of IEnumerable(Of ISymbol))
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Protected Overrides Function GetSymbolsWorker(context As SyntaxContext, position As Integer, options As OptionSet, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of ISymbol))
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End Function
Private Function GetCompletionListType(inferredType As ITypeSymbol, within As INamedTypeSymbol, compilation As Compilation) As ITypeSymbol
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Completion
Imports Microsoft.CodeAnalysis.Completion.Providers
......@@ -13,23 +14,25 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
Partial Friend Class EnumCompletionProvider
Inherits AbstractSymbolCompletionProvider
Protected Overrides Function GetPreselectedSymbolsWorker(context As SyntaxContext, position As Integer, options As OptionSet, cancellationToken As CancellationToken) As Task(Of IEnumerable(Of ISymbol))
Protected Overrides Function GetPreselectedSymbolsWorker(
context As SyntaxContext, position As Integer, options As OptionSet, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of ISymbol))
If context.SyntaxTree.IsInNonUserCode(context.Position, cancellationToken) Then
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End If
' This providers provides fully qualified names, eg "DayOfWeek.Monday"
' Don't run after dot because SymbolCompletionProvider will provide
' members in situations like Dim x = DayOfWeek.$$
If context.TargetToken.IsKind(SyntaxKind.DotToken) Then
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End If
Dim typeInferenceService = context.GetLanguageService(Of ITypeInferenceService)()
Dim enumType = typeInferenceService.InferType(context.SemanticModel, position, objectAsDefault:=True, cancellationToken:=cancellationToken)
If enumType.TypeKind <> TypeKind.Enum Then
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End If
Dim hideAdvancedMembers = options.GetOption(CodeAnalysis.Recommendations.RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language)
......@@ -40,19 +43,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
Return m.Kind = SymbolKind.Field AndAlso
DirectCast(m, IFieldSymbol).IsConst AndAlso
m.IsEditorBrowsable(hideAdvancedMembers, context.SemanticModel.Compilation)
End Function)
End Function).ToImmutableArray()
Return Task.FromResult(Of IEnumerable(Of ISymbol))(result)
Return Task.FromResult(result)
End Function
Protected Overrides Function GetSymbolsWorker(context As SyntaxContext, position As Integer, options As OptionSet, cancellationToken As CancellationToken) As Task(Of IEnumerable(Of ISymbol))
Protected Overrides Function GetSymbolsWorker(
context As SyntaxContext, position As Integer, options As OptionSet, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of ISymbol))
If context.SyntaxTree.IsInNonUserCode(context.Position, cancellationToken) OrElse
context.SyntaxTree.IsInSkippedText(position, cancellationToken) Then
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End If
If context.TargetToken.IsKind(SyntaxKind.DotToken) Then
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End If
Dim typeInferenceService = context.GetLanguageService(Of ITypeInferenceService)()
......@@ -60,15 +65,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
Dim enumType = typeInferenceService.InferType(context.SemanticModel, position, objectAsDefault:=True, cancellationToken:=cancellationToken)
If enumType.TypeKind <> TypeKind.Enum Then
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End If
Dim hideAdvancedMembers = options.GetOption(CodeAnalysis.Recommendations.RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language)
Dim otherSymbols = context.SemanticModel.LookupSymbols(position).Where(Function(s) s.MatchesKind(SymbolKind.Field, SymbolKind.Local, SymbolKind.Parameter, SymbolKind.Property) AndAlso
s.IsEditorBrowsable(hideAdvancedMembers, context.SemanticModel.Compilation))
Dim otherSymbols = context.SemanticModel.LookupSymbols(position).WhereAsArray(
Function(s) s.MatchesKind(SymbolKind.Field, SymbolKind.Local, SymbolKind.Parameter, SymbolKind.Property) AndAlso
s.IsEditorBrowsable(hideAdvancedMembers, context.SemanticModel.Compilation))
Dim otherInstances = otherSymbols.Where(Function(s) enumType Is GetTypeFromSymbol(s))
Dim otherInstances = otherSymbols.WhereAsArray(Function(s) enumType Is GetTypeFromSymbol(s))
Return Task.FromResult(otherInstances.Concat(enumType))
End Function
......
......@@ -8,21 +8,22 @@ Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Microsoft.CodeAnalysis.VisualBasic.Extensions.ContextQuery
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.CodeAnalysis.Shared.Extensions.ContextQuery
Imports System.Collections.Immutable
Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
Partial Friend Class HandlesClauseCompletionProvider
Inherits AbstractSymbolCompletionProvider
Protected Overrides Function GetSymbolsWorker(context As SyntaxContext, position As Integer, options As OptionSet, cancellationToken As CancellationToken) As Task(Of IEnumerable(Of ISymbol))
Protected Overrides Function GetSymbolsWorker(context As SyntaxContext, position As Integer, options As OptionSet, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of ISymbol))
Dim vbContext = DirectCast(context, VisualBasicSyntaxContext)
If context.SyntaxTree.IsInNonUserCode(position, cancellationToken) OrElse
context.SyntaxTree.IsInSkippedText(position, cancellationToken) Then
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End If
If context.TargetToken.Kind = SyntaxKind.None Then
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End If
' Handles or a comma
......@@ -36,7 +37,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
Return Task.FromResult(LookUpEventsAsync(vbContext, context.TargetToken, cancellationToken))
End If
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End Function
Friend Overrides Function IsInsertionTrigger(text As SourceText, characterPosition As Integer, options As OptionSet) As Boolean
......@@ -47,7 +48,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
context As VisualBasicSyntaxContext,
token As SyntaxToken,
cancellationToken As CancellationToken
) As IEnumerable(Of ISymbol)
) As ImmutableArray(Of ISymbol)
Dim containingSymbol = context.SemanticModel.GetEnclosingSymbol(context.Position, cancellationToken)
Dim containingType = TryCast(containingSymbol, ITypeSymbol)
......@@ -58,19 +59,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
If containingType Is Nothing Then
' We've somehow failed to find a containing type.
Return SpecializedCollections.EmptyEnumerable(Of ISymbol)()
Return ImmutableArray(Of ISymbol).Empty
End If
' Instance or shared variables declared WithEvents
Dim symbols = context.SemanticModel.LookupSymbols(context.Position, DirectCast(containingType, INamespaceOrTypeSymbol), includeReducedExtensionMethods:=True)
Return symbols.Where(Function(s) IsWithEvents(s))
Return symbols.WhereAsArray(Function(s) IsWithEvents(s))
End Function
Private Function LookUpEventsAsync(
context As VisualBasicSyntaxContext,
token As SyntaxToken,
cancellationToken As CancellationToken
) As IEnumerable(Of ISymbol)
) As ImmutableArray(Of ISymbol)
' We came up on a dot, so the previous token will tell us in which object we should find events.
Dim containingSymbol = context.SemanticModel.GetEnclosingSymbol(context.Position, cancellationToken)
......@@ -82,29 +83,35 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
If containingType Is Nothing Then
' We've somehow failed to find a containing type.
Return SpecializedCollections.EmptyEnumerable(Of ISymbol)()
Return ImmutableArray(Of ISymbol).Empty
End If
Dim result As IEnumerable(Of ISymbol) = Nothing
Dim result = ImmutableArray(Of IEventSymbol).Empty
Dim previousToken = token.GetPreviousToken()
Select Case previousToken.Kind
Case SyntaxKind.MeKeyword, SyntaxKind.MyClassKeyword
result = context.SemanticModel.LookupSymbols(context.Position, containingType).OfType(Of IEventSymbol)()
result = context.SemanticModel.LookupSymbols(context.Position, containingType).
OfType(Of IEventSymbol)().
ToImmutableArray()
Case SyntaxKind.MyBaseKeyword
result = context.SemanticModel.LookupSymbols(context.Position, containingType.BaseType).OfType(Of IEventSymbol)()
result = context.SemanticModel.LookupSymbols(context.Position, containingType.BaseType).
OfType(Of IEventSymbol)().
ToImmutableArray()
Case SyntaxKind.IdentifierToken
' We must be looking at a WithEvents property.
Dim symbolInfo = context.SemanticModel.GetSymbolInfo(previousToken, cancellationToken)
If symbolInfo.Symbol IsNot Nothing Then
Dim type = TryCast(symbolInfo.Symbol, IPropertySymbol)?.Type
If type IsNot Nothing Then
result = context.SemanticModel.LookupSymbols(token.SpanStart, type).OfType(Of IEventSymbol)()
result = context.SemanticModel.LookupSymbols(token.SpanStart, type).
OfType(Of IEventSymbol)().
ToImmutableArray()
End If
End If
End Select
Return result
Return ImmutableArray(Of ISymbol).CastUp(result)
End Function
Private Function CreateCompletionItem(position As Integer,
......
......@@ -24,14 +24,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
Return True
End Function
Protected Overrides Function GetSymbolsWorker(context As SyntaxContext, position As Integer, options As OptionSet, cancellationToken As CancellationToken) As Task(Of IEnumerable(Of ISymbol))
Protected Overrides Function GetSymbolsWorker(
context As SyntaxContext, position As Integer, options As OptionSet, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of ISymbol))
If context.TargetToken.Kind = SyntaxKind.None Then
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End If
If context.SyntaxTree.IsInNonUserCode(position, cancellationToken) OrElse
context.SyntaxTree.IsInSkippedText(position, cancellationToken) Then
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End If
' We only care about Methods, Properties, and Events
......@@ -51,10 +52,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
' We couldn't find a declaration. Bail.
If memberKindKeyword = Nothing Then
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End If
Dim result As IEnumerable(Of ISymbol) = Nothing
Dim result = ImmutableArray(Of ISymbol).Empty
' Valid positions: Immediately after 'Implements, after ., or after a ,
If context.TargetToken.Kind = SyntaxKind.ImplementsKeyword AndAlso context.TargetToken.Parent.IsKind(SyntaxKind.ImplementsClause) Then
......@@ -69,11 +70,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
result = GetDottedMembers(position, DirectCast(context.TargetToken.Parent, QualifiedNameSyntax), context.SemanticModel, memberKindKeyword, cancellationToken)
End If
If result IsNot Nothing Then
Return Task.FromResult(result.Where(Function(s) MatchesMemberKind(s, memberKindKeyword)))
If result.Length > 0 Then
Return Task.FromResult(result.WhereAsArray(Function(s) MatchesMemberKind(s, memberKindKeyword)))
End If
Return SpecializedTasks.EmptyEnumerable(Of ISymbol)()
Return SpecializedTasks.EmptyImmutableArray(Of ISymbol)()
End Function
Private Function MatchesMemberKind(symbol As ISymbol, memberKindKeyword As SyntaxKind) As Boolean
......@@ -101,10 +102,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
Return memberKindKeyword = SyntaxKind.EventKeyword
End Function
Private Function GetDottedMembers(position As Integer, qualifiedName As QualifiedNameSyntax, semanticModel As SemanticModel, memberKindKeyword As SyntaxKind, cancellationToken As CancellationToken) As IEnumerable(Of ISymbol)
Private Function GetDottedMembers(position As Integer, qualifiedName As QualifiedNameSyntax, semanticModel As SemanticModel, memberKindKeyword As SyntaxKind, cancellationToken As CancellationToken) As ImmutableArray(Of ISymbol)
Dim containingType = semanticModel.GetEnclosingNamedType(position, cancellationToken)
If containingType Is Nothing Then
Return Nothing
Return ImmutableArray(Of ISymbol).Empty
End If
Dim unimplementedInterfacesAndMembers = From item In containingType.GetAllUnimplementedMembersInThis(containingType.Interfaces, cancellationToken)
......@@ -142,11 +143,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
End If
Dim symbols = semanticModel.LookupSymbols(position, container)
Return New HashSet(Of ISymbol)(symbols.ToArray() _
Dim hashSet = New HashSet(Of ISymbol)(symbols.ToArray() _
.Where(Function(s As ISymbol) interfacesAndContainers.Contains(s, SymbolEquivalenceComparer.Instance) OrElse
(TypeOf (s) Is INamespaceSymbol AndAlso namespaces.Contains(TryCast(s, INamespaceSymbol), INamespaceSymbolExtensions.EqualityComparer)) OrElse
members.Contains(s)))
Return hashSet.ToImmutableArray()
End Function
Private Function interfaceMemberGetter([interface] As ITypeSymbol, within As ISymbol) As ImmutableArray(Of ISymbol)
......@@ -154,10 +155,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
.AddRange([interface].GetMembers())
End Function
Private Function GetInterfacesAndContainers(position As Integer, node As SyntaxNode, semanticModel As SemanticModel, kind As SyntaxKind, cancellationToken As CancellationToken) As IEnumerable(Of ISymbol)
Private Function GetInterfacesAndContainers(position As Integer, node As SyntaxNode, semanticModel As SemanticModel, kind As SyntaxKind, cancellationToken As CancellationToken) As ImmutableArray(Of ISymbol)
Dim containingType = semanticModel.GetEnclosingNamedType(position, cancellationToken)
If containingType Is Nothing Then
Return Nothing
Return ImmutableArray(Of ISymbol).Empty
End If
Dim interfaceWithUnimplementedMembers = containingType.GetAllUnimplementedMembersInThis(containingType.Interfaces, AddressOf interfaceMemberGetter, cancellationToken) _
......@@ -171,7 +172,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
Dim symbols = semanticModel.LookupSymbols(position)
Dim result = TryAddGlobalTo(interfacesAndContainers.Intersect(symbols.ToArray()))
Dim result = TryAddGlobalTo(interfacesAndContainers.Intersect(symbols.ToArray()).ToImmutableArray())
' Even if there's not anything left to implement, we'll show the list of interfaces,
' the global namespace, and the project root namespace (if any), as long as the class implements something.
......@@ -182,7 +183,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
defaultListing.Add(containingType.ContainingNamespace)
AddAliasesAndContainers(containingType.ContainingNamespace, defaultListing, node, semanticModel)
End If
Return defaultListing
Return defaultListing.ToImmutableArray()
End If
Return result
......@@ -220,10 +221,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Completion.Providers
Return [namespace] IsNot Nothing AndAlso [namespace].IsGlobalNamespace
End Function
Private Function TryAddGlobalTo(symbols As IEnumerable(Of ISymbol)) As IEnumerable(Of ISymbol)
Private Function TryAddGlobalTo(symbols As ImmutableArray(Of ISymbol)) As ImmutableArray(Of ISymbol)
Dim withGlobalContainer = symbols.FirstOrDefault(Function(s) s.ContainingNamespace.IsGlobalNamespace)
If withGlobalContainer IsNot Nothing Then
Return symbols.Concat(SpecializedCollections.SingletonEnumerable(withGlobalContainer.ContainingNamespace))
Return symbols.Concat(ImmutableArray.Create(Of ISymbol)(withGlobalContainer.ContainingNamespace))
End If
Return symbols
......
......@@ -64,7 +64,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp
Dim symbolDisplayService = document.Project.LanguageServices.GetService(Of ISymbolDisplayService)()
Dim accessibleConstructors = attributeType.InstanceConstructors.
Where(Function(c) c.IsAccessibleWithin(within)).
WhereAsArray(Function(c) c.IsAccessibleWithin(within)).
FilterToVisibleAndBrowsableSymbolsAndNotUnsafeSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation).
Sort(symbolDisplayService, semanticModel, attribute.SpanStart)
......
......@@ -57,7 +57,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp
Dim methods = semanticModel.LookupSymbols(
functionAggregation.SpanStart,
name:=functionAggregation.FunctionName.ValueText,
includeReducedExtensionMethods:=True).OfType(Of IMethodSymbol).Where(Function(m) m.IsAggregateFunction()).ToList()
includeReducedExtensionMethods:=True).OfType(Of IMethodSymbol).
Where(Function(m) m.IsAggregateFunction()).
ToImmutableArrayOrEmpty()
Dim within = semanticModel.GetEnclosingNamedTypeOrAssembly(position, cancellationToken)
If within Is Nothing Then
......@@ -65,7 +67,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp
End If
Dim symbolDisplayService = document.Project.LanguageServices.GetService(Of ISymbolDisplayService)()
Dim accessibleMethods = methods.Where(Function(m) m.IsAccessibleWithin(within)).
Dim accessibleMethods = methods.WhereAsArray(Function(m) m.IsAccessibleWithin(within)).
FilterToVisibleAndBrowsableSymbolsAndNotUnsafeSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation).
Sort(symbolDisplayService, semanticModel, functionAggregation.SpanStart)
......
......@@ -89,8 +89,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp
End If
Dim symbolDisplayService = document.Project.LanguageServices.GetService(Of ISymbolDisplayService)()
Dim accessibleSymbols = symbols.Where(Function(s) s.GetArity() > 0).
Where(Function(s) TypeOf s Is INamedTypeSymbol OrElse TypeOf s Is IMethodSymbol).
Dim accessibleSymbols = symbols.WhereAsArray(Function(s) s.GetArity() > 0).
WhereAsArray(Function(s) TypeOf s Is INamedTypeSymbol OrElse TypeOf s Is IMethodSymbol).
FilterToVisibleAndBrowsableSymbolsAndNotUnsafeSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation).
Sort(symbolDisplayService, semanticModel, genericName.SpanStart)
......
......@@ -83,7 +83,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp
' if the symbol could be bound, replace that item in the symbol list
If matchedMethodSymbol IsNot Nothing AndAlso matchedMethodSymbol.IsGenericMethod Then
memberGroup = memberGroup.Select(Function(m) If(matchedMethodSymbol.OriginalDefinition Is m, matchedMethodSymbol, m))
memberGroup = memberGroup.SelectAsArray(Function(m) If(matchedMethodSymbol.OriginalDefinition Is m, matchedMethodSymbol, m))
End If
memberGroup = memberGroup.Sort(symbolDisplayService, semanticModel, invocationExpression.SpanStart)
......@@ -95,7 +95,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp
SpecializedCollections.EmptyList(Of IPropertySymbol),
semanticModel.LookupSymbols(position, expressionType, includeReducedExtensionMethods:=True).
OfType(Of IPropertySymbol).
Where(Function(p) p.IsIndexer).
ToImmutableArrayOrEmpty().
WhereAsArray(Function(p) p.IsIndexer).
FilterToVisibleAndBrowsableSymbolsAndNotUnsafeSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation).
Sort(symbolDisplayService, semanticModel, invocationExpression.SpanStart))
......
......@@ -19,7 +19,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp
normalType As INamedTypeSymbol,
within As ISymbol,
cancellationToken As CancellationToken) As IList(Of SignatureHelpItem)
Dim accessibleConstructors = normalType.InstanceConstructors.Where(Function(c) c.IsAccessibleWithin(within)).
Dim accessibleConstructors = normalType.InstanceConstructors.
WhereAsArray(Function(c) c.IsAccessibleWithin(within)).
FilterToVisibleAndBrowsableSymbolsAndNotUnsafeSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation).
Sort(symbolDisplayService, semanticModel, objectCreationExpression.SpanStart)
......
......@@ -76,8 +76,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SignatureHelp
semanticModel.LookupSymbols(raiseEventStatement.SpanStart, containingType, raiseEventStatement.Name.Identifier.ValueText))
Dim symbolDisplayService = document.Project.LanguageServices.GetService(Of ISymbolDisplayService)()
Dim allowedEvents = events.Where(Function(s) s.Kind = SymbolKind.Event AndAlso s.ContainingType Is containingType).
Cast(Of IEventSymbol)().
Dim allowedEvents = events.WhereAsArray(Function(s) s.Kind = SymbolKind.Event AndAlso s.ContainingType Is containingType).
OfType(Of IEventSymbol)().
ToImmutableArrayOrEmpty().
FilterToVisibleAndBrowsableSymbolsAndNotUnsafeSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation).
Sort(symbolDisplayService, semanticModel, raiseEventStatement.SpanStart)
......
// 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.Composition;
using System.Diagnostics;
using System.Linq;
......@@ -24,7 +24,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Recommendations
[ExportLanguageService(typeof(IRecommendationService), LanguageNames.CSharp), Shared]
internal class CSharpRecommendationService : AbstractRecommendationService
{
protected override Task<Tuple<IEnumerable<ISymbol>, SyntaxContext>> GetRecommendedSymbolsAtPositionWorkerAsync(
protected override Task<Tuple<ImmutableArray<ISymbol>, SyntaxContext>> GetRecommendedSymbolsAtPositionWorkerAsync(
Workspace workspace, SemanticModel semanticModel, int position, OptionSet options, CancellationToken cancellationToken)
{
var context = CSharpSyntaxContext.CreateContext(workspace, semanticModel, position, cancellationToken);
......@@ -35,10 +35,10 @@ internal class CSharpRecommendationService : AbstractRecommendationService
var hideAdvancedMembers = options.GetOption(RecommendationOptions.HideAdvancedMembers, semanticModel.Language);
symbols = symbols.FilterToVisibleAndBrowsableSymbols(hideAdvancedMembers, semanticModel.Compilation);
return Task.FromResult(Tuple.Create<IEnumerable<ISymbol>, SyntaxContext>(symbols, context));
return Task.FromResult(Tuple.Create<ImmutableArray<ISymbol>, SyntaxContext>(symbols, context));
}
private static IEnumerable<ISymbol> GetSymbolsWorker(
private static ImmutableArray<ISymbol> GetSymbolsWorker(
CSharpSyntaxContext context,
bool filterOutOfScopeLocals,
CancellationToken cancellationToken)
......@@ -46,20 +46,15 @@ internal class CSharpRecommendationService : AbstractRecommendationService
if (context.IsInNonUserCode ||
context.IsPreProcessorDirectiveContext)
{
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
if (context.IsRightOfNameSeparator)
{
return GetSymbolsOffOfContainer(context, cancellationToken);
}
else
{
return GetSymbolsForCurrentContext(context, filterOutOfScopeLocals, cancellationToken);
}
return context.IsRightOfNameSeparator
? GetSymbolsOffOfContainer(context, cancellationToken)
: GetSymbolsForCurrentContext(context, filterOutOfScopeLocals, cancellationToken);
}
private static IEnumerable<ISymbol> GetSymbolsForCurrentContext(
private static ImmutableArray<ISymbol> GetSymbolsForCurrentContext(
CSharpSyntaxContext context,
bool filterOutOfScopeLocals,
CancellationToken cancellationToken)
......@@ -92,17 +87,18 @@ internal class CSharpRecommendationService : AbstractRecommendationService
}
else if (context.IsDestructorTypeContext)
{
return SpecializedCollections.SingletonEnumerable(context.SemanticModel.GetDeclaredSymbol(context.ContainingTypeOrEnumDeclaration, cancellationToken));
return ImmutableArray.Create<ISymbol>(
context.SemanticModel.GetDeclaredSymbol(context.ContainingTypeOrEnumDeclaration, cancellationToken));
}
else if (context.IsNamespaceDeclarationNameContext)
{
return GetSymbolsForNamespaceDeclarationNameContext(context, cancellationToken);
}
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
private static IEnumerable<ISymbol> GetSymbolsOffOfContainer(
private static ImmutableArray<ISymbol> GetSymbolsOffOfContainer(
CSharpSyntaxContext context,
CancellationToken cancellationToken)
{
......@@ -132,11 +128,11 @@ internal class CSharpRecommendationService : AbstractRecommendationService
}
else
{
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
}
private static IEnumerable<ISymbol> GetSymbolsForGlobalStatementContext(
private static ImmutableArray<ISymbol> GetSymbolsForGlobalStatementContext(
CSharpSyntaxContext context,
CancellationToken cancellationToken)
{
......@@ -170,7 +166,7 @@ internal class CSharpRecommendationService : AbstractRecommendationService
return symbols;
}
private static IEnumerable<ISymbol> GetSymbolsForTypeArgumentOfConstraintClause(
private static ImmutableArray<ISymbol> GetSymbolsForTypeArgumentOfConstraintClause(
CSharpSyntaxContext context,
CancellationToken cancellationToken)
{
......@@ -182,12 +178,12 @@ internal class CSharpRecommendationService : AbstractRecommendationService
var symbols = enclosingSymbol != null
? enclosingSymbol.GetTypeArguments()
: SpecializedCollections.EmptyEnumerable<ISymbol>();
: ImmutableArray<ITypeSymbol>.Empty;
return symbols;
return ImmutableArray<ISymbol>.CastUp(symbols);
}
private static IEnumerable<ISymbol> GetSymbolsOffOffAlias(
private static ImmutableArray<ISymbol> GetSymbolsOffOffAlias(
CSharpSyntaxContext context,
IdentifierNameSyntax alias,
CancellationToken cancellationToken)
......@@ -195,7 +191,7 @@ internal class CSharpRecommendationService : AbstractRecommendationService
var aliasSymbol = context.SemanticModel.GetAliasInfo(alias, cancellationToken);
if (aliasSymbol == null)
{
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
return context.SemanticModel.LookupNamespacesAndTypes(
......@@ -203,7 +199,7 @@ internal class CSharpRecommendationService : AbstractRecommendationService
aliasSymbol.Target);
}
private static IEnumerable<ISymbol> GetSymbolsForLabelContext(
private static ImmutableArray<ISymbol> GetSymbolsForLabelContext(
CSharpSyntaxContext context,
CancellationToken cancellationToken)
{
......@@ -212,41 +208,40 @@ internal class CSharpRecommendationService : AbstractRecommendationService
// Exclude labels (other than 'default') that come from case switch statements
return allLabels
.Where(label => label.DeclaringSyntaxReferences.First().GetSyntax(cancellationToken)
.IsKind(SyntaxKind.LabeledStatement, SyntaxKind.DefaultSwitchLabel))
.AsImmutableOrEmpty();
.WhereAsArray(label => label.DeclaringSyntaxReferences.First().GetSyntax(cancellationToken)
.IsKind(SyntaxKind.LabeledStatement, SyntaxKind.DefaultSwitchLabel));
}
private static IEnumerable<ISymbol> GetSymbolsForTypeOrNamespaceContext(CSharpSyntaxContext context)
private static ImmutableArray<ISymbol> GetSymbolsForTypeOrNamespaceContext(CSharpSyntaxContext context)
{
var symbols = context.SemanticModel.LookupNamespacesAndTypes(context.LeftToken.SpanStart);
if (context.TargetToken.IsUsingKeywordInUsingDirective())
{
return symbols.Where(s => s.IsNamespace());
return symbols.WhereAsArray(s => s.IsNamespace());
}
if (context.TargetToken.IsStaticKeywordInUsingDirective())
{
return symbols.Where(s => !s.IsDelegateType() && !s.IsInterfaceType());
return symbols.WhereAsArray(s => !s.IsDelegateType() && !s.IsInterfaceType());
}
return symbols;
}
private static IEnumerable<ISymbol> GetSymbolsForNamespaceDeclarationNameContext(CSharpSyntaxContext context, CancellationToken cancellationToken)
private static ImmutableArray<ISymbol> GetSymbolsForNamespaceDeclarationNameContext(CSharpSyntaxContext context, CancellationToken cancellationToken)
{
var declarationSyntax = context.TargetToken.GetAncestor<NamespaceDeclarationSyntax>();
if (declarationSyntax == null)
{
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
return GetRecommendedNamespaceNameSymbols(context.SemanticModel, declarationSyntax, cancellationToken);
}
private static IEnumerable<ISymbol> GetSymbolsForExpressionOrStatementContext(
private static ImmutableArray<ISymbol> GetSymbolsForExpressionOrStatementContext(
CSharpSyntaxContext context,
bool filterOutOfScopeLocals,
CancellationToken cancellationToken)
......@@ -267,7 +262,7 @@ private static IEnumerable<ISymbol> GetSymbolsForNamespaceDeclarationNameContext
}
}
IEnumerable<ISymbol> symbols = !context.IsNameOfContext && context.LeftToken.Parent.IsInStaticContext()
var symbols = !context.IsNameOfContext && context.LeftToken.Parent.IsInStaticContext()
? context.SemanticModel.LookupStaticMembers(context.LeftToken.SpanStart)
: context.SemanticModel.LookupSymbols(context.LeftToken.SpanStart);
......@@ -275,22 +270,23 @@ private static IEnumerable<ISymbol> GetSymbolsForNamespaceDeclarationNameContext
// But include extension methods declared in the context's type or it's parents
var contextEnclosingNamedType = context.SemanticModel.GetEnclosingNamedType(context.Position, cancellationToken);
var contextOuterTypes = context.GetOuterTypes(cancellationToken);
symbols = symbols.Where(symbol => !symbol.IsExtensionMethod() ||
contextEnclosingNamedType.Equals(symbol.ContainingType) ||
contextOuterTypes.Any(outerType => outerType.Equals(symbol.ContainingType)));
symbols = symbols.WhereAsArray(symbol =>
!symbol.IsExtensionMethod() ||
contextEnclosingNamedType.Equals(symbol.ContainingType) ||
contextOuterTypes.Any(outerType => outerType.Equals(symbol.ContainingType)));
// The symbols may include local variables that are declared later in the method and
// should not be included in the completion list, so remove those. Filter them away,
// unless we're in the debugger, where we show all locals in scope.
if (filterOutOfScopeLocals)
{
symbols = symbols.Where(symbol => !symbol.IsInaccessibleLocal(context.Position));
symbols = symbols.WhereAsArray(symbol => !symbol.IsInaccessibleLocal(context.Position));
}
return symbols;
}
private static IEnumerable<ISymbol> GetSymbolsOffOfName(
private static ImmutableArray<ISymbol> GetSymbolsOffOfName(
CSharpSyntaxContext context,
NameSyntax name,
CancellationToken cancellationToken)
......@@ -325,14 +321,14 @@ private static IEnumerable<ISymbol> GetSymbolsForNamespaceDeclarationNameContext
return context.SemanticModel.LookupSymbols(position: name.SpanStart, container: symbol);
}
IEnumerable<ISymbol> symbols = context.SemanticModel.LookupNamespacesAndTypes(
var symbols = context.SemanticModel.LookupNamespacesAndTypes(
position: name.SpanStart,
container: symbol);
if (context.IsNamespaceDeclarationNameContext)
{
var declarationSyntax = name.GetAncestorOrThis<NamespaceDeclarationSyntax>();
return symbols.Where(s => IsNonIntersectingNamespace(s, declarationSyntax));
return symbols.WhereAsArray(s => IsNonIntersectingNamespace(s, declarationSyntax));
}
// Filter the types when in a using directive, but not an alias.
......@@ -347,11 +343,11 @@ private static IEnumerable<ISymbol> GetSymbolsForNamespaceDeclarationNameContext
{
if (usingDirective.StaticKeyword.IsKind(SyntaxKind.StaticKeyword))
{
return symbols.Where(s => !s.IsDelegateType() && !s.IsInterfaceType());
return symbols.WhereAsArray(s => !s.IsDelegateType() && !s.IsInterfaceType());
}
else
{
symbols = symbols.Where(s => s.IsNamespace()).ToList();
symbols = symbols.WhereAsArray(s => s.IsNamespace());
}
}
......@@ -361,10 +357,10 @@ private static IEnumerable<ISymbol> GetSymbolsForNamespaceDeclarationNameContext
}
}
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
private static IEnumerable<ISymbol> GetSymbolsOffOfExpression(
private static ImmutableArray<ISymbol> GetSymbolsOffOfExpression(
CSharpSyntaxContext context,
ExpressionSyntax originalExpression,
CancellationToken cancellationToken)
......@@ -388,7 +384,7 @@ private static IEnumerable<ISymbol> GetSymbolsForNamespaceDeclarationNameContext
return normalSymbols;
}
private static IEnumerable<ISymbol> GetSymbolsOffOfDereferencedExpression(
private static ImmutableArray<ISymbol> GetSymbolsOffOfDereferencedExpression(
CSharpSyntaxContext context,
ExpressionSyntax originalExpression,
CancellationToken cancellationToken)
......@@ -405,7 +401,7 @@ private static IEnumerable<ISymbol> GetSymbolsForNamespaceDeclarationNameContext
return GetSymbolsOffOfBoundExpression(context, originalExpression, expression, leftHandBinding, container, cancellationToken);
}
private static IEnumerable<ISymbol> GetSymbolsOffOfConditionalReceiver(
private static ImmutableArray<ISymbol> GetSymbolsOffOfConditionalReceiver(
CSharpSyntaxContext context,
ExpressionSyntax originalExpression,
CancellationToken cancellationToken)
......@@ -422,13 +418,13 @@ private static IEnumerable<ISymbol> GetSymbolsForNamespaceDeclarationNameContext
// IntelliSense.
if (leftHandBinding.GetBestOrAllSymbols().FirstOrDefault().MatchesKind(SymbolKind.NamedType, SymbolKind.Namespace, SymbolKind.Alias))
{
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
return GetSymbolsOffOfBoundExpression(context, originalExpression, expression, leftHandBinding, container, cancellationToken);
}
private static IEnumerable<ISymbol> GetSymbolsOffOfBoundExpression(
private static ImmutableArray<ISymbol> GetSymbolsOffOfBoundExpression(
CSharpSyntaxContext context,
ExpressionSyntax originalExpression,
ExpressionSyntax expression,
......@@ -450,21 +446,21 @@ private static IEnumerable<ISymbol> GetSymbolsForNamespaceDeclarationNameContext
SymbolKind.Namespace,
SymbolKind.Alias))
{
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
// If the thing on the left is a lambda expression, we shouldn't show anything.
if (symbol.Kind == SymbolKind.Method &&
((IMethodSymbol)symbol).MethodKind == MethodKind.AnonymousFunction)
{
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
// If the thing on the left is an event that can't be used as a field, we shouldn't show anything
if (symbol.Kind == SymbolKind.Event &&
!context.SemanticModel.IsEventUsableAsField(originalExpression.SpanStart, (IEventSymbol)symbol))
{
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
// If the thing on the left is a this parameter (e.g. this or base) and we're in a static context,
......@@ -472,7 +468,7 @@ private static IEnumerable<ISymbol> GetSymbolsForNamespaceDeclarationNameContext
if (symbol.IsThisParameter() &&
expression.IsInStaticContext())
{
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
// What is the thing on the left?
......@@ -514,7 +510,7 @@ private static IEnumerable<ISymbol> GetSymbolsForNamespaceDeclarationNameContext
}
else
{
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
Debug.Assert(!excludeInstance || !excludeStatic);
......@@ -530,7 +526,7 @@ private static IEnumerable<ISymbol> GetSymbolsForNamespaceDeclarationNameContext
var position = originalExpression.SpanStart;
IEnumerable<ISymbol> symbols = useBaseReferenceAccessibility
var symbols = useBaseReferenceAccessibility
? context.SemanticModel.LookupBaseMembers(position)
: excludeInstance
? context.SemanticModel.LookupStaticMembers(position, container)
......@@ -539,7 +535,7 @@ private static IEnumerable<ISymbol> GetSymbolsForNamespaceDeclarationNameContext
// If we're showing instance members, don't include nested types
return excludeStatic
? symbols.Where(s => !s.IsStatic && !(s is ITypeSymbol))
? symbols.WhereAsArray(s => !s.IsStatic && !(s is ITypeSymbol))
: symbols;
}
}
......
......@@ -118,7 +118,7 @@ internal static class DependentTypeFinder
CancellationToken cancellationToken)
{
return FindDerivedAndImplementingTypesAsync(
SymbolAndProjectId.Create(type, projectId: null), solution, projects: null,
SymbolAndProjectId.Create(type, projectId: null), solution, projects: null,
transitive: false, cancellationToken: cancellationToken);
}
......@@ -611,10 +611,10 @@ internal static class DependentTypeFinder
var declarationInfo = await document.GetDeclarationInfoAsync(cancellationToken).ConfigureAwait(false);
cachedInfos.Add(declarationInfo);
SymbolAndProjectIdSet result = null;
var result = CreateSymbolAndProjectIdSet();
foreach (var symbolInfo in declarationInfo.DeclaredSymbolInfos)
{
result = await ProcessSymbolInfo(
await ProcessSymbolInfo(
document, symbolInfo,
typesToSearchFor,
inheritanceQuery, cachedModels,
......@@ -624,7 +624,7 @@ internal static class DependentTypeFinder
return ToImmutableAndFree(result);
}
private static async Task<SymbolAndProjectIdSet> ProcessSymbolInfo(
private static async Task ProcessSymbolInfo(
Document document,
DeclaredSymbolInfo info,
SymbolAndProjectIdSet typesToSearchFor,
......@@ -644,7 +644,6 @@ internal static class DependentTypeFinder
var symbol = await ResolveAsync(document, info, cachedModels, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol;
if (symbol != null)
{
result = result ?? CreateSymbolAndProjectIdSet();
result.Add(SymbolAndProjectId.Create(symbol, projectId));
}
}
......@@ -658,7 +657,6 @@ internal static class DependentTypeFinder
var symbol = await ResolveAsync(document, info, cachedModels, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol;
if (symbol?.BaseType?.SpecialType == SpecialType.System_Object)
{
result = result ?? CreateSymbolAndProjectIdSet();
result.Add(SymbolAndProjectId.Create(symbol, projectId));
}
}
......@@ -670,13 +668,10 @@ internal static class DependentTypeFinder
{
if (typeImmediatelyMatches(typesToSearchFor, symbol))
{
result = result ?? CreateSymbolAndProjectIdSet();
result.Add(SymbolAndProjectId.Create(symbol, projectId));
}
}
}
return result;
}
private static bool AnyInheritanceNamesMatch(
......
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
......@@ -14,10 +15,10 @@ namespace Microsoft.CodeAnalysis.Recommendations
{
internal abstract class AbstractRecommendationService : IRecommendationService
{
protected abstract Task<Tuple<IEnumerable<ISymbol>, SyntaxContext>> GetRecommendedSymbolsAtPositionWorkerAsync(
protected abstract Task<Tuple<ImmutableArray<ISymbol>, SyntaxContext>> GetRecommendedSymbolsAtPositionWorkerAsync(
Workspace workspace, SemanticModel semanticModel, int position, OptionSet options, CancellationToken cancellationToken);
public async Task<IEnumerable<ISymbol>> GetRecommendedSymbolsAtPositionAsync(
public async Task<ImmutableArray<ISymbol>> GetRecommendedSymbolsAtPositionAsync(
Workspace workspace, SemanticModel semanticModel, int position, OptionSet options, CancellationToken cancellationToken)
{
var result = await GetRecommendedSymbolsAtPositionWorkerAsync(workspace, semanticModel, position, options, cancellationToken).ConfigureAwait(false);
......@@ -25,11 +26,11 @@ internal abstract class AbstractRecommendationService : IRecommendationService
var symbols = result.Item1;
var context = new ShouldIncludeSymbolContext(result.Item2, cancellationToken);
symbols = symbols.Where(context.ShouldIncludeSymbol);
symbols = symbols.WhereAsArray(context.ShouldIncludeSymbol);
return symbols;
}
protected static IEnumerable<ISymbol> GetRecommendedNamespaceNameSymbols(
protected static ImmutableArray<ISymbol> GetRecommendedNamespaceNameSymbols(
SemanticModel semanticModel, SyntaxNode declarationSyntax, CancellationToken cancellationToken)
{
if (declarationSyntax == null)
......@@ -41,12 +42,13 @@ internal abstract class AbstractRecommendationService : IRecommendationService
semanticModel.GetEnclosingNamespace(declarationSyntax.SpanStart, cancellationToken));
var symbols = semanticModel.LookupNamespacesAndTypes(declarationSyntax.SpanStart, containingNamespaceSymbol)
.Where(recommendationSymbol => IsNonIntersectingNamespace(recommendationSymbol, declarationSyntax));
.WhereAsArray(recommendationSymbol => IsNonIntersectingNamespace(recommendationSymbol, declarationSyntax));
return symbols;
}
protected static bool IsNonIntersectingNamespace(ISymbol recommendationSymbol, SyntaxNode declarationSyntax)
protected static bool IsNonIntersectingNamespace(
ISymbol recommendationSymbol, SyntaxNode declarationSyntax)
{
//
// Apart from filtering out non-namespace symbols, this also filters out the symbol
......@@ -76,8 +78,8 @@ protected static bool IsNonIntersectingNamespace(ISymbol recommendationSymbol, S
/// the suppression of the corresponding default name (ItemN).
/// In that case, Rest is also removed.
/// </summary>
protected static IEnumerable<ISymbol> SuppressDefaultTupleElements(INamespaceOrTypeSymbol container,
IEnumerable<ISymbol> symbols)
protected static ImmutableArray<ISymbol> SuppressDefaultTupleElements(
INamespaceOrTypeSymbol container, ImmutableArray<ISymbol> symbols)
{
if (!container.IsType)
{
......@@ -102,7 +104,10 @@ protected static bool IsNonIntersectingNamespace(ISymbol recommendationSymbol, S
var fieldsToRemove = elementNames.Select((n, i) => IsFriendlyName(i, n) ? "Item" + (i + 1) : null)
.Where(n => n != null).Concat("Rest").ToSet();
return symbols.Where(s => s.Kind != SymbolKind.Field || elementNames.Contains(s.Name) || !fieldsToRemove.Contains(s.Name));
return symbols.WhereAsArray(
s => s.Kind != SymbolKind.Field ||
elementNames.Contains(s.Name) ||
!fieldsToRemove.Contains(s.Name));
}
private static bool IsFriendlyName(int i, string elementName)
......
// 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.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
......@@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Recommendations
{
internal interface IRecommendationService : ILanguageService
{
Task<IEnumerable<ISymbol>> GetRecommendedSymbolsAtPositionAsync(
Task<ImmutableArray<ISymbol>> GetRecommendedSymbolsAtPositionAsync(
Workspace workspace,
SemanticModel semanticModel,
int position,
......
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Options;
......@@ -25,7 +26,18 @@ public static class Recommender
return GetRecommendedSymbolsAtPositionAsync(semanticModel, position, workspace, options, cancellationToken).WaitAndGetResult(cancellationToken);
}
public static Task<IEnumerable<ISymbol>> GetRecommendedSymbolsAtPositionAsync(
public static async Task<IEnumerable<ISymbol>> GetRecommendedSymbolsAtPositionAsync(
SemanticModel semanticModel,
int position,
Workspace workspace,
OptionSet options = null,
CancellationToken cancellationToken = default(CancellationToken))
{
return await GetImmutableRecommendedSymbolsAtPositionAsync(
semanticModel, position, workspace, options, cancellationToken).ConfigureAwait(false);
}
internal static async Task<ImmutableArray<ISymbol>> GetImmutableRecommendedSymbolsAtPositionAsync(
SemanticModel semanticModel,
int position,
Workspace workspace,
......@@ -35,7 +47,8 @@ public static class Recommender
options = options ?? workspace.Options;
var languageRecommender = workspace.Services.GetLanguageServices(semanticModel.Language).GetService<IRecommendationService>();
return languageRecommender.GetRecommendedSymbolsAtPositionAsync(workspace, semanticModel, position, options, cancellationToken);
return await languageRecommender.GetRecommendedSymbolsAtPositionAsync(
workspace, semanticModel, position, options, cancellationToken).ConfigureAwait(false);
}
}
}
......@@ -946,7 +946,8 @@ private static bool VerifyGetAwaiter(IMethodSymbol getAwaiter)
/// unsupported (e.g. pointer types in VB) or not editor browsable based on the EditorBrowsable
/// attribute.
/// </summary>
public static IEnumerable<T> FilterToVisibleAndBrowsableSymbols<T>(this IEnumerable<T> symbols, bool hideAdvancedMembers, Compilation compilation) where T : ISymbol
public static ImmutableArray<T> FilterToVisibleAndBrowsableSymbols<T>(
this ImmutableArray<T> symbols, bool hideAdvancedMembers, Compilation compilation) where T : ISymbol
{
symbols = symbols.RemoveOverriddenSymbolsWithinSet();
......@@ -962,7 +963,7 @@ private static bool VerifyGetAwaiter(IMethodSymbol getAwaiter)
// PERF: HasUnsupportedMetadata may require recreating the syntax tree to get the base class, so first
// check to see if we're referencing a symbol defined in source.
Func<Location, bool> isSymbolDefinedInSource = l => l.IsInSource;
return symbols.Where(s =>
return symbols.WhereAsArray(s =>
(s.Locations.Any(isSymbolDefinedInSource) || !s.HasUnsupportedMetadata) &&
!s.IsDestructor() &&
s.IsEditorBrowsable(
......@@ -975,9 +976,9 @@ private static bool VerifyGetAwaiter(IMethodSymbol getAwaiter)
hideModuleNameAttribute));
}
private static IEnumerable<T> RemoveOverriddenSymbolsWithinSet<T>(this IEnumerable<T> symbols) where T : ISymbol
private static ImmutableArray<T> RemoveOverriddenSymbolsWithinSet<T>(this ImmutableArray<T> symbols) where T : ISymbol
{
HashSet<ISymbol> overriddenSymbols = new HashSet<ISymbol>();
var overriddenSymbols = new HashSet<ISymbol>();
foreach (var symbol in symbols)
{
......@@ -987,12 +988,14 @@ private static bool VerifyGetAwaiter(IMethodSymbol getAwaiter)
}
}
return symbols.Where(s => !overriddenSymbols.Contains(s));
return symbols.WhereAsArray(s => !overriddenSymbols.Contains(s));
}
public static IEnumerable<T> FilterToVisibleAndBrowsableSymbolsAndNotUnsafeSymbols<T>(this IEnumerable<T> symbols, bool hideAdvancedMembers, Compilation compilation) where T : ISymbol
public static ImmutableArray<T> FilterToVisibleAndBrowsableSymbolsAndNotUnsafeSymbols<T>(
this ImmutableArray<T> symbols, bool hideAdvancedMembers, Compilation compilation) where T : ISymbol
{
return symbols.FilterToVisibleAndBrowsableSymbols(hideAdvancedMembers, compilation).Where(s => !s.IsUnsafe());
return symbols.FilterToVisibleAndBrowsableSymbols(hideAdvancedMembers, compilation)
.WhereAsArray(s => !s.IsUnsafe());
}
}
}
......@@ -663,15 +663,16 @@ public static INamedTypeSymbol GetDelegateType(this ITypeSymbol typeSymbol, Comp
return types.SelectMany(x => x.GetMembers().OfType<T>().Where(m => m.IsAccessibleWithin(within)));
}
public static IEnumerable<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
public static ImmutableArray<T> GetAccessibleMembersInThisAndBaseTypes<T>(this ITypeSymbol containingType, ISymbol within) where T : class, ISymbol
{
if (containingType == null)
{
return SpecializedCollections.EmptyEnumerable<T>();
return ImmutableArray<T>.Empty;
}
var types = containingType.GetBaseTypesAndThis();
return types.SelectMany(x => x.GetMembers().OfType<T>().Where(m => m.IsAccessibleWithin(within)));
return types.SelectMany(x => x.GetMembers().OfType<T>().Where(m => m.IsAccessibleWithin(within)))
.ToImmutableArray();
}
public static bool? AreMoreSpecificThan(this IList<ITypeSymbol> t1, IList<ITypeSymbol> t2)
......
......@@ -22,7 +22,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
position As Integer,
options As OptionSet,
cancellationToken As CancellationToken
) As Tasks.Task(Of Tuple(Of IEnumerable(Of ISymbol), SyntaxContext))
) As Tasks.Task(Of Tuple(Of ImmutableArray(Of ISymbol), SyntaxContext))
Dim context = Await VisualBasicSyntaxContext.CreateContextAsync(workspace, semanticModel, position, cancellationToken).ConfigureAwait(False)
......@@ -32,18 +32,18 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
Dim hideAdvancedMembers = options.GetOption(RecommendationOptions.HideAdvancedMembers, semanticModel.Language)
symbols = symbols.FilterToVisibleAndBrowsableSymbols(hideAdvancedMembers, semanticModel.Compilation)
Return Tuple.Create(Of IEnumerable(Of ISymbol), SyntaxContext)(symbols, context)
Return Tuple.Create(Of ImmutableArray(Of ISymbol), SyntaxContext)(symbols, context)
End Function
Private Function GetSymbolsWorker(
context As VisualBasicSyntaxContext,
filterOutOfScopeLocals As Boolean,
cancellationToken As CancellationToken
) As IEnumerable(Of ISymbol)
) As ImmutableArray(Of ISymbol)
If context.SyntaxTree.IsInNonUserCode(context.Position, cancellationToken) OrElse
context.SyntaxTree.IsInSkippedText(context.Position, cancellationToken) Then
Return SpecializedCollections.EmptyEnumerable(Of ISymbol)()
Return ImmutableArray(Of ISymbol).Empty
End If
Dim node = context.TargetToken.Parent
......@@ -69,20 +69,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
Return GetUnqualifiedSymbolsForRaiseEvent(context, cancellationToken)
ElseIf context.TargetToken.IsKind(SyntaxKind.ForKeyword) Then
Dim symbols = GetUnqualifiedSymbolsForExpressionOrStatementContext(context, filterOutOfScopeLocals, cancellationToken) _
.Where(AddressOf IsWritableFieldOrLocal)
.WhereAsArray(AddressOf IsWritableFieldOrLocal)
Return symbols
ElseIf context.IsNamespaceDeclarationNameContext Then
Return GetUnqualifiedSymbolsForNamespaceDeclarationNameContext(context, cancellationToken)
End If
Return SpecializedCollections.EmptyEnumerable(Of ISymbol)()
Return ImmutableArray(Of ISymbol).Empty
End Function
Private Function GetUnqualifiedSymbolsForNamespaceDeclarationNameContext(context As VisualBasicSyntaxContext, cancellationToken As CancellationToken) As IEnumerable(Of ISymbol)
Private Function GetUnqualifiedSymbolsForNamespaceDeclarationNameContext(
context As VisualBasicSyntaxContext, cancellationToken As CancellationToken) As ImmutableArray(Of ISymbol)
Dim declarationSyntax = context.TargetToken.GetAncestor(Of NamespaceBlockSyntax)
If declarationSyntax Is Nothing Then
Return SpecializedCollections.EmptyEnumerable(Of ISymbol)()
Return ImmutableArray(Of ISymbol).Empty
End If
Return GetRecommendedNamespaceNameSymbols(context.SemanticModel, declarationSyntax, cancellationToken)
......@@ -105,25 +107,28 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
Private Function GetSymbolsForGlobalStatementContext(
context As VisualBasicSyntaxContext,
cancellationToken As CancellationToken
) As IEnumerable(Of ISymbol)
) As ImmutableArray(Of ISymbol)
Return context.SemanticModel.LookupSymbols(context.TargetToken.Span.End)
End Function
Private Function GetUnqualifiedSymbolsForQueryIntoContext(
context As VisualBasicSyntaxContext,
cancellationToken As CancellationToken
) As IEnumerable(Of ISymbol)
) As ImmutableArray(Of ISymbol)
Dim symbols = context.SemanticModel _
.LookupSymbols(context.TargetToken.SpanStart, includeReducedExtensionMethods:=True)
Return symbols.OfType(Of IMethodSymbol)().Where(Function(m) m.IsAggregateFunction())
Return ImmutableArray(Of ISymbol).CastUp(
symbols.OfType(Of IMethodSymbol)().
Where(Function(m) m.IsAggregateFunction()).
ToImmutableArray())
End Function
Private Function GetUnqualifiedSymbolsForLabelContext(
context As VisualBasicSyntaxContext,
cancellationToken As CancellationToken
) As IEnumerable(Of ISymbol)
) As ImmutableArray(Of ISymbol)
Return context.SemanticModel _
.LookupLabels(context.TargetToken.SpanStart)
......@@ -132,19 +137,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
Private Function GetUnqualifiedSymbolsForRaiseEvent(
context As VisualBasicSyntaxContext,
cancellationToken As CancellationToken
) As IEnumerable(Of ISymbol)
) As ImmutableArray(Of ISymbol)
Dim containingType = context.SemanticModel.GetEnclosingSymbol(context.Position, cancellationToken).ContainingType
Return context.SemanticModel _
.LookupSymbols(context.Position, container:=containingType) _
.Where(Function(s) s.Kind = SymbolKind.Event AndAlso s.ContainingType Is containingType)
.WhereAsArray(Function(s) s.Kind = SymbolKind.Event AndAlso s.ContainingType Is containingType)
End Function
Private Function GetUnqualifiedSymbolsForType(
context As VisualBasicSyntaxContext,
cancellationToken As CancellationToken
) As IEnumerable(Of ISymbol)
) As ImmutableArray(Of ISymbol)
Dim symbols = context.SemanticModel _
.LookupNamespacesAndTypes(context.TargetToken.SpanStart)
......@@ -156,20 +161,20 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
context As VisualBasicSyntaxContext,
filterOutOfScopeLocals As Boolean,
cancellationToken As CancellationToken
) As IEnumerable(Of ISymbol)
) As ImmutableArray(Of ISymbol)
Dim lookupPosition = context.TargetToken.SpanStart
If context.FollowsEndOfStatement Then
lookupPosition = context.Position
End If
Dim symbols As IEnumerable(Of ISymbol) = If(
Dim symbols = If(
Not context.IsNameOfContext AndAlso context.TargetToken.Parent.IsInStaticContext(),
context.SemanticModel.LookupStaticMembers(lookupPosition),
context.SemanticModel.LookupSymbols(lookupPosition))
If filterOutOfScopeLocals Then
symbols = symbols.Where(Function(symbol) Not symbol.IsInaccessibleLocal(context.Position))
symbols = symbols.WhereAsArray(Function(symbol) Not symbol.IsInaccessibleLocal(context.Position))
End If
' GitHub #4428: When the user is typing a predicate (eg. "Enumerable.Range(0,10).Select($$")
......@@ -178,11 +183,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
If Not context.TargetToken.IsKind(SyntaxKind.OpenParenToken) OrElse
Not context.TargetToken.Parent.IsKind(SyntaxKind.GetTypeExpression) Then
symbols = symbols.Where(Function(s) Not IsInEligibleDelegate(s))
symbols = symbols.WhereAsArray(Function(s) Not IsInEligibleDelegate(s))
End If
' Hide backing fields and events
Return symbols.Where(Function(s) FilterEventsAndGeneratedSymbols(Nothing, s))
Return symbols.WhereAsArray(Function(s) FilterEventsAndGeneratedSymbols(Nothing, s))
End Function
Private Function IsInEligibleDelegate(s As ISymbol) As Boolean
......@@ -198,7 +203,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
context As VisualBasicSyntaxContext,
node As QualifiedNameSyntax,
cancellationToken As CancellationToken
) As IEnumerable(Of ISymbol)
) As ImmutableArray(Of ISymbol)
' We're in a name-only context, since if we were an expression we'd be a
' MemberAccessExpressionSyntax. Thus, let's do other namespaces and types.
......@@ -207,20 +212,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
Dim couldBeMergedNamespace = ContainsNamespaceCandidateSymbols(leftHandSymbolInfo)
If leftHandSymbol Is Nothing AndAlso Not couldBeMergedNamespace Then
Return SpecializedCollections.EmptyEnumerable(Of ISymbol)()
Return ImmutableArray(Of ISymbol).Empty
End If
Dim symbols As IEnumerable(Of ISymbol)
Dim symbols As ImmutableArray(Of ISymbol)
If couldBeMergedNamespace Then
symbols = leftHandSymbolInfo.CandidateSymbols.OfType(Of INamespaceSymbol)() _
.SelectMany(Function(n) context.SemanticModel.LookupNamespacesAndTypes(node.SpanStart, n))
.SelectMany(Function(n) context.SemanticModel.LookupNamespacesAndTypes(node.SpanStart, n)) _
.ToImmutableArray()
Else
symbols = context.SemanticModel _
.LookupNamespacesAndTypes(position:=node.SpanStart, container:=leftHandSymbol)
If context.IsNamespaceDeclarationNameContext Then
Dim declarationSyntax = node.GetAncestor(Of NamespaceBlockSyntax)
symbols = symbols.Where(Function(symbol) IsNonIntersectingNamespace(symbol, declarationSyntax))
symbols = symbols.WhereAsArray(Function(symbol) IsNonIntersectingNamespace(symbol, declarationSyntax))
End If
End If
......@@ -231,11 +237,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
context As VisualBasicSyntaxContext,
node As MemberAccessExpressionSyntax,
cancellationToken As CancellationToken
) As IEnumerable(Of ISymbol)
) As ImmutableArray(Of ISymbol)
Dim leftExpression = node.GetExpressionOfMemberAccessExpression()
If leftExpression Is Nothing Then
Return SpecializedCollections.EmptyEnumerable(Of ISymbol)()
Return ImmutableArray(Of ISymbol).Empty
End If
Dim leftHandTypeInfo = context.SemanticModel.GetTypeInfo(leftExpression, cancellationToken)
......@@ -264,7 +270,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
Select Case firstSymbol.Kind
Case SymbolKind.TypeParameter
' 884060: We don't allow invocations off type parameters.
Return SpecializedCollections.EmptyEnumerable(Of ISymbol)()
Return ImmutableArray(Of ISymbol).Empty
Case SymbolKind.NamedType, SymbolKind.Namespace
excludeInstance = True
excludeShared = False
......@@ -308,7 +314,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
End If
If container Is Nothing AndAlso Not couldBeMergedNamespace Then
Return SpecializedCollections.EmptyEnumerable(Of ISymbol)()
Return ImmutableArray(Of ISymbol).Empty
End If
Debug.Assert((Not excludeInstance OrElse Not excludeShared) OrElse
......@@ -326,24 +332,25 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
' No completion on types/namespace after conditional access
If leftExpression.Parent.IsKind(SyntaxKind.ConditionalAccessExpression) AndAlso
(couldBeMergedNamespace OrElse leftHandSymbolInfo.GetBestOrAllSymbols().FirstOrDefault().MatchesKind(SymbolKind.NamedType, SymbolKind.Namespace, SymbolKind.Alias)) Then
Return SpecializedCollections.EmptyCollection(Of ISymbol)()
Return ImmutableArray(Of ISymbol).Empty
End If
Dim position = node.SpanStart
Dim symbols As IEnumerable(Of ISymbol)
Dim symbols As ImmutableArray(Of ISymbol)
If couldBeMergedNamespace Then
symbols = leftHandSymbolInfo.CandidateSymbols _
.OfType(Of INamespaceSymbol) _
.SelectMany(Function(n) LookupSymbolsInContainer(n, context.SemanticModel, position, excludeInstance))
.SelectMany(Function(n) LookupSymbolsInContainer(n, context.SemanticModel, position, excludeInstance)) _
.ToImmutableArray()
Else
symbols = If(
useBaseReferenceAccessibility,
context.SemanticModel.LookupBaseMembers(position),
LookupSymbolsInContainer(container, context.SemanticModel, position, excludeInstance)).AsEnumerable()
LookupSymbolsInContainer(container, context.SemanticModel, position, excludeInstance))
End If
If excludeShared Then
symbols = symbols.Where(Function(s) Not s.IsShared)
symbols = symbols.WhereAsArray(Function(s) Not s.IsShared)
End If
' If the left expression is Me, MyBase or MyClass and we're the first statement of constructor,
......@@ -352,26 +359,26 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
Dim parentingCtor = GetEnclosingCtor(context.SemanticModel, node, cancellationToken)
Debug.Assert(parentingCtor IsNot Nothing)
symbols = symbols.Where(Function(s) Not s.Equals(parentingCtor)).ToList()
symbols = symbols.WhereAsArray(Function(s) Not s.Equals(parentingCtor))
Else
symbols = symbols.Where(Function(s) Not s.IsConstructor()).ToList()
symbols = symbols.WhereAsArray(Function(s) Not s.IsConstructor())
End If
' If the left expression is My.MyForms, we should filter out all non-property symbols
If leftHandSymbolInfo.Symbol IsNot Nothing AndAlso
leftHandSymbolInfo.Symbol.IsMyFormsProperty(context.SemanticModel.Compilation) Then
symbols = symbols.Where(Function(s) s.Kind = SymbolKind.Property)
symbols = symbols.WhereAsArray(Function(s) s.Kind = SymbolKind.Property)
End If
' Also filter out operators
symbols = symbols.Where(Function(s) s.Kind <> SymbolKind.Method OrElse DirectCast(s, IMethodSymbol).MethodKind <> MethodKind.UserDefinedOperator)
symbols = symbols.WhereAsArray(Function(s) s.Kind <> SymbolKind.Method OrElse DirectCast(s, IMethodSymbol).MethodKind <> MethodKind.UserDefinedOperator)
' Filter events and generated members
symbols = symbols.Where(Function(s) FilterEventsAndGeneratedSymbols(node, s))
symbols = symbols.WhereAsArray(Function(s) FilterEventsAndGeneratedSymbols(node, s))
' Never show the enum backing field
symbols = symbols.Where(Function(s) s.Kind <> SymbolKind.Field OrElse Not s.ContainingType.IsEnumType() OrElse s.Name <> WellKnownMemberNames.EnumBackingFieldName)
symbols = symbols.WhereAsArray(Function(s) s.Kind <> SymbolKind.Field OrElse Not s.ContainingType.IsEnumType() OrElse s.Name <> WellKnownMemberNames.EnumBackingFieldName)
Return symbols
End Function
......@@ -380,7 +387,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
Return symbolInfo.CandidateSymbols.Any() AndAlso symbolInfo.CandidateSymbols.All(Function(s) s.IsNamespace())
End Function
Private Function LookupSymbolsInContainer(container As INamespaceOrTypeSymbol, semanticModel As SemanticModel, position As Integer, excludeInstance As Boolean) As IEnumerable(Of ISymbol)
Private Function LookupSymbolsInContainer(container As INamespaceOrTypeSymbol, semanticModel As SemanticModel, position As Integer, excludeInstance As Boolean) As ImmutableArray(Of ISymbol)
If excludeInstance Then
Return semanticModel.LookupStaticMembers(position, container)
Else
......@@ -427,10 +434,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
End Function
Private Function FilterToValidAccessibleSymbols(
symbols As IEnumerable(Of ISymbol),
symbols As ImmutableArray(Of ISymbol),
context As VisualBasicSyntaxContext,
cancellationToken As CancellationToken
) As IEnumerable(Of ISymbol)
) As ImmutableArray(Of ISymbol)
' If this is an Inherits or Implements statement, we filter out symbols which do not recursively contain accessible, valid types.
Dim inheritsContext = IsInheritsStatementContext(context.TargetToken)
......@@ -451,19 +458,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
' In an interface's Inherits statement, only show interfaces.
If isInterface Then
Return symbols.Where(Function(s) IsValidAccessibleInterfaceOrContainer(s, typeOrAssemblySymbol))
Return symbols.WhereAsArray(Function(s) IsValidAccessibleInterfaceOrContainer(s, typeOrAssemblySymbol))
End If
Return symbols.Where(Function(s) IsValidAccessibleClassOrContainer(s, typeOrAssemblySymbol))
Return symbols.WhereAsArray(Function(s) IsValidAccessibleClassOrContainer(s, typeOrAssemblySymbol))
Else ' implementsContext
' In an interface's Implements statement, show nothing.
If isInterface Then
Return SpecializedCollections.EmptyEnumerable(Of ISymbol)()
Return ImmutableArray(Of ISymbol).Empty
End If
Return symbols.Where(Function(s) IsValidAccessibleInterfaceOrContainer(s, typeOrAssemblySymbol))
Return symbols.WhereAsArray(Function(s) IsValidAccessibleInterfaceOrContainer(s, typeOrAssemblySymbol))
End If
End If
End If
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册