Beispiel #1
0
        /// <summary>
        /// Extract member comments for display in the completion list
        /// </summary>
        /// <param name="member">Member data</param>
        /// <param name="highlightParam">Parameter to highlight</param>
        /// <returns>Formated comments</returns>
        static public string GetTipFullDetails(MemberModel member, string highlightParam)
        {
            if (member == null || member.Comments == null || !ASContext.CommonSettings.SmartTipsEnabled)
            {
                return("");
            }
            CommentBlock cb = ParseComment(member.Comments);

            cb.IsFunctionWithArguments = IsFunctionWithArguments(member);
            return(GetTipFullDetails(cb, highlightParam));
        }
Beispiel #2
0
 /// <summary>
 /// Extract comments for display in the completion list
 /// </summary>
 /// <param name="cb">Parsed comments</param>
 /// <returns>Formated comments</returns>
 static public string GetTipFullDetails(CommentBlock cb, string highlightParam)
 {
     string details = "";
     if (cb.Description.Length > 0) 
     {
         string[] lines = cb.Description.Split('\n');
         int n = Math.Min(lines.Length, ASContext.CommonSettings.DescriptionLinesLimit);
         for(int i=0; i<n; i++) details += lines[i]+"\n";
         if (lines.Length > ASContext.CommonSettings.DescriptionLinesLimit) details = details.TrimEnd() + " \u2026\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 += MethodCallTip.HLBgStyleBeg 
                         + MethodCallTip.HLTextStyleBeg + highlightParam + ":" + MethodCallTip.HLTextStyleEnd + " "
                         + (string)cb.ParamDesc[i] 
                         + MethodCallTip.HLBgStyleEnd;
             }
             else details += cb.ParamName[i] + ": " + (string)cb.ParamDesc[i];
         }
     }
     
     // @return
     if (cb.Return != null)
     {
         details += "\n\nReturn:\n    "+cb.Return;
     }
     return "\n\n"+details.Trim();
 }
Beispiel #3
0
        /// <summary>
        /// Short contextual details to display in tips
        /// </summary>
        /// <param name="cb">Parsed comments</param>
        /// <returns>Formated comments</returns>
        static public string GetTipShortDetails(CommentBlock cb, string highlightParam)
        {
            string details = "";
            
            // get parameter detail
            if (highlightParam != null && highlightParam.Length > 0 && cb.ParamName != null)
            {
                for(int i=0; i<cb.ParamName.Count; i++)
                {
                    if (highlightParam == (string)cb.ParamName[i])
                    {
                        details += "\n" + MethodCallTip.HLTextStyleBeg + highlightParam + ":" + MethodCallTip.HLTextStyleEnd 
                                + " " + Get2LinesOf((string)cb.ParamDesc[i], true).TrimStart();
                        return details;
                    }
                }
            }
            // get description extract
            if (ASContext.CommonSettings.SmartTipsEnabled)
            {
                if (cb.InfoTip != null && cb.InfoTip.Length > 0)
                    details += "\n"+cb.InfoTip;
                else if (cb.Description != null && cb.Description.Length > 0) 
                    details += Get2LinesOf(cb.Description, cb.IsFunctionWithArguments);
            }

            return details;
        }
Beispiel #4
0
 static public CommentBlock ParseComment(string comment)
 {
     // cleanup
     comment = comment.Replace("&lt;", "<").Replace("&gt;", ">").Replace("&nbsp;", " ");
     comment = reKeepTags.Replace(comment, "[$1]");
     comment = reSpecialTags.Replace(comment, match =>
     {
         string tag = match.Groups[2].Value;
         bool open = match.Groups[1].Length == 0;
         switch (tag)
         {
             case "small": return open ? "[size=-2]" : "[/size]";
             case "code": return open ? "[font=Courier New]" : "[/font]";
             case "strong": return open ? "[b]" : "[/b]";
             case "em": return open ? "[i]" : "[/i]";
         }
         return "";
     });
     comment = reStripTags.Replace(comment, "");
     string[] lines = reNewLine.Split(comment);
     char[] trim = new char[] { ' ', '\t', '*' };
     bool addNL = false;
     comment = "";
     foreach (string line in lines)
     {
         string temp = line.Trim(trim);
         if (addNL) comment += '\n' + temp;
         else { comment += temp; addNL = true; }
     }
     // extraction
     CommentBlock cb = new CommentBlock();
     MatchCollection tags = reDocTags.Matches(comment);
     
     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 = reSplitParams.Match(desc);
             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;
     
 }
Beispiel #5
0
        /// <summary>
        /// Extract comments for display in the completion list
        /// </summary>
        /// <param name="cb">Parsed comments</param>
        /// <returns>Formated comments</returns>
        static public string GetTipFullDetails(CommentBlock cb, string highlightParam)
        {
            string details = "";

            if (cb.Description.Length > 0)
            {
                string[] lines = cb.Description.Split('\n');
                int      n     = Math.Min(lines.Length, ASContext.CommonSettings.DescriptionLinesLimit);
                for (int i = 0; i < n; i++)
                {
                    details += lines[i] + "\n";
                }
                if (lines.Length > ASContext.CommonSettings.DescriptionLinesLimit)
                {
                    details = details.TrimEnd() + " \u2026\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 += MethodCallTip.HLBgStyleBeg
                                   + MethodCallTip.HLTextStyleBeg + highlightParam + ":" + MethodCallTip.HLTextStyleEnd + " "
                                   + (string)cb.ParamDesc[i]
                                   + MethodCallTip.HLBgStyleEnd;
                    }
                    else
                    {
                        details += cb.ParamName[i] + ": " + (string)cb.ParamDesc[i];
                    }
                }
            }

            // @return
            if (cb.Return != null)
            {
                details += "\n\nReturn:\n    " + cb.Return;
            }
            return("\n\n" + details.Trim());
        }
Beispiel #6
0
        static public CommentBlock ParseComment(string comment)
        {
            // cleanup
            comment = comment.Replace("&lt;", "<").Replace("&gt;", ">").Replace("&nbsp;", " ");
            comment = reKeepTags.Replace(comment, "[$1]");
            comment = reSpecialTags.Replace(comment, match =>
            {
                string tag = match.Groups[2].Value;
                bool open  = match.Groups[1].Length == 0;
                switch (tag)
                {
                case "small": return(open ? "[size=-2]" : "[/size]");

                case "code": return(open ? "[font=Courier New]" : "[/font]");

                case "strong": return(open ? "[b]" : "[/b]");

                case "em": return(open ? "[i]" : "[/i]");
                }
                return("");
            });
            comment = reStripTags.Replace(comment, "");
            string[] lines = reNewLine.Split(comment);
            char[]   trim  = new char[] { ' ', '\t', '*' };
            bool     addNL = false;

            comment = "";
            foreach (string line in lines)
            {
                string temp = line.Trim(trim);
                if (addNL)
                {
                    comment += '\n' + temp;
                }
                else
                {
                    comment += temp; addNL = true;
                }
            }
            // extraction
            CommentBlock    cb   = new CommentBlock();
            MatchCollection tags = reDocTags.Matches(comment);

            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 = reSplitParams.Match(desc);
                    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 public 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 public 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;
			
		}