예제 #1
0
        public static CompletionItem Create(INamedTypeSymbol typeSymbol, string containingNamespace, string genericTypeSuffix)
        {
            PooledDictionary <string, string> propertyBuilder = null;

            if (typeSymbol.Arity > 0)
            {
                propertyBuilder = PooledDictionary <string, string> .GetInstance();

                propertyBuilder.Add(TypeAritySuffixName, GetAritySuffix(typeSymbol.Arity));
            }

            // Add tildes (ASCII: 126) to name and namespace as sort text:
            // 1. '~' before type name makes import items show after in-scope items
            // 2. ' ' before namespace makes types with identical type name but from different namespace all show up in the list,
            //    it also makes sure type with shorter name shows first, e.g. 'SomeType` before 'SomeTypeWithLongerName'.
            var sortTextBuilder = PooledStringBuilder.GetInstance();

            sortTextBuilder.Builder.AppendFormat(SortTextFormat, typeSymbol.Name, containingNamespace);

            return(CompletionItem.Create(
                       displayText: typeSymbol.Name,
                       filterText: typeSymbol.Name,
                       sortText: sortTextBuilder.ToStringAndFree(),
                       properties: propertyBuilder?.ToImmutableDictionaryAndFree(),
                       tags: GlyphTags.GetTags(typeSymbol.GetGlyph()),
                       rules: CompletionItemRules.Default,
                       displayTextPrefix: null,
                       displayTextSuffix: typeSymbol.Arity == 0 ? string.Empty : genericTypeSuffix,
                       inlineDescription: containingNamespace));
        }
예제 #2
0
        public static CompletionItem Create(INamedTypeSymbol typeSymbol, string containingNamespace)
        {
            PooledDictionary <string, string> propertyBuilder = null;

            if (typeSymbol.Arity > 0)
            {
                propertyBuilder = PooledDictionary <string, string> .GetInstance();

                propertyBuilder.Add(TypeAritySuffixName, GetAritySuffix(typeSymbol.Arity));
            }

            // Hack: add tildes (ASCII: 126) to name and namespace as sort text:
            // 1. '~' before type name makes import items show after in-scope items
            // 2. ' ' before namespace makes types with identical type name but from different namespace all show up in the list,
            //    it also makes sure type with shorter name shows first, e.g. 'SomeType` before 'SomeTypeWithLongerName'.
            var sortTextBuilder = PooledStringBuilder.GetInstance();

            sortTextBuilder.Builder.AppendFormat(SortTextFormat, typeSymbol.Name, containingNamespace);

            // 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.
            // 3. Editor support for resolving item text conflicts?
            return(CompletionItem.Create(
                       displayText: typeSymbol.Name,
                       filterText: typeSymbol.Name,
                       sortText: sortTextBuilder.ToStringAndFree(),
                       properties: propertyBuilder?.ToImmutableDictionaryAndFree(),
                       tags: GlyphTags.GetTags(typeSymbol.GetGlyph()),
                       rules: CompletionItemRules.Default,
                       displayTextPrefix: null,
                       displayTextSuffix: typeSymbol.Arity == 0 ? string.Empty : "<>",
                       inlineDescription: containingNamespace));
        }