/// <summary> /// Short contextual details to display in tips /// </summary> /// <param name="member">Member data</param> /// <param name="highlightParam">Parameter to detail</param> /// <returns></returns> static public string GetTipShortDetails(ASMember member, string highlightParam) { if (member == null || member.Comments == null || !ASContext.DocumentationInTips) { return(""); } CommentBlock cb = ParseComment(member.Comments); string details = " …"; // get parameter detail if (highlightParam != null && highlightParam.Length > 0) { if (cb.ParamName != null) { for (int i = 0; i < cb.ParamName.Count; i++) { if (highlightParam == (string)cb.ParamName[i]) { details += "\n[B]" + highlightParam + ":[/B] " + (string)cb.ParamDesc[i]; return(details); } } } } // get description extract if (ASContext.DescriptionInTips) { if (cb.InfoTip != null && cb.InfoTip.Length > 0) { details += "\n" + cb.InfoTip; } else if (cb.Description != null && cb.Description.Length > 0) { string[] lines = cb.Description.Split('\n'); int n = Math.Min(lines.Length, 2); for (int i = 0; i < n; i++) { details += "\n" + lines[i]; } if (lines.Length > 2) { details += " …"; } } } return(details); }
/// <summary> /// Extract member comments for display in the completion list /// </summary> /// <param name="member">Member data</param> /// <param name="member">Parameter to highlight</param> /// <returns>Formated comments</returns> static public string GetTipFullDetails(ASMember member, string highlightParam) { if (member == null || member.Comments == null || !ASContext.DocumentationInTips) { return(""); } CommentBlock cb = ParseComment(member.Comments); // details string details = ""; if (cb.Description.Length > 0) { string[] lines = cb.Description.Split('\n'); int n = Math.Min(lines.Length, ASContext.TipsDescriptionMaxLines); for (int i = 0; i < n; i++) { details += lines[i] + "\n"; } if (lines.Length > ASContext.TipsDescriptionMaxLines) { details = details.TrimEnd() + " …\n"; } } // @usage if (cb.TagName != null) { bool hasUsage = false; for (int i = 0; i < cb.TagName.Count; i++) { if ((string)cb.TagName[i] == "usage") { hasUsage = true; details += "\n " + (string)cb.TagDesc[i]; } } if (hasUsage) { details += "\n"; } } // @param if (cb.ParamName != null && cb.ParamName.Count > 0) { details += "\nParam:"; for (int i = 0; i < cb.ParamName.Count; i++) { details += "\n "; if (highlightParam == (string)cb.ParamName[i]) { details += "[B]" + highlightParam + "[/B]: "; } else { details += cb.ParamName[i] + ": "; } details += (string)cb.ParamDesc[i]; } } // @return if (cb.Return != null) { details += "\n\nReturn:\n " + cb.Return; } return("\n\n" + details.Trim()); }
static private CommentBlock ParseComment(string comment) { // cleanup comment = Regex.Replace(comment, "^[ \t*]+", ""); comment = Regex.Replace(comment, "[ \t*]+$", "", RegexOptions.RightToLeft); string[] lines = Regex.Split(comment, "[\r\n]+"); int p; comment = ""; foreach (string line in lines) { p = line.IndexOf('*'); if (p < 0) { comment += '\n' + line.TrimStart(); } else if (p + 1 < line.Length) { if (line[p + 1] == ' ') { p++; } comment += '\n' + line.Substring(p + 1); } } // extraction CommentBlock cb = new CommentBlock(); MatchCollection tags = Regex.Matches(comment, "\n@(?<tag>[a-z]+)\\s"); if (tags.Count == 0) { cb.Description = comment.Trim(); return(cb); } if (tags[0].Index > 0) { cb.Description = comment.Substring(0, tags[0].Index).Trim(); } else { cb.Description = ""; } cb.TagName = new ArrayList(); cb.TagDesc = new ArrayList(); Group gTag; for (int i = 0; i < tags.Count; i++) { gTag = tags[i].Groups["tag"]; string tag = gTag.Value; int start = gTag.Index + gTag.Length; int end = (i < tags.Count - 1) ? tags[i + 1].Index : comment.Length; string desc = comment.Substring(start, end - start).Trim(); if (tag == "param") { Match mParam = Regex.Match(desc, "(?<var>[\\w$]+)\\s"); if (mParam.Success) { Group mVar = mParam.Groups["var"]; if (cb.ParamName == null) { cb.ParamName = new ArrayList(); cb.ParamDesc = new ArrayList(); } cb.ParamName.Add(mVar.Value); cb.ParamDesc.Add(desc.Substring(mVar.Index + mVar.Length).TrimStart()); } } else if (tag == "return") { cb.Return = desc; } else if (tag == "infotip") { cb.InfoTip = desc; if (cb.Description.Length == 0) { cb.Description = cb.InfoTip; } } cb.TagName.Add(tag); cb.TagDesc.Add(desc); } return(cb); }
static private CommentBlock ParseComment(string comment) { // cleanup comment = Regex.Replace(comment, "^[ \t*]+", ""); comment = Regex.Replace(comment, "[ \t*]+$", "", RegexOptions.RightToLeft); string[] lines = Regex.Split(comment, "[\r\n]+"); int p; comment = ""; foreach(string line in lines) { p = line.IndexOf('*'); if (p < 0) comment += '\n'+line.TrimStart(); else if (p+1 < line.Length) { if (line[p+1] == ' ') p++; comment += '\n'+line.Substring(p+1); } } // extraction CommentBlock cb = new CommentBlock(); MatchCollection tags = Regex.Matches(comment, "\n@(?<tag>[a-z]+)\\s"); if (tags.Count == 0) { cb.Description = comment.Trim(); return cb; } if (tags[0].Index > 0) cb.Description = comment.Substring(0, tags[0].Index).Trim(); else cb.Description = ""; cb.TagName = new ArrayList(); cb.TagDesc = new ArrayList(); Group gTag; for(int i=0; i<tags.Count; i++) { gTag = tags[i].Groups["tag"]; string tag = gTag.Value; int start = gTag.Index+gTag.Length; int end = (i<tags.Count-1) ? tags[i+1].Index : comment.Length; string desc = comment.Substring(start, end-start).Trim(); if (tag == "param") { Match mParam = Regex.Match(desc, "(?<var>[\\w$]+)\\s"); if (mParam.Success) { Group mVar = mParam.Groups["var"]; if (cb.ParamName == null) { cb.ParamName = new ArrayList(); cb.ParamDesc = new ArrayList(); } cb.ParamName.Add(mVar.Value); cb.ParamDesc.Add(desc.Substring(mVar.Index+mVar.Length).TrimStart()); } } else if (tag == "return") { cb.Return = desc; } else if (tag == "infotip") { cb.InfoTip = desc; if (cb.Description.Length == 0) cb.Description = cb.InfoTip; } cb.TagName.Add(tag); cb.TagDesc.Add(desc); } return cb; }