/// <summary>
        /// Returns a string for a return tag if one is necessary.
        /// </summary>
        /// <param name="position">Position of the last slash in the triple slash comment</param>
        /// <returns>Return tag line as a string.</returns>
        private string GetReturnTag(int position)
        {
            string shouldCreate = StubUtils.ShouldCreateReturnTag(position, this.view.TextSnapshot);

            string result = NewLine() + "@returns {" + shouldCreate.Trim() + "}";

            return(result);
        }
        private void CreateMethodComment(ITextChange change)
        {
            int    position = change.NewEnd;
            string text     = this.view.TextSnapshot.ToString();

            using (ITextEdit editor = this.view.TextBuffer.CreateEdit())
            {
                try
                {
                    this.tabs = StubUtils.GetIndention(position, this.view.TextSnapshot);
                    string summaryString = StubUtils.Options.MultiLineSummary ? NewLine() : "";


                    string parameters = GetFunctionParameters(position);
                    string returnTag  = GetReturnTag(position);


                    string commentBody = summaryString + parameters + returnTag;
                    string autoComment = this.tabs + "/**" + commentBody;
                    if (!String.IsNullOrEmpty(commentBody))
                    {
                        autoComment += Environment.NewLine + this.tabs;
                    }

                    autoComment += " */";


                    int  lineStart     = this.view.TextSnapshot.GetLineFromPosition(position).Start.Position;
                    Span firstLineSpan = new Span(lineStart, change.NewSpan.End - lineStart);
                    editor.Replace(firstLineSpan, autoComment);

                    ITextSnapshot after = editor.Apply();

                    ////Move the caret back at the comment description

                    //int lineNumber = after.GetLineNumberFromPosition(change.NewPosition);
                    //var lineSnapShotPoint = after.GetLineFromLineNumber(lineNumber).End;
                    //this.view.Caret.MoveTo(lineSnapShotPoint);

                    //view.Caret.MoveTo(
                    //    view.GetTextViewLineContainingBufferPosition(
                    //        after.GetLineFromPosition(
                    //            after.GetText().IndexOf(autoComment)).Start));


                    //view.Caret.MoveTo(
                    //    view.GetTextViewLineContainingBufferPosition(
                    //        view.TextSnapshot.GetLineFromPosition(
                    //            view.TextSnapshot.GetText().IndexOf(fn)).Start));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ERROR_MSG_PREFIX + ex.Message);
                }
            }
        }
        private string GetFunctionParameters(int position)
        {
            var parameters = StubUtils.GetFunctionParameters(position, this.view.TextSnapshot);
            var result     = "";

            foreach (string param in parameters)
            {
                string name = StubUtils.GetParamName(param);
                string type = StubUtils.GetParamType(param);
                if (!String.IsNullOrEmpty(name))
                {
                    result += NewLine() + CreateParamString(name, type);
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        public static string[] GetFunctionParameters(int position, ITextSnapshot capture)
        {
            int openFunctionLine = capture.GetLineNumberFromPosition(position - 1) + 1;
            var prevLine         = capture.GetLineFromLineNumber(openFunctionLine).GetText();

            int firstParenPosition = capture.GetLineFromLineNumber(openFunctionLine).Start
                                     + prevLine.IndexOf('(')
                                     + 1;


            int lastParenPosition = -1;

            if (prevLine.IndexOf(')') > 0)
            {
                lastParenPosition = capture.GetLineFromLineNumber(openFunctionLine).Start + prevLine.IndexOf(')', prevLine.IndexOf('('));
            }
            else
            {
                do
                {
                    openFunctionLine++;
                    prevLine = capture.GetLineFromLineNumber(openFunctionLine).GetText();
                } while (!prevLine.Contains(")"));

                lastParenPosition = capture.GetLineFromLineNumber(openFunctionLine).Start + prevLine.IndexOf(")");
            }


            return(StubUtils
                   .RemoveComments(capture
                                   .GetText()
                                   .Substring(firstParenPosition, (lastParenPosition - firstParenPosition)))
                   .Split(',')
                   .Select(param => param.Trim())
                   .ToArray());
        }