예제 #1
0
        internal void ComputeCurrentParameter()
        {
            //the number of commas in the string is the index of the current parameter
            string sigText = ApplicableToSpan.GetText(m_textBuffer.CurrentSnapshot);

            var commaCount = XSharpVsSignature.CalculateCommaPosition(sigText, sigText.Length, m_textBuffer);

            //
            List <ISignature> signatures = new List <ISignature>();

            foreach (ISignature sig in this.m_session.Signatures)
            {
                if (sig.Parameters.Count > commaCount)
                {
                    signatures.Add(sig);
                }
            }
            //
            if (signatures.Count == 0)
            {
                var sig = this.m_session.SelectedSignature as XSharpVsSignature;
                sig.CurrentParameter = null;
            }
            else
            {
                this.m_session.SelectedSignature = signatures[0];
                var sig = this.m_session.SelectedSignature as XSharpVsSignature;
                sig.CurrentParameter = signatures[0].Parameters[commaCount];
            }
        }
예제 #2
0
        private XSharpVsSignature CreateSignature(ITextBuffer textBuffer, IXMemberSymbol member, string methodSig, ITrackingSpan span, bool isCtor, XFile file)
        {
            var    doc = "";
            string returns;
            string remarks;

            if (member != null)
            {
                doc = XSharpXMLDocMember.GetMemberSummary(member, file.Project, out returns, out remarks);
            }

            Debug($"XSharpSignatureHelpSource.CreateSignature( {methodSig})");
            var sig          = new XSharpVsSignature(textBuffer, methodSig, doc, null);
            var names        = new List <string>();
            var descriptions = new List <string>();

            if (member != null)
            {
                XSharpXMLDocMember.GetMemberParameters(member, file.Project, names, descriptions);
            }
            // Moved : Done in the XSharpSignature constructor
            // textBuffer.Changed += new EventHandler<TextContentChangedEventArgs>(sig.OnSubjectBufferChanged);

            // find the parameters in the method signature :
            // MyMethod( param1 AS TYPE1, param2 AS TYPE2 ) AS TYPE3 will turn to
            // 0 : MyMethod
            // 1 : param1 AS TYPE1
            // 2 : param2 AS TYPE2
            // 3 : AS TYPE3
            var pars = methodSig.Split(new char[] { '(', '{', ',', '}', ')' });
            List <IParameter> paramList = new List <IParameter>();
            int locusSearchStart        = 0;

            // i = 1 to skip the MethodName; Length-1 to Skip the ReturnType
            while (names.Count < pars.Length)
            {
                names.Add("");
                descriptions.Add("");
            }
            for (int i = 1; i < pars.Length - 1; i++)
            {
                string param = pars[i].Trim();
                if (string.IsNullOrEmpty(param))
                {
                    continue;
                }

                //find where this parameter is located in the method signature
                int locusStart = methodSig.IndexOf(param, locusSearchStart);
                if (locusStart >= 0)
                {
                    Span locus = new Span(locusStart, param.Length);
                    locusSearchStart = locusStart + param.Length;
                    // paramList.Add(new XSharpParameter("Documentation for the parameter.", locus, param, sig));
                    if (!string.IsNullOrEmpty(names[i - 1]))
                    {
                        param = names[i - 1];
                    }
                    paramList.Add(new XSharpVsParameter(descriptions[i - 1], locus, param, sig));
                }
            }

            sig.Parameters       = new ReadOnlyCollection <IParameter>(paramList);
            sig.ApplicableToSpan = span;
            sig.ComputeCurrentParameter();
            return(sig);
        }