Пример #1
0
    System.Windows.Documents.Section _FormatText(int iSel, bool userSelected)
    {
        _data.iSelected = iSel;
        if (userSelected)
        {
            _data.iUserSelected = iSel;
        }

        var     r           = _data.r;
        ISymbol currentItem = null;
        SignatureHelpParameter currentParameter = null;
        var x = new CiText();

        //print.clear();
        for (int i = 0; i < r.Items.Count; i++)
        {
            var sh = r.Items[i];
            if (sh is AbstractSignatureHelpProvider.SymbolKeySignatureHelpItem kk)
            {
                var sym = kk.Symbol;
                if (i == iSel)
                {
                    currentItem = sym;
                }
                x.StartOverload(i == iSel, i);
#if false
                x.AppendTaggedParts(sh.PrefixDisplayParts);                 //works, but formats not as I like (too much garbage). Has bugs with tuples.
#else
                //if(nt != null) {
                //	print.it(1, nt.IsGenericType, nt.IsTupleType, nt.IsUnboundGenericType, nt.Arity, nt.CanBeReferencedByName);
                //	print.it(2, nt.IsAnonymousType, nt.IsDefinition, nt.IsImplicitlyDeclared, nt.Kind, nt.TypeKind);
                //	print.it(3, nt.MemberNames);
                //	print.it(4, nt.Name, nt.MetadataName, nt.OriginalDefinition, nt.TupleUnderlyingType);
                //	print.it("TypeParameters:");
                //	print.it(nt.TypeParameters);
                //	print.it("TypeArguments:");
                //	print.it(nt.TypeArguments);
                //	print.it("TupleElements:");
                //	try { var te = nt.TupleElements; if(!te.IsDefault) print.it(te); } catch(Exception e1) { print.it(e1.ToStringWithoutStack()); }
                //	print.it("---");
                //}

                int isTuple = 0;                 //1 ValueTuple<...>, 2 (...)
                var nt      = sym as INamedTypeSymbol;
                if (nt != null && nt.IsTupleType)
                {
                    isTuple = nt.IsDefinition ? 1 : 2;
                }

                if (isTuple == 1)
                {
                    x.Append("ValueTuple");                               //AppendSymbolWithoutParameters formats incorrectly
                }
                else if (isTuple == 0)
                {
                    x.AppendSymbolWithoutParameters(sym);
                }
                string b1 = "(", b2 = ")";
                if (nt != null)
                {
                    if (nt.IsGenericType && isTuple != 2)
                    {
                        b1 = "<"; b2 = ">";
                    }
                }
                else if (sym is IPropertySymbol)
                {
                    b1 = "["; b2 = "]";
                }
                x.Append(b1);
#endif
                int iArg = r.ArgumentIndex, lastParam = sh.Parameters.Length - 1;
                int selParam = iArg <= lastParam ? iArg : (sh.IsVariadic ? lastParam : -1);
                if (!r.ArgumentName.NE())
                {
                    var pa = sh.Parameters;
                    for (int pi = 0; pi < pa.Length; pi++)
                    {
                        if (pa[pi].Name == r.ArgumentName)
                        {
                            selParam = pi; break;
                        }
                    }
                }
                x.AppendParameters(sym, selParam, sh);
                //x.AppendParameters(sh, selParam); //works, but formats not as I like (too much garbage)
#if false
                x.AppendTaggedParts(sh.SuffixDisplayParts);
#else
                x.Append(b2);
#endif
                if (i == iSel && selParam >= 0)
                {
                    currentParameter = sh.Parameters[selParam];
                }
                x.EndOverload(i == iSel);
            }
            else
            {
                Debug_.Print(sh);
            }
        }

        if (currentItem != null)
        {
            var    tt        = r.Items[iSel].DocumentationFactory?.Invoke(default);