Example #1
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);
        }
        private ITextView GetTextView(IVsWindowFrame frame)
        {
            if (frame == null)
                return null;

            IVsTextView viewAdapter = VsShellUtilities.GetTextView(frame);
            IWpfTextView wpfTextView = this.VsEditorAdaptorsFactoryService.GetWpfTextView(viewAdapter);
            return wpfTextView;
        }
Example #3
0
        private void GoToLocation(RawSourceSpan loc, string caption, bool asReadonly)
        {
            // Code taken from Nemerle https://github.com/rsdn/nemerle/blob/master/snippets/VS2010/Nemerle.VisualStudio/LanguageService/NemerleLanguageService.cs#L565
            // TODO: Add licensing
            if (loc == null || loc.File == null)
            {
                return;
            }

            // Opens the document
            var span = new TextSpan {
                iStartLine = loc.Line - 1, iStartIndex = loc.Column - 1, iEndLine = loc.EndLine - 1, iEndIndex = loc.EndColumn - 1
            };
            uint           itemID;
            IVsUIHierarchy hierarchy;
            IVsWindowFrame docFrame;
            IVsTextView    textView;

            VsShell.OpenDocument(Site, loc.File, VSConstants.LOGVIEWID_Code, out hierarchy, out itemID, out docFrame, out textView);

            // If we need readonly, set the buffer to read-only
            if (asReadonly)
            {
                IVsTextLines buffer;
                ErrorHandler.ThrowOnFailure(textView.GetBuffer(out buffer));
                var stream = (IVsTextStream)buffer;
                stream.SetStateFlags((uint)BUFFERSTATEFLAGS.BSF_USER_READONLY);
            }

            // Need to use a different caption?
            if (caption != null)
            {
                ErrorHandler.ThrowOnFailure(docFrame.SetProperty((int)__VSFPROPID.VSFPROPID_OwnerCaption, caption));
            }

            // Show the frame
            ErrorHandler.ThrowOnFailure(docFrame.Show());

            // Go to the specific location
            if (textView != null && loc.Line != 0)
            {
                try
                {
                    ErrorHandler.ThrowOnFailure(textView.SetCaretPos(span.iStartLine, span.iStartIndex));
                    TextSpanHelper.MakePositive(ref span);
                    //ErrorHandler.ThrowOnFailure(textView.SetSelection(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex));
                    ErrorHandler.ThrowOnFailure(textView.EnsureSpanVisible(span));
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.Message);
                }
            }
        }
Example #4
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);
            }
        }
        internal static void ShowError(string message, string document, string helpSubPage = "", int lineNo = 0, int column = 0)
        {
            ErrorTask task = new ErrorTask()
            {
                Category      = TaskCategory.Misc,
                ErrorCategory = TaskErrorCategory.Error,
                Text          = message
            };

            DTE dte = (DTE)(_serviceProvider.GetService(typeof(DTE)));
            IServiceProvider serviceProvider = new ServiceProvider(dte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);

            if (document != null)
            {
                task.Document = document;

                task.Navigate += (s, e) =>
                {
                    try
                    {
                        IVsUIHierarchy hierarchy;
                        uint           itemID;
                        IVsWindowFrame docFrame;
                        IVsTextView    textView;
                        VsShell.OpenDocument(serviceProvider, document, Guids.LOGVIEWID_Code, out hierarchy, out itemID, out docFrame, out textView);
                        ThrowOnFailure(docFrame.Show());
                        if (textView != null)
                        {
                            ThrowOnFailure(textView.SetCaretPos(lineNo, column));
                        }
                    }catch (Exception)
                    {
                        // don't trow crazy exceptions when trying to navigate to errors
                    }
                };
            }

            task.Help += (s, e) =>
            {
                var mainPage = "http://fsprojects.github.io/Paket/";
                var errorUrl = mainPage;
                if (!String.IsNullOrWhiteSpace(helpSubPage))
                {
                    errorUrl += helpSubPage;
                }

                IVsWebBrowsingService webBrowsingService = serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
                if (webBrowsingService != null)
                {
                    IVsWindowFrame windowFrame;
                    webBrowsingService.Navigate(errorUrl, 0, out windowFrame);
                    return;
                }

                IVsUIShellOpenDocument openDocument = serviceProvider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
                if (openDocument != null)
                {
                    openDocument.OpenStandardPreviewer(0, errorUrl, VSPREVIEWRESOLUTION.PR_Default, 0);
                    return;
                }
            };
            _paketErrorProvider.Tasks.Add(task);
            _paketErrorProvider.Show();
            _paketErrorProvider.BringToFront();
        }