/// <summary>
        /// Open the file and jump to a line (and optional column)
        /// </summary>
        public static void OpenAndNavigateTo(string fileName, int line, int column = 0)
        {
            IVsUIShellOpenDocument uishellOpenDocument = Package.GetGlobalService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            if (uishellOpenDocument != null)
            {
                Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider;
                IVsWindowFrame frame;
                IVsUIHierarchy hierarchy;
                uint           itemId;
                Guid           logicalView = VSConstants.LOGVIEWID_Code;
                if (ErrorHandler.Succeeded(uishellOpenDocument.OpenDocumentViaProject(fileName, ref logicalView, out serviceProvider, out hierarchy, out itemId, out frame)))
                {
                    object document;
                    frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out document);
                    VsTextBuffer buffer = document as VsTextBuffer;
                    if (buffer == null)
                    {
                        IVsTextBufferProvider bufferProvider = document as IVsTextBufferProvider;
                        if (bufferProvider != null)
                        {
                            IVsTextLines lines;
                            ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines));
                            buffer = lines as VsTextBuffer;
                        }
                    }
                    if (buffer != null)
                    {
                        IVsTextManager textManager = Package.GetGlobalService(typeof(VsTextManagerClass)) as IVsTextManager;
                        textManager.NavigateToLineAndColumn(buffer, ref logicalView, line, column, line, column);
                    }
                }
            }
        }
예제 #2
0
        public override bool Navigate(VsTextBuffer buffer, int line, int column)
        {
            var source = (BooSource)GlobalServices.LanguageService.GetOrCreateSource((IVsTextLines)buffer);
            var pos    = source.MapPosition(line, column);

            return(base.Navigate(buffer, pos.Line, pos.Column));
        }
예제 #3
0
        private void OpenDocumentAndNavigateTo(string path, int startLine, int startColumn, int?endLine = null, int?endColumn = null)
        {
            IVsUIShellOpenDocument openDoc = Package.GetGlobalService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            if (openDoc == null)
            {
                return;
            }

            Guid           logicalView = VSConstants.LOGVIEWID_Code;
            IVsWindowFrame frame;

            try
            {
                Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp;
                IVsUIHierarchy hier;
                uint           itemid;
                openDoc.OpenDocumentViaProject(path, ref logicalView, out sp, out hier, out itemid, out frame);
            }
            catch (Exception)
            {
                return;
            }

            object docData;

            frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);

            // Get the VsTextBuffer
            VsTextBuffer buffer = docData as VsTextBuffer;

            if (buffer == null)
            {
                IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
                if (bufferProvider != null)
                {
                    IVsTextLines lines;
                    try
                    {
                        bufferProvider.GetTextBuffer(out lines);
                    }
                    catch (Exception)
                    {
                        return;
                    }

                    buffer = lines as VsTextBuffer;
                    Debug.Assert(buffer != null, "IVsTextLines does not implement IVsTextBuffer");
                }
            }

            IVsTextManager mgr = Package.GetGlobalService(typeof(VsTextManagerClass)) as IVsTextManager;

            if (mgr == null)
            {
                return;
            }

            mgr.NavigateToLineAndColumn(buffer, ref logicalView, startLine - 1, startColumn - 1, (endLine ?? startLine) - 1, (endColumn ?? startColumn) - 1);
        }
