static void VisitNamespace( INamespaceSymbol symbol, string containingNamespace, ArrayBuilder <TypeImportCompletionItemInfo> builder, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); containingNamespace = ConcatNamespace(containingNamespace, symbol.Name); foreach (var memberNamespace in symbol.GetNamespaceMembers()) { VisitNamespace(memberNamespace, containingNamespace, builder, cancellationToken); } var overloads = PooledDictionary <string, TypeOverloadInfo> .GetInstance(); var types = symbol.GetTypeMembers(); // Iterate over all top level internal and public types, keep track of "type overloads". foreach (var type in types) { // No need to check accessibility here, since top level types can only be internal or public. if (type.CanBeReferencedByName) { overloads.TryGetValue(type.Name, out var overloadInfo); overloads[type.Name] = overloadInfo.Aggregate(type); } } foreach (var pair in overloads) { var overloadInfo = pair.Value; // Create CompletionItem for non-generic type overload, if exists. if (overloadInfo.NonGenericOverload != null) { var item = TypeImportCompletionItem.Create(overloadInfo.NonGenericOverload, containingNamespace); var isPublic = overloadInfo.NonGenericOverload.DeclaredAccessibility == Accessibility.Public; item.IsCached = true; builder.Add(new TypeImportCompletionItemInfo(item, isPublic)); } // Create one CompletionItem for all generic type overloads, if there's any. // For simplicity, we always show the type symbol with lowest arity in CompletionDescription // and without displaying the total number of overloads. if (overloadInfo.BestGenericOverload != null) { // If any of the generic overloads is public, then the completion item is considered public. var item = TypeImportCompletionItem.Create(overloadInfo.BestGenericOverload, containingNamespace); var isPublic = overloadInfo.ContainsPublicGenericOverload; item.IsCached = true; builder.Add(new TypeImportCompletionItemInfo(item, isPublic)); } } overloads.Free(); }
static void AddItems(ImmutableArray <CompletionItem> items, CompletionContext completionContext, HashSet <string> namespacesInScope, TelemetryCounter counter) { foreach (var item in items) { var containingNamespace = TypeImportCompletionItem.GetContainingNamespace(item); if (!namespacesInScope.Contains(containingNamespace)) { // We can return cached item directly, item's span will be fixed by completion service. // On the other hand, because of this (i.e. mutating the span of cached item for each run), // the provider can not be used as a service by components that might be run in parallel // with completion, which would be a race. completionContext.AddItem(item); counter.ItemsCount++;; } } }
static void AddItems(TypeImportCompletionItemInfo itemInfo, bool isInternalsVisible, CompletionContext completionContext, HashSet <string> namespacesInScope) { if (itemInfo.IsPublic || isInternalsVisible) { var containingNamespace = TypeImportCompletionItem.GetContainingNamespace(itemInfo.Item); if (!namespacesInScope.Contains(containingNamespace)) { // We can return cached item directly, item's span will be fixed by completion service. // On the other hand, because of this (i.e. mutating the span of cached item for each run), // the provider can not be used as a service by components that might be run in parallel // with completion, which would be a race. completionContext.AddItem(itemInfo.Item); } } }