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); }
private void InitDescription(XSourceEntity member) //, _VSOBJDESCOPTIONS flags, IVsObjectBrowserDescription3 description) { description = new List <Tuple <string, VSOBDESCRIPTIONSECTION> >(); string descText; if (member != null) { string modifier = ""; string access = ""; if ((member is XSourceTypeSymbol) && (member.Kind != Kind.Namespace)) { modifier = member.Modifiers.ToDisplayString(); access = member.Visibility.ToDisplayString(); } else if ((member is XSourceMemberSymbol) && ((member.Kind != Kind.Function) && (member.Kind != Kind.Procedure))) { modifier = member.Modifiers.ToDisplayString(); access = member.Visibility.ToDisplayString(); } // if (!string.IsNullOrEmpty(modifier)) { description.Add(Item(modifier + " ", VSOBDESCRIPTIONSECTION.OBDS_ATTRIBUTE)); } // if (!string.IsNullOrEmpty(access)) { description.Add(Item(access + " ", VSOBDESCRIPTIONSECTION.OBDS_ATTRIBUTE)); } // if (member.Kind != Kind.Field) { VSOBDESCRIPTIONSECTION descName = VSOBDESCRIPTIONSECTION.OBDS_MISC; descText = XSettings.FormatKeyword(member.Kind.DisplayName()) + " "; if (member.Kind == Kind.Constructor) { descName = VSOBDESCRIPTIONSECTION.OBDS_NAME; } description.Add(Item(descText, descName)); } if (member.Kind != Kind.Constructor) { descText = member.Name; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_NAME)); } // Parameters ? if (member.Kind.HasParameters()) { descText = "("; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC)); XSourceMemberSymbol realmember; XSourceTypeSymbol type = member as XSourceTypeSymbol; if (member.Kind == Kind.Delegate && type?.XMembers.Count > 0) { realmember = type.XMembers[0]; } else { realmember = member as XSourceMemberSymbol; } if (realmember != null && realmember.HasParameters) { // int paramNum = 1; foreach (IXParameterSymbol param in realmember.Parameters) { descText = param.Name; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_PARAM)); descText = param.ParamTypeDesc; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC)); descText = param.TypeName; // description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_TYPE)); // Need a comma ? if (paramNum < realmember.ParameterCount) { paramNum++; descText = ","; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_COMMA)); } } } descText = ")"; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC)); } if (member.Kind.HasReturnType()) { descText = XLiterals.AsKeyWord; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC)); descText = member.TypeName; description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_TYPE)); } description.Add(Item(null, VSOBDESCRIPTIONSECTION.OBDS_ENDDECL)); } // if (member.File?.Project != null) { string summary = null, returns = null, remarks = null; List <string> pNames = new List <string>(); List <string> pDescriptions = new List <string>(); if (member is XSourceMemberSymbol symbol1) { summary = XSharpXMLDocMember.GetMemberSummary(symbol1, member.File?.Project, out returns, out remarks); XSharpXMLDocMember.GetMemberParameters(symbol1, member.File?.Project, pNames, pDescriptions); } else if (member is XSourceTypeSymbol symbol) { summary = XSharpXMLDocMember.GetTypeSummary(symbol, member.File?.Project, out returns, out remarks); } if (!string.IsNullOrEmpty(summary)) { description.Add(Item(NEWLINE, VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(Item(SUMMARY, VSOBDESCRIPTIONSECTION.OBDS_NAME)); description.Add(Item(summary, VSOBDESCRIPTIONSECTION.OBDS_MISC)); } if (pNames.Count > 0) { description.Add(Item(NEWLINE, VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(Item(PARAMETERS, VSOBDESCRIPTIONSECTION.OBDS_NAME)); for (int i = 0; i < pNames.Count; i++) { description.Add(Item(NEWLINE + pNames[i], VSOBDESCRIPTIONSECTION.OBDS_PARAM)); description.Add(Item(" : ", VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(Item(pDescriptions[i], VSOBDESCRIPTIONSECTION.OBDS_MISC)); } } if (!string.IsNullOrEmpty(returns)) { description.Add(Item(NEWLINE, VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(Item(RETURNS, VSOBDESCRIPTIONSECTION.OBDS_NAME)); description.Add(Item(returns, VSOBDESCRIPTIONSECTION.OBDS_MISC)); } if (!string.IsNullOrEmpty(remarks)) { description.Add(Item(NEWLINE, VSOBDESCRIPTIONSECTION.OBDS_MISC)); description.Add(Item(REMARKS, VSOBDESCRIPTIONSECTION.OBDS_NAME)); description.Add(Item(remarks, VSOBDESCRIPTIONSECTION.OBDS_MISC)); } } }
public ClassifiedTextRun[] WPFPrototype() { var content = new List <ClassifiedTextRun>(); string name = ""; if (!this.typeMember.Kind.IsGlobalTypeMember()) { name = this.typeMember.Parent.Name; var pos = name.IndexOfAny(new char[] { '`', '<' }); { if (pos > 0) { name = name.Substring(0, pos); } } if (this.typeMember.IsStatic) { name += "."; } else { name += ":"; } } name += this.typeMember.Name; content.addText(name); if (this.typeMember.Kind.HasParameters()) { content.addKeyword(this.typeMember.Kind == XSharpModel.Kind.Constructor ? "{" : "("); bool first = true; foreach (var var in this.typeMember.Parameters) { if (!first) { content.addText(", "); } first = false; addVarInfo(content, var); } content.addKeyword(this.typeMember.Kind == XSharpModel.Kind.Constructor ? "}" : ")"); } // // if (!String.IsNullOrEmpty(this.typeMember.Value)) { var text = " := " + this.typeMember.Value; content.addText(text); } if (this.typeMember.Kind.HasReturnType() && !String.IsNullOrEmpty(this.typeMember.TypeName)) { content.addReturnType(typeMember.TypeName.GetXSharpTypeName()); } string returns; string remarks; var xmldesc = XSharpXMLDocMember.GetMemberSummary(this.typeMember, null, out returns, out remarks); content.addSummary(xmldesc); content.addReturns(returns); content.addRemarks(remarks); content.addLocation(typeMember.Location); return(content.ToArray()); }