Example #1
0
 /// <summary>
 /// Construct a new edit span object
 /// </summary>
 /// <param name="toReplace">The text span to remove from the buffer (can be empty)</param>
 /// <param name="insertText">The text to insert in it's place (can be null)</param>
 internal EditSpan(TextSpan toReplace, string insertText)
 {
     if (!TextSpanHelper.IsPositive(toReplace))
     {
         TextSpanHelper.MakePositive(ref toReplace);
     }
     this.span      = toReplace;
     this.text      = insertText;
     this.lineCount = -1;
 }
Example #2
0
        // It is important that this function not throw an exception.
        protected override void OnNavigate(EventArgs e)
        {
            try {
                TextSpan span = this.span;
                if (textLineMarker != null)
                {
                    TextSpan[] spanArray = new TextSpan[1];
                    if (NativeMethods.Failed(textLineMarker.GetCurrentSpan(spanArray)))
                    {
                        Debug.Assert(false, "Unexpected error getting current span in OnNavigate");
                        return;
                    }
                    span = spanArray[0];
                }

                IVsUIHierarchy hierarchy;
                uint           itemID;
                IVsWindowFrame docFrame;
                IVsTextView    textView;
                try {
                    VsShell.OpenDocument(this.site, this.fileName, NativeMethods.LOGVIEWID_Code, out hierarchy, out itemID, out docFrame, out textView);
                } catch (System.ArgumentException) {
                    // No assert here because this can legitimately happen when quickly doing F8 during a refresh of language service errors (see 4846)
                    return;
                }
                catch (System.IO.FileNotFoundException)
                {
                    // No assert here because this can legitimately happen, e.g. with type provider errors (which are attributed to "FSC" file), or other cases
                    return;
                }
                if (NativeMethods.Failed(docFrame.Show()))
                {
                    // No assert here because this can legitimately happen when quickly doing F8 during a refresh of language service errors (see 4846)
                    return;
                }
                if (textView != null)
                {
                    // In the off-chance these methods fail, we 'recover' by continuing. It is more helpful to show the user the file if possible than not.
                    textView.SetCaretPos(span.iStartLine, span.iStartIndex);
                    TextSpanHelper.MakePositive(ref span);
                    textView.SetSelection(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex);
                    textView.EnsureSpanVisible(span);
                }
                base.OnNavigate(e);
            } catch (Exception exn) {
                System.Diagnostics.Debug.Assert(false, "Unexpected exception thrown from DocumentTask.OnNavigate" + exn.ToString() + exn.StackTrace);
            }
        }