Example #1
0
        /// <summary>
        /// Builds the comment stub and inserts it into the editor.
        /// </summary>
        /// <param name="position">The position of the last slash.</param>
        private void CreateStub(int position, ITextChange change)
        {
            string text = this._view.TextSnapshot.ToString();

            using (ITextEdit editor = this._view.TextBuffer.CreateEdit())
            {
                try
                {
                    this.tabs = StubUtils.GetIndention(position, this._view.TextSnapshot);
                    string summaryTag  = generateSummaryTag();
                    string parameters  = getFunctionParameters(position);
                    string returnTag   = getReturnTag(position);
                    string autoComment = summaryTag + parameters + returnTag;

                    int  lineStart     = this._view.TextSnapshot.GetLineFromPosition(position).Start.Position;
                    var  caretPosition = autoComment.IndexOf(StubUtils.CaretPlaceholder);
                    Span firstLineSpan = new Span(lineStart, change.NewSpan.End - lineStart);
                    autoComment = autoComment.Replace(StubUtils.CaretPlaceholder, "");

                    editor.Replace(firstLineSpan, autoComment);
                    ITextSnapshotLine prevLine = this._view.TextSnapshot.GetLineFromPosition(position);

                    StubUtils.MoveCaretAfterChange(this._view, this.editor, lineStart + caretPosition);

                    var after = editor.Apply();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(errorMsgPrefix + ex.Message);
                }
            }
        }
Example #2
0
        private void CreateStub(int position, ITextChange change)
        {
            string text = this._view.TextSnapshot.ToString();

            using (ITextEdit editor = this._view.TextBuffer.CreateEdit())
            {
                try
                {
                    this.tabs = StubUtils.GetIndention(position, this._view.TextSnapshot, true);
                    string summaryString = StubUtils.Options.MultiLineSummary ? NewLine() : "";
                    string parameters    = getFunctionParameters(position);
                    string returnTag     = getReturnTag(position);
                    string commentBody   = summaryString + StubUtils.CaretPlaceholder + 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;
                    var caretPosition = autoComment.IndexOf(StubUtils.CaretPlaceholder);
                    autoComment = autoComment.Replace(StubUtils.CaretPlaceholder, "");

                    Span firstLineSpan = new Span(lineStart, change.NewSpan.End - lineStart);
                    editor.Replace(firstLineSpan, autoComment);

                    StubUtils.MoveCaretAfterChange(this._view, this.editor, lineStart + caretPosition);

                    var after = editor.Apply();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(errorMsgPrefix + ex.Message);
                }
            }
        }