private SymbolKeyResolution ReadWorker(SymbolKeyType type) { switch (type) { case SymbolKeyType.Alias: return(AliasSymbolKey.Resolve(this)); case SymbolKeyType.BodyLevel: return(BodyLevelSymbolKey.Resolve(this)); case SymbolKeyType.ConstructedMethod: return(ConstructedMethodSymbolKey.Resolve(this)); case SymbolKeyType.NamedType: return(NamedTypeSymbolKey.Resolve(this)); case SymbolKeyType.ErrorType: return(ErrorTypeSymbolKey.Resolve(this)); case SymbolKeyType.Field: return(FieldSymbolKey.Resolve(this)); case SymbolKeyType.DynamicType: return(DynamicTypeSymbolKey.Resolve(this)); case SymbolKeyType.Method: return(MethodSymbolKey.Resolve(this)); case SymbolKeyType.Namespace: return(NamespaceSymbolKey.Resolve(this)); case SymbolKeyType.PointerType: return(PointerTypeSymbolKey.Resolve(this)); case SymbolKeyType.Parameter: return(ParameterSymbolKey.Resolve(this)); case SymbolKeyType.Property: return(PropertySymbolKey.Resolve(this)); case SymbolKeyType.ArrayType: return(ArrayTypeSymbolKey.Resolve(this)); case SymbolKeyType.Assembly: return(AssemblySymbolKey.Resolve(this)); case SymbolKeyType.TupleType: return(TupleTypeSymbolKey.Resolve(this)); case SymbolKeyType.Module: return(ModuleSymbolKey.Resolve(this)); case SymbolKeyType.Event: return(EventSymbolKey.Resolve(this)); case SymbolKeyType.ReducedExtensionMethod: return(ReducedExtensionMethodSymbolKey.Resolve(this)); case SymbolKeyType.TypeParameter: return(TypeParameterSymbolKey.Resolve(this)); case SymbolKeyType.AnonymousType: return(AnonymousTypeSymbolKey.Resolve(this)); case SymbolKeyType.AnonymousFunctionOrDelegate: return(AnonymousFunctionOrDelegateSymbolKey.Resolve(this)); case SymbolKeyType.TypeParameterOrdinal: return(TypeParameterOrdinalSymbolKey.Resolve(this)); } throw new NotImplementedException(); }
public ImmutableArray <CompletionItem> GetItemsForContext( Compilation originCompilation, string language, string genericTypeSuffix, bool isAttributeContext, bool isCaseSensitive, bool hideAdvancedMembers) { if (AssemblySymbolKey.Resolve(originCompilation).Symbol is not IAssemblySymbol assemblySymbol) { return(ImmutableArray <CompletionItem> .Empty); } var isSameLanguage = Language == language; var isInternalsVisible = originCompilation.Assembly.IsSameAssemblyOrHasFriendAccessTo(assemblySymbol); using var _ = ArrayBuilder <CompletionItem> .GetInstance(out var builder); // PERF: try set the capacity upfront to avoid allocation from Resize if (!isAttributeContext) { if (isInternalsVisible) { builder.EnsureCapacity(ItemInfos.Length); } else { builder.EnsureCapacity(PublicItemCount); } } foreach (var info in ItemInfos) { if (!info.IsPublic && !isInternalsVisible) { continue; } // Option to show advanced members is false so we need to exclude them. if (hideAdvancedMembers && info.IsEditorBrowsableStateAdvanced) { continue; } var item = info.Item; if (isAttributeContext) { // Don't show non attribute item in attribute context if (!info.IsAttribute) { continue; } // We are in attribute context, will not show or complete with "Attribute" suffix. item = GetAppropriateAttributeItem(info.Item, isCaseSensitive); } // C# and VB the display text is different for generics, i.e. <T> and (Of T). For simpllicity, we only cache for one language. // But when we trigger in a project with different language than when the cache entry was created for, we will need to // change the generic suffix accordingly. if (!isSameLanguage && info.IsGeneric) { // We don't want to cache this item. item = ImportCompletionItem.CreateItemWithGenericDisplaySuffix(item, genericTypeSuffix); } builder.Add(item); } return(builder.ToImmutable());