예제 #4
0
 public static void OpenDocumentAndNavigateTo(string path, int line, int column)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     if (Package.GetGlobalService(typeof(IVsUIShellOpenDocument)) is IVsUIShellOpenDocument openDocument)
     {
         Guid logicalView = VSConstants.LOGVIEWID_Code;
         if (ErrorHandler.Failed(openDocument.OpenDocumentViaProject(path,
                                                                     ref logicalView,
                                                                     out _,
                                                                     out _,
                                                                     out _,
                                                                     out IVsWindowFrame frame)) || frame == null)
         {
             return;
         }
         frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out object docData);
         VsTextBuffer buffer = docData as VsTextBuffer;
         if (buffer == null)
         {
             if (docData is IVsTextBufferProvider textBufferProvider)
             {
                 ErrorHandler.ThrowOnFailure(textBufferProvider.GetTextBuffer(out IVsTextLines lines));
                 buffer = lines as VsTextBuffer;
                 if (buffer == null)
                 {
                     return;
                 }
             }
         }
         if (Package.GetGlobalService(typeof(VsTextManagerClass)) is IVsTextManager textManager)
         {
             textManager.NavigateToLineAndColumn(buffer, ref logicalView, line, column, line, column);
         }
     }
 }
        public static void OpenDocumentAndNavigateTo(string path, int line, int column)
        {
            IVsUIShellOpenDocument openDoc = Package.GetGlobalService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            if (openDoc == null)
            {
                return;
            }

            IVsWindowFrame frame;

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp;
            IVsUIHierarchy hier;
            uint           itemid;
            Guid           logicalView = VSConstants.LOGVIEWID_Code;

            if (ErrorHandler.Failed(
                    openDoc.OpenDocumentViaProject(path, ref logicalView, out sp, out hier, out itemid, out frame)) ||
                frame == null)
            {
                return;
            }

            object docData;

            frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);

            // Get the VsTextBuffer
            VsTextBuffer buffer = docData as VsTextBuffer;

            if (buffer == null)
            {
                IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
                if (bufferProvider != null)
                {
                    IVsTextLines lines;
                    ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines));
                    buffer = lines as VsTextBuffer;
                    Debug.Assert(buffer != null, "IVsTextLines does not implement IVsTextBuffer");
                    if (buffer == null)
                    {
                        return;
                    }
                }
            }

            // Finally, perform the navigation.
            IVsTextManager mgr = Package.GetGlobalService(typeof(VsTextManagerClass))
                                 as IVsTextManager;

            if (mgr == null)
            {
                return;
            }
            mgr.NavigateToLineAndColumn(buffer, ref logicalView, line, column, line, column);
        }
예제 #6
0
        private void OpenDocumentAndNavigateTo(string path, int line, int column)
        {
            var openDoc = (IVsUIShellOpenDocument)_serviceProvider.GetService(typeof(IVsUIShellOpenDocument));

            if (openDoc == null)
            {
                return;
            }

            IVsWindowFrame frame;                                    // IVsWindowFrame

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp;  // Microsoft.VisualStudio.OLE.Interop.IServiceProvider
            IVsUIHierarchy hier;                                     // IVsUIHierarchy
            uint           itemid;                                   // uint
            var            logicalView = VSConstants.LOGVIEWID_Code; // Guid

            if (ErrorHandler.Failed(openDoc.OpenDocumentViaProject(path, ref logicalView, out sp, out hier, out itemid, out frame)) || frame == null)
            {
                return;
            }

            object docData;

            frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);

            // Get the VsTextBuffer
            VsTextBuffer buffer = docData as VsTextBuffer;

            if (buffer == null)
            {
                IVsTextLines lines; // IVsTextLines
                var          bufferProvider = docData as IVsTextBufferProvider;
                if (bufferProvider != null)
                {
                    ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines));
                }
            }

            if (buffer == null)
            {
                return;
            }

            // Finally, perform the navigation.
            var mgr = (IVsTextManager)_serviceProvider.GetService(typeof(VsTextManagerClass));

            if (mgr == null)
            {
                return;
            }

            mgr.NavigateToLineAndColumn(buffer, ref logicalView, line, column, line, column);
        }
예제 #7
0
        public override bool Navigate(VsTextBuffer buffer, int line, int column)
        {
            var source    = GlobalServices.LanguageService.GetOrCreateSource((IVsTextLines)buffer);
            var booSource = source as BooSource;

            if (booSource != null)
            {
                var pos = booSource.MapPosition(line, column);
                line   = pos.Line;
                column = pos.Column;
            }
            return(base.Navigate(buffer, line, column));
        }
예제 #8
0
        private void NavigateTo(object sender, EventArgs arguments)
        {
            Microsoft.VisualStudio.Shell.Task task = sender as Microsoft.VisualStudio.Shell.Task;
            if (task == null)
                throw new ArgumentException("sender");

            // Get the doc data for the task's document
            if (String.IsNullOrEmpty(task.Document))
                return;

            IVsUIShellOpenDocument openDoc = serviceProvider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            if (openDoc == null)
                return;

            IVsWindowFrame frame;
            IOleServiceProvider sp;
            IVsUIHierarchy hier;
            uint itemid;
            Guid logicalView = VSConstants.LOGVIEWID_Code;

            if (Microsoft.VisualStudio.ErrorHandler.Failed(openDoc.OpenDocumentViaProject(task.Document, ref logicalView, out sp, out hier, out itemid, out frame)) || frame == null)
                return;

            object docData;
            frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);

            // Get the VsTextBuffer
            VsTextBuffer buffer = docData as VsTextBuffer;
            if (buffer == null)
            {
                IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
                if (bufferProvider != null)
                {
                    IVsTextLines lines;
                    Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines));
                    buffer = lines as VsTextBuffer;
                    Debug.Assert(buffer != null, "IVsTextLines does not implement IVsTextBuffer");
                    if (buffer == null)
                        return;
                }
            }

            // Finally, perform the navigation.
            IVsTextManager mgr = serviceProvider.GetService(typeof(VsTextManagerClass)) as IVsTextManager;
            if (mgr == null)
                return;

            mgr.NavigateToLineAndColumn(buffer, ref logicalView, task.Line, task.Column, task.Line, task.Column);
        }
