Beispiel #1
0
 public virtual int GetLine()
 {
     if (this.textLineMarker == null)
     {
         return(1);
     }
     else
     {
         TextSpan[] span = new TextSpan[1];
         textLineMarker.GetCurrentSpan(span);
         return(span[0].iStartLine);
     }
 }
        public static Result <TextSpan> GetCurrentSpan(this IVsTextLineMarker marker)
        {
            var array   = new TextSpan[1];
            var hresult = marker.GetCurrentSpan(array);

            return(Result.CreateSuccessOrError(array[0], hresult));
        }
Beispiel #3
0
        /// <include file='doc\DocumentTask.uex' path='docs/doc[@for="DocumentTask.OnNavigate"]/*' />
        protected override void OnNavigate(EventArgs e)
        {
            TextSpan span = this.span;

            if (textLineMarker != null)
            {
                TextSpan[] spanArray = new TextSpan[1];
                NativeMethods.ThrowOnFailure(textLineMarker.GetCurrentSpan(spanArray));
                span = spanArray[0];
            }

            IVsUIHierarchy hierarchy;
            uint           itemID;
            IVsWindowFrame docFrame;
            IVsTextView    textView;

            VsShell.OpenDocument(this.site, this.fileName, NativeMethods.LOGVIEWID_Code, out hierarchy, out itemID, out docFrame, out textView);
            NativeMethods.ThrowOnFailure(docFrame.Show());
            if (textView != null)
            {
                NativeMethods.ThrowOnFailure(textView.SetCaretPos(span.iStartLine, span.iStartIndex));
                TextSpanHelper.MakePositive(ref span);
                NativeMethods.ThrowOnFailure(textView.SetSelection(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex));
                NativeMethods.ThrowOnFailure(textView.EnsureSpanVisible(span));
            }
            base.OnNavigate(e);
        }
Beispiel #4
0
 public int OnAfterMarkerChange(IVsTextMarker pMarker)
 {
     if (marker != null)
     {
         TextSpan[] tspan = new TextSpan[1];
         int        hr    = marker.GetCurrentSpan(tspan);
         if (tspan != null && hr == 0)
         {
             location.TextSpan = tspan[0];
             //Refresh();
         }
     }
     return(0);
 }
Beispiel #5
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);
            }
        }
Beispiel #6
0
 public int OnAfterMarkerChange(IVsTextMarker pMarker)
 {
     if (marker != null)
     {
         // Common.Trace("Task: OnAfterMarkerChange: " + location);
         TextSpan[] tspan = new TextSpan[1];
         int        hr    = marker.GetCurrentSpan(tspan);
         if (tspan != null && hr == 0)
         {
             location.TextSpan = tspan[0];
             if (taskManager != null)
             {
                 taskManager.RefreshDelayed();
             }
         }
     }
     return(0);
 }
        public ExternalEditMarker?TryCreateExternalEditMarker(IVsTextLineMarker marker, ITextSnapshot snapshot)
        {
            var result = marker.GetMarkerType();

            if (result.IsError)
            {
                return(null);
            }

            // Predefined markers aren't a concern
            var value = (int)result.Value;

            if (value <= (int)MARKERTYPE.DEF_MARKER_COUNT)
            {
                return(null);
            }

            // Get the SnapshotSpan for the marker
            var span = marker.GetCurrentSpan(snapshot);

            if (span.IsError)
            {
                return(null);
            }

            switch ((int)result.Value)
            {
            case 15:
            case 16:
            case 26:
                // Details
                //  15: Snippet marker for inactive span
                //  16: Snippet marker for active span
                //  26: Tracks comment insertion for a snippet don' for cursor placement
                return(new ExternalEditMarker(ExternalEditKind.Snippet, span.Value));

            case 25:
                // Kind currently unknown.
                return(null);

            default:
                return(null);
            }
        }
        public ExternalEditMarker? TryCreateExternalEditMarker(IVsTextLineMarker marker, ITextSnapshot snapshot)
        {
            var result = marker.GetMarkerType();
            if (result.IsError)
            {
                return null;
            }

            // Predefined markers aren't a concern
            var value = (int)result.Value;
            if (value <= (int)MARKERTYPE.DEF_MARKER_COUNT)
            {
                return null;
            }

            // Get the SnapshotSpan for the marker
            var span = marker.GetCurrentSpan(snapshot);
            if (span.IsError)
            {
                return null;
            }

            switch ((int)result.Value)
            {
                case 15:
                case 16:
                case 26:
                    // Details
                    //  15: Snippet marker for inactive span
                    //  16: Snippet marker for active span
                    //  26: Tracks comment insertion for a snippet don' for cursor placement
                    return new ExternalEditMarker(ExternalEditKind.Snippet, span.Value);
                case 25:
                    // Kind currently unknown.
                    return null;
                default:
                    return null;
            }
        }
Beispiel #9
0
 public virtual void Line(out int piLine)
 {
     TextSpan[] span = new TextSpan[1];
     textLineMarker.GetCurrentSpan(span);
     piLine = span[0].iStartLine;
 }