diff --git a/src/Features/Core/Portable/Completion/Providers/TypeImportCompletionItem.cs b/src/Features/Core/Portable/Completion/Providers/TypeImportCompletionItem.cs index b976dbc73e91849898b33b74260c1260b23f8192..11fa198c01952064ae4dfd8afe60ef57abe04532 100644 --- a/src/Features/Core/Portable/Completion/Providers/TypeImportCompletionItem.cs +++ b/src/Features/Core/Portable/Completion/Providers/TypeImportCompletionItem.cs @@ -14,27 +14,27 @@ internal static class TypeImportCompletionItem private const string GenericTypeNameManglingString = "`"; private static readonly string[] s_aritySuffixesOneToNine = { "`1", "`2", "`3", "`4", "`5", "`6", "`7", "`8", "`9" }; - private const string ContainingNamespaceName = nameof(ContainingNamespaceName); private const string TypeAritySuffixName = nameof(TypeAritySuffixName); public static CompletionItem Create(INamedTypeSymbol typeSymbol, string containingNamespace) { - var builder = PooledDictionary.GetInstance(); - builder.Add(ContainingNamespaceName, containingNamespace); + PooledDictionary builder = null; if (typeSymbol.Arity > 0) { + builder = PooledDictionary.GetInstance(); builder.Add(TypeAritySuffixName, GetAritySuffix(typeSymbol.Arity)); } // TODO: // 1. Suffix should be language specific, i.e. `(Of ...)` if triggered from VB. - // 2. Sort the import items to be after in-scope symbols in a less hacky way. + // 2. Add editor support for multiple items with identical display text but different inline description. + // 3. Sort the import items to be after in-scope symbols in a less hacky way. return CompletionItem.Create( displayText: typeSymbol.Name, filterText: typeSymbol.Name, sortText: "~" + typeSymbol.Name, // Hack: prepend tilde (ASCII: 126) to make import items show after in-scope items - properties: builder.ToImmutableDictionaryAndFree(), + properties: builder?.ToImmutableDictionaryAndFree(), tags: GlyphTags.GetTags(typeSymbol.GetGlyph()), rules: CompletionItemRules.Default, displayTextPrefix: null, @@ -50,11 +50,7 @@ public static CompletionItem Create(INamedTypeSymbol typeSymbol, string containi } public static string GetContainingNamespace(CompletionItem item) - { - return item.Properties.TryGetValue(ContainingNamespaceName, out var containingNamespace) - ? containingNamespace - : null; - } + => item.InlineDescription; public static async Task GetCompletionDescriptionAsync(Document document, CompletionItem item, CancellationToken cancellationToken) { @@ -97,18 +93,14 @@ private static string GetFullyQualifiedName(string namespaceName, string typeNam private static string GetMetadataName(CompletionItem item) { - if (item.Properties.TryGetValue(ContainingNamespaceName, out var containingNamespace)) + var containingNamespace = GetContainingNamespace(item); + var fullyQualifiedName = GetFullyQualifiedName(containingNamespace, item.DisplayText); + if (item.Properties.TryGetValue(TypeAritySuffixName, out var aritySuffix)) { - var fullyQualifiedName = GetFullyQualifiedName(containingNamespace, item.DisplayText); - if (item.Properties.TryGetValue(TypeAritySuffixName, out var aritySuffix)) - { - return fullyQualifiedName + aritySuffix; - } - - return fullyQualifiedName; + return fullyQualifiedName + aritySuffix; } - return null; + return fullyQualifiedName; } } }