예제 #9
0
        public override void NavigateToFileAndPosition(string file, int line, int col, int lineEnd = 0, int columnEnd = 0)
        {
            IVsUIShellOpenDocument openDoc = AspectPackage.GetGlobalService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            IVsWindowFrame frame;

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp;
            IVsUIHierarchy hier;
            uint           itemid;
            Guid           logicalView = VSConstants.LOGVIEWID_Code;

            if (ErrorHandler.Failed(openDoc.OpenDocumentViaProject(file, ref logicalView, out sp, out hier, out itemid, out frame)) || frame == null)
            {
                return;
            }
            object docData;

            frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);

            // Get the VsTextBuffer
            VsTextBuffer buffer = docData as VsTextBuffer;

            if (buffer == null)
            {
                IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
                if (bufferProvider != null)
                {
                    IVsTextLines lines;
                    ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines));
                    buffer = lines as VsTextBuffer;
                    if (buffer == null)
                    {
                        return;
                    }
                }
            }
            IVsTextManager mgr = AspectPackage.GetGlobalService(typeof(VsTextManagerClass)) as IVsTextManager;

            if (lineEnd == 0)
            {
                lineEnd   = line;
                columnEnd = col;
            }
            mgr.NavigateToLineAndColumn(buffer, ref logicalView, line - 1, col, lineEnd - 1, columnEnd);
        }
예제 #10
0
        private void NavigateAndSelect(
            VsTextBuffer buffer,
            int startLine,
            int startColumn,
            int endLine,
            int endColumn
            )
        {
            if (_textManager == null)
            {
                return;
            }

            var docViewType = default(Guid);

            _textManager.NavigateToLineAndColumn(
                buffer,
                ref docViewType,
                startLine,
                startColumn,
                endLine,
                endColumn
                );
        }
예제 #11
0
        private void NavigateTo(object sender, EventArgs arguments)
        {
            try {
                Microsoft.VisualStudio.Shell.Task task = sender as Microsoft.VisualStudio.Shell.Task;
                if (task == null)
                {
                    throw new ArgumentException("sender");
                }

                // Get the doc data for the task's document
                if (String.IsNullOrEmpty(task.Document))
                {
                    return;
                }

                IVsUIShellOpenDocument openDoc = serviceProvider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
                if (openDoc == null)
                {
                    return;
                }

                IVsWindowFrame      frame;
                IOleServiceProvider sp;
                IVsUIHierarchy      hier;
                uint itemid;
                Guid logicalView = VSConstants.LOGVIEWID_Code;

                if (Microsoft.VisualStudio.ErrorHandler.Failed(openDoc.OpenDocumentViaProject(task.Document, ref logicalView, out sp, out hier, out itemid, out frame)) || frame == null)
                {
                    return;
                }

                object docData;
                frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);

                // Get the VsTextBuffer
                VsTextBuffer buffer = docData as VsTextBuffer;
                if (buffer == null)
                {
                    IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
                    if (bufferProvider != null)
                    {
                        IVsTextLines lines;
                        Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines));
                        buffer = lines as VsTextBuffer;
                        Debug.Assert(buffer != null, "IVsTextLines does not implement IVsTextBuffer");
                        if (buffer == null)
                        {
                            return;
                        }
                    }
                }

                // Finally, perform the navigation.
                IVsTextManager mgr = serviceProvider.GetService(typeof(VsTextManagerClass)) as IVsTextManager;
                if (mgr == null)
                {
                    return;
                }

                // We should use the full span information if we've been given a DocumentTask
                bool isDocumentTask = task is DocumentTask;
                int  endLine        = isDocumentTask ? ((DocumentTask)task).Span.iEndLine : task.Line;
                int  endColumn      = isDocumentTask ? ((DocumentTask)task).Span.iEndIndex : task.Column;

                mgr.NavigateToLineAndColumn(buffer, ref logicalView, task.Line, task.Column, endLine, endColumn);
            } catch (Exception e) {
                System.Diagnostics.Debug.Assert(false, "Error thrown from NavigateTo. " + e.ToString());
            }
        }
