private XSharpSignature CreateSignature(ITextBuffer textBuffer, string methodSig, string methodDoc, ITrackingSpan span, bool comma, bool isCtor) { XSharpProjectPackage.Instance.DisplayOutPutMessage("XSharpSignatureHelpSource.CreateSignature()"); XSharpSignature sig = new XSharpSignature(textBuffer, methodSig, methodDoc, null); // 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 string[] pars; if (isCtor) { pars = methodSig.Split(new char[] { '{', ',', '}' }); } else { 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 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)); paramList.Add(new XSharpParameter("", locus, param, sig)); } } sig.Parameters = new ReadOnlyCollection <IParameter>(paramList); sig.ApplicableToSpan = span; sig.ComputeCurrentParameter(); return(sig); }
internal void ComputeCurrentParameter() { //the number of commas in the string is the index of the current parameter string sigText = ApplicableToSpan.GetText(m_textBuffer.CurrentSnapshot); int currentIndex = 0; int commaCount = 0; while (currentIndex < sigText.Length) { int commaIndex = sigText.IndexOf(',', currentIndex); if (commaIndex == -1) { break; } commaCount++; currentIndex = commaIndex + 1; } // 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) { XSharpSignature sig = this.m_session.SelectedSignature as XSharpSignature; sig.CurrentParameter = null; } else { this.m_session.SelectedSignature = signatures[0]; XSharpSignature sig = this.m_session.SelectedSignature as XSharpSignature; sig.CurrentParameter = signatures[0].Parameters[commaCount]; } }