예제 #12
0
        public static async void Error_Task_Navigate_Handler(object sender, EventArgs arguments)
        {
            if (!ThreadHelper.CheckAccess())
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
            }

            Microsoft.VisualStudio.Shell.Task task = sender as Microsoft.VisualStudio.Shell.Task;

            if (task == null)
            {
                throw new ArgumentException("sender parm cannot be null");
            }
            if (string.IsNullOrEmpty(task.Document))
            {
                Output_INFO("AsmDudeToolsStatic:Error_Task_Navigate_Handler: task.Document is empty");
                return;
            }

            Output_INFO("AsmDudeToolsStatic: Error_Task_Navigate_Handler: task.Document=" + task.Document);


            IVsUIShellOpenDocument openDoc = Package.GetGlobalService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            if (openDoc == null)
            {
                Output_INFO("AsmDudeToolsStatic:Error_Task_Navigate_Handler: openDoc is null");
                return;
            }

            Guid logicalView = VSConstants.LOGVIEWID_Code;

            int hr = openDoc.OpenDocumentViaProject(task.Document, ref logicalView, out Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider, out IVsUIHierarchy hierarchy, out uint itemId, out IVsWindowFrame frame);

            if (ErrorHandler.Failed(hr) || (frame == null))
            {
                Output_INFO("AsmDudeToolsStatic:Error_Task_Navigate_Handler: OpenDocumentViaProject failed");
                return;
            }

            frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out object docData);

            VsTextBuffer buffer = docData as VsTextBuffer;

            if (buffer == null)
            {
                if (docData is IVsTextBufferProvider bufferProvider)
                {
                    ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out IVsTextLines lines));
                    buffer = lines as VsTextBuffer;

                    if (buffer == null)
                    {
                        Output_INFO("INFO: AsmDudeToolsStatic:Error_Task_Navigate_Handler: buffer is null");
                        return;
                    }
                }
            }
            IVsTextManager mgr = Package.GetGlobalService(typeof(SVsTextManager)) as IVsTextManager;

            if (mgr == null)
            {
                Output_INFO("AsmDudeToolsStatic:Error_Task_Navigate_Handler: IVsTextManager is null");
                return;
            }

            //Output("INFO: AsmDudeToolsStatic:errorTaskNavigateHandler: navigating to row="+task.Line);
            int iStartIndex = task.Column & 0xFFFF;
            int iEndIndex   = (task.Column >> 16) & 0xFFFF;

            mgr.NavigateToLineAndColumn(buffer, ref logicalView, task.Line, iStartIndex, task.Line, iEndIndex);
        }
예제 #13
0
파일: VsLogger.cs 프로젝트: formist/LinkMe
        private void NavigateToHandler(object sender, System.EventArgs args)
        {
            Microsoft.VisualStudio.Shell.Task task = sender as Microsoft.VisualStudio.Shell.Task;
            if (task == null)
            {
                throw new System.ArgumentException("sender");
            }

            // Open the document.

            if (string.IsNullOrEmpty(task.Document))
            {
                return;
            }
            IVsUIShellOpenDocument openDocument = m_serviceProvider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            if (openDocument == null)
            {
                return;
            }

            IVsWindowFrame      frame;
            IOleServiceProvider serviceProvider;
            IVsUIHierarchy      hierarchy;
            uint itemId;

            System.Guid logicalView = VSConstants.LOGVIEWID_Code;
            if (Failed(openDocument.OpenDocumentViaProject(task.Document, ref logicalView, out serviceProvider, out hierarchy, out itemId, out frame)) || frame == null)
            {
                return;
            }

            // Get the text buffer.

            object docData;

            frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);
            VsTextBuffer buffer = docData as VsTextBuffer;

            if (buffer == null)
            {
                IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
                if (bufferProvider != null)
                {
                    IVsTextLines lines;
                    ThrowOnFailure(bufferProvider.GetTextBuffer(out lines));
                    buffer = lines as VsTextBuffer;
                    if (buffer == null)
                    {
                        return;
                    }
                }
            }

            // Perform the navigation.

            IVsTextManager manager = m_serviceProvider.GetService(typeof(VsTextManagerClass)) as IVsTextManager;

            if (manager == null)
            {
                return;
            }
            manager.NavigateToLineAndColumn(buffer, ref logicalView, task.Line, task.Column, task.Line, task.Column);
        }
예제 #14
0
        /// <include file='doc\TaskProvider.uex' path='docs/doc[@for="Navigate"]/*' />
        /// <devdoc>
        ///     Navigates the document in the given task to the given logical view.
        /// </devdoc>
        public bool Navigate(Task task, Guid logicalView)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }

            // Get the doc data for the task's document
            if (task.Document == null || task.Document.Length == 0)
            {
                return(false);
            }

            IVsUIShellOpenDocument openDoc = GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            if (openDoc == null)
            {
                return(false);
            }

            IVsWindowFrame      frame;
            IOleServiceProvider sp;
            IVsUIHierarchy      hier;
            uint itemid;
            Guid logView = logicalView;

            if (NativeMethods.Failed(openDoc.OpenDocumentViaProject(task.Document, ref logView, out sp, out hier, out itemid, out frame)) || frame == null)
            {
                return(false);
            }

            object docData;

            frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);

            VsTextBuffer buffer = docData as VsTextBuffer;

            if (buffer == null)
            {
                IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
                if (bufferProvider != null)
                {
                    IVsTextLines lines;
                    NativeMethods.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines));
                    buffer = lines as VsTextBuffer;
                    Debug.Assert(buffer != null, "IVsTextLines does not implement IVsTextBuffer");
                    if (buffer == null)
                    {
                        return(false);
                    }
                }
            }

            // Finally, perform the navigation.
            IVsTextManager mgr = GetService(typeof(VsTextManagerClass)) as IVsTextManager;

            if (mgr == null)
            {
                return(false);
            }

            int line = task.Line;

            // Buffer is zero based
            if (line > 0)
            {
                line--;
            }

            mgr.NavigateToLineAndColumn(buffer, ref logicalView, line, 0, line, 0);
            return(true);
        }
예제 #15
0
        void NavigateHandler(object sender, EventArgs arguments)
        {
            var task = sender as ErrorTask;

            if (task == null || task.Document == null)
            {
                return;
            }

            // This would have been the simple way of doing things:
            //     _errorProvider.Navigate(error, new Guid(EnvDTE.Constants.vsViewKindCode));
            // Unfortunately, it doesn't work--it seems to ignore the column position.  (Moreover, it wants 1-based
            // line/column numbers, whereas the Error Task pane wants 0-based line/column numbers.)
            // So, instead we do all the things that follow:

            var openDoc = Package.GetGlobalService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            if (openDoc == null)
            {
                return;
            }

            IVsWindowFrame frame;

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp;
            IVsUIHierarchy hier;
            uint           itemid;
            Guid           logicalView = VSConstants.LOGVIEWID_Code;

            if (Microsoft.VisualStudio.ErrorHandler.Failed(openDoc.OpenDocumentViaProject(task.Document, ref logicalView, out sp, out hier, out itemid, out frame)) || frame == null)
            {
                return;
            }

            object docData;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData));

            // Get the VsTextBuffer
            VsTextBuffer buffer = docData as VsTextBuffer;

            if (buffer == null)
            {
                IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
                if (bufferProvider != null)
                {
                    IVsTextLines lines;
                    Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines));
                    buffer = lines as VsTextBuffer;
                    if (buffer == null)
                    {
                        return;
                    }
                }
            }

            VsTextManager textManager = Package.GetGlobalService(typeof(VsTextManagerClass)) as VsTextManager;

            if (textManager == null)
            {
                return;
            }

            // Finally, move the cursor
            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(textManager.NavigateToLineAndColumn(buffer, ref logicalView, task.Line, task.Column, task.Line, task.Column));
        }
예제 #16
0
        /// <summary>
        /// Used by the editor factory architecture to create editors that support
        /// data/view separation.
        /// </summary>
        public int CreateEditorInstance(
            uint grfCreateDoc,
            string pszMkDocument,
            string pszPhysicalView,
            IVsHierarchy pvHier,
            uint itemid,
            System.IntPtr punkDocDataExisting,
            out System.IntPtr ppunkDocView,
            out System.IntPtr ppunkDocData,
            out string pbstrEditorCaption,
            out System.Guid pguidCmdUI,
            out int pgrfCDW)
        {
            int retval = VSConstants.E_FAIL;

            // Initialize these to empty to start with
            ppunkDocView       = IntPtr.Zero;
            ppunkDocData       = IntPtr.Zero;
            pbstrEditorCaption = "";
            pguidCmdUI         = Guid.Empty;
            pgrfCDW            = 0;

            if ((grfCreateDoc & (VSConstants.CEF_OPENFILE |
                                 VSConstants.CEF_SILENT)) == 0)
            {
                throw new ArgumentException("Only Open or Silent is valid");
            }
            if (punkDocDataExisting != IntPtr.Zero)
            {
                return(VSConstants.VS_E_INCOMPATIBLEDOCDATA);
            }

            // Instantiate a text buffer of type VsTextBuffer.
            // Note: we only need an IUnknown (object) interface for
            // this invocation.
            Guid   clsidTextBuffer = typeof(VsTextBufferClass).GUID;
            Guid   iidTextBuffer   = VSConstants.IID_IUnknown;
            object pTextBuffer     = parentPackage.CreateInstance(
                ref clsidTextBuffer,
                ref iidTextBuffer,
                typeof(object));

            if (pTextBuffer != null)
            {
                // "Site" the text buffer with the service provider we were
                // provided.
                IObjectWithSite textBufferSite = pTextBuffer as IObjectWithSite;
                if (textBufferSite != null)
                {
                    textBufferSite.SetSite(this.serviceProvider);
                }
                VsTextBuffer textBuffer = pTextBuffer as VsTextBuffer;

                // Get the language settings from options page
                Guid guidLangSvc = Guid.Empty;
                LanguageServiceOptionsPage options = parentPackage.GetLanguageServiceOptions();
                switch (options.LanguageServiceSetting)
                {
                case LanguageService.None:
                    break;

                case LanguageService.VB:
                    guidLangSvc = GuidList.guidVBLangSvc;
                    break;

                case LanguageService.CS:
                    guidLangSvc = GuidList.guidCSharpLangSvc;
                    break;

                case LanguageService.XML:
                    guidLangSvc = GuidList.guidXmlLangSvc;
                    break;

                default:
                    break;
                }

                // Set language service ID
                int hr = textBuffer.SetLanguageServiceID(ref guidLangSvc);

                IVsUserData usrData = pTextBuffer as IVsUserData;
                //     Gets a GUID value in Microsoft.VisualStudio.TextManager.Interop.IVsUserData
                //     that, when set to false, will stop the core editor for searching for a different
                //     language service.
                Guid guidVSBufferDetectLangSid = Microsoft.VisualStudio.Package.EditorFactory.GuidVSBufferDetectLangSid;
                usrData.SetData(ref guidVSBufferDetectLangSid, false);


                // Instantiate a code window of type IVsCodeWindow.
                Guid          clsidCodeWindow = typeof(VsCodeWindowClass).GUID;
                Guid          iidCodeWindow   = typeof(IVsCodeWindow).GUID;
                IVsCodeWindow pCodeWindow     =
                    (IVsCodeWindow)this.parentPackage.CreateInstance(
                        ref clsidCodeWindow,
                        ref iidCodeWindow,
                        typeof(IVsCodeWindow));
                if (pCodeWindow != null)
                {
                    // Give the text buffer to the code window.
                    // We are giving up ownership of the text buffer!
                    pCodeWindow.SetBuffer((IVsTextLines)pTextBuffer);

                    // Now tell the caller about all this new stuff
                    // that has been created.
                    ppunkDocView = Marshal.GetIUnknownForObject(pCodeWindow);
                    ppunkDocData = Marshal.GetIUnknownForObject(pTextBuffer);

                    // Specify the command UI to use so keypresses are
                    // automatically dealt with.
                    pguidCmdUI = VSConstants.GUID_TextEditorFactory;

                    // This caption is appended to the filename and
                    // lets us know our invocation of the core editor
                    // is up and running.
                    pbstrEditorCaption = " [CSVSPackageInvokeCoreEditor]";

                    retval = VSConstants.S_OK;
                }
            }
            return(retval);
        }
예제 #17
0
        private void NavigateHandler(object sender, EventArgs arguments)
        {
            Microsoft.VisualStudio.Shell.Task task = sender as Microsoft.VisualStudio.Shell.Task;

            if (task == null)
            {
                throw new ArgumentException("sender parm cannot be null");
            }

            if (String.IsNullOrEmpty(task.Document))
            {
                return;
            }

            IVsUIShellOpenDocument openDoc = GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            if (openDoc == null)
            {
                return;
            }

            IVsWindowFrame frame;

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider;
            IVsUIHierarchy hierarchy;
            uint           itemId;
            Guid           logicalView = VSConstants.LOGVIEWID_Code;

            if (ErrorHandler.Failed(openDoc.OpenDocumentViaProject(
                                        task.Document, ref logicalView, out serviceProvider, out hierarchy, out itemId, out frame)) ||
                frame == null)
            {
                return;
            }

            object docData;

            frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);

            VsTextBuffer buffer = docData as VsTextBuffer;

            if (buffer == null)
            {
                IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
                if (bufferProvider != null)
                {
                    IVsTextLines lines;
                    ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines));
                    buffer = lines as VsTextBuffer;

                    if (buffer == null)
                    {
                        return;
                    }
                }
            }

            IVsTextManager mgr = GetService(typeof(VsTextManagerClass)) as IVsTextManager;

            if (mgr == null)
            {
                return;
            }

            mgr.NavigateToLineAndColumn(buffer, ref logicalView, task.Line, task.Column, task.Line, task.Column);
        }
예제 #18
0
        public virtual bool Navigate(VsTextBuffer buffer, int line, int column)
        {
            Guid logicalView = VSConstants.LOGVIEWID_Code;

            // Finally, perform the navigation.
            IVsTextManager mgr = GetService(typeof(VsTextManagerClass)) as IVsTextManager;
            if (mgr == null)
                return false;

            return Microsoft.VisualStudio.ErrorHandler.Succeeded(mgr.NavigateToLineAndColumn(buffer, ref logicalView, line, column, line, column));
        }
예제 #19
0
        //
        // Plumbing - an event handler for when a Task is double-clicked, i.e.
        // to navigate to the code causing a parser error.
        //
        internal async void NavigationHandler(object sender, EventArgs args)
        {
            var task = sender as Microsoft.VisualStudio.Shell.Task;

            if (string.IsNullOrEmpty(task.Document))
            {
                return;
            }

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var serviceProvider = new ParseSession.ErrorListHelper();
            var openDoc         = serviceProvider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            if (openDoc == null)
            {
                return;
            }

            IVsWindowFrame frame;

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp;
            IVsUIHierarchy hier;
            uint           itemid;
            Guid           logicalView = VSConstants.LOGVIEWID_Code;

            if (ErrorHandler.Failed(openDoc.OpenDocumentViaProject(task.Document, ref logicalView, out sp, out hier, out itemid, out frame)) || frame == null)
            {
                return;
            }

            object docData;

            frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);

            VsTextBuffer buffer = docData as VsTextBuffer;

            if (buffer == null)
            {
                IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
                if (bufferProvider != null)
                {
                    IVsTextLines lines;
                    ErrorHandler.ThrowOnFailure(bufferProvider.GetTextBuffer(out lines));
                    buffer = lines as VsTextBuffer;

                    if (buffer == null)
                    {
                        return;
                    }
                }
            }

            IVsTextManager mgr = serviceProvider.GetService(typeof(VsTextManagerClass)) as IVsTextManager;

            if (mgr == null)
            {
                return;
            }

            // This whole mess could arguably be a lot simpler as a call to ErrorProvider.Navigate().
            // Unfortunately that API assumes 1-based column/line indices, whereas our task (in order
            // to display correctly in the task list) assumes 0-based. This can be worked around with
            // a trivial addition/substraction, but the kicker is that the column is not used by that
            // particular API. Therefore to preserve the column we do all this crazy stuff instead.
            mgr.NavigateToLineAndColumn(buffer, ref logicalView, task.Line, task.Column, task.Line, task.Column);
        }
예제 #20
0
 public override bool Navigate(VsTextBuffer buffer, int line, int column)
 {
     var source = (BooSource)GlobalServices.LanguageService.GetOrCreateSource((IVsTextLines)buffer);
     var pos = source.MapPosition(line, column);
     return base.Navigate(buffer, pos.Line, pos.Column);
 }