Example #1
0
        /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.HandleGoto"]/*' />
        /// <summary>Handles VsCommands.GotoDefn, VsCommands.GotoDecl and VsCommands.GotoRef by
        /// calling OnSyncGoto on the Source object and opening the text editor on the resulting
        /// URL, then scrolling to the resulting span.</summary>
        public virtual void HandleGoto(VsCommands cmd)
        {
            TextSpan ts = new TextSpan();

            // Get the caret position
            NativeMethods.ThrowOnFailure(this.textView.GetCaretPos(out ts.iStartLine, out ts.iStartIndex));
            ts.iEndLine  = ts.iStartLine;
            ts.iEndIndex = ts.iStartIndex;

            // Get the tip text at that location.
            // Wait, since the user specifically requested this one...
            TextSpan span;
            string   url = this.source.OnSyncGoto(cmd, this.textView, ts.iEndLine, ts.iEndIndex, out span);

            if (url == null || url.Trim().Length == 0)   // nothing to show
            {
                return;
            }

            // Open the referenced document, and scroll to the given location.
            IVsUIHierarchy hierarchy;
            uint           itemID;
            IVsWindowFrame frame;
            IVsTextView    view;

            VsShell.OpenDocument(this.service.Site, url, NativeMethods.LOGVIEWID_Code, out hierarchy, out itemID, out frame, out view);
            if (view != null)
            {
                TextSpanHelper.MakePositive(ref span);
                NativeMethods.ThrowOnFailure(view.EnsureSpanVisible(span));
                NativeMethods.ThrowOnFailure(view.SetSelection(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex));
            }
        }
Example #2
0
 public override string Goto(Microsoft.VisualStudio.VSConstants.VSStd97CmdID cmd, IVsTextView textView, int line, int col, out TextSpan span)
 {
     if (source != null)
     {
         return(source.Goto(line, col, out span));
     }
     span = new TextSpan();
     return(null);
 }
Example #3
0
        /// <summary>
        /// Gotoes the specified CMD.
        /// </summary>
        /// <param name="cmd">The CMD.</param>
        /// <param name="textView">The text view.</param>
        /// <param name="line">The line.</param>
        /// <param name="col">The col.</param>
        /// <param name="span">The span.</param>
        /// <returns></returns>
        public override string Goto(Microsoft.VisualStudio.VSConstants.VSStd97CmdID cmd, IVsTextView textView, int line, int col, out TextSpan span)
        {
            span = m_goto_textspan;
            return(m_goto_filename);

            // testing:
            // span.iStartLine = span.iEndLine = 23;
            // span.iStartIndex = 16; span.iEndIndex = 21;
            // return "E:/Temp/NPL/VsNPL/test.lua";
        }
Example #4
0
        /// <summary>
        /// Gets the system command status.
        /// </summary>
        /// <param name="cmdID">The CMD ID.</param>
        public override COMMAND_STATUS GetSystemCommandStatus(Microsoft.VisualStudio.VSConstants.VSStd97CmdID cmdID)
        {
            switch (cmdID)
            {
            case Microsoft.VisualStudio.VSConstants.VSStd97CmdID.Delete:
                return(UIControl.CanDelete);    // returns status of Delete command

            case Microsoft.VisualStudio.VSConstants.VSStd97CmdID.SelectAll:
                return(UIControl.CanSelectAll);    // returns status of SelectAll command

            default:
                return(base.GetSystemCommandStatus(cmdID));
            }
        }
        /// <summary>
        /// Handles the Goto-command.
        /// We have to do that synchronous as the default async-operation SOMETIMES doesn't work due to internal error (Win32Exception: "Invalid window handle")
        /// </summary>
        /// <param name="cmd">The command id.</param>
        public override void HandleGoto(VsCommands cmd)
        {
            //we handle only th goto-definition command
            if (cmd != VsCommands.GotoDefn)
            {
                base.HandleGoto(cmd);
                return;
            }

            int line, col;

            // Get the caret position
            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(TextView.GetCaretPos(out line, out col));

            //parse the source synchronous
            AuthoringScope scope = Source.LanguageService.ParseSource(new ParseRequest(line, col, new TokenInfo(), Source.GetText(), Source.GetFilePath(), ParseReason.Goto, TextView, Source.CreateAuthoringSink(ParseReason.Goto, line, col), true));

            //navigate to the found position

            string   url = null;
            TextSpan span;

            if (scope != null)
            {
                url = scope.Goto(cmd, TextView, line, col, out span);
            }
            else
            {
                return;
            }
            if (url == null || url.Trim().Length == 0)   // nothing to show
            {
                return;
            }

            // Open the referenced document, and scroll to the given location.
            IVsUIHierarchy hierarchy;
            uint           itemID;
            IVsWindowFrame frame;
            IVsTextView    view;

            Microsoft.VisualStudio.Shell.VsShellUtilities.OpenDocument(base.Source.LanguageService.Site, url, VSConstants.LOGVIEWID_Code, out hierarchy, out itemID, out frame, out view);
            if (view != null)
            {
                TextSpanHelper.MakePositive(ref span);
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(view.EnsureSpanVisible(span));
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(view.SetSelection(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex));
            }
        }
Example #6
0
        /// <summary>
        /// Executes the system command.
        /// </summary>
        /// <param name="cmdID">The CMD ID.</param>
        public override bool ExecuteSystemCommand(Microsoft.VisualStudio.VSConstants.VSStd97CmdID cmdID)
        {
            switch (cmdID)
            {
            case Microsoft.VisualStudio.VSConstants.VSStd97CmdID.Delete:
                UIControl.NotifyRemoveRequested(REMOVEKIND.REMOVE);     // executes Delete command
                return(true);

            case Microsoft.VisualStudio.VSConstants.VSStd97CmdID.SelectAll:
                return(UIControl.ExecuteSelectAll());    // executes SelectAll command

            default:
                return(base.ExecuteSystemCommand(cmdID));
            }
        }
Example #7
0
        public override void HandleGoto(VsCommands cmd)
        {
            int line, col;

            // Get the caret position
            ErrorHandler.ThrowOnFailure(this.TextView.GetCaretPos(out line, out col));
            bool gotoDefinition = false;

            switch (cmd)
            {
            case VSConstants.VSStd97CmdID.GotoDecl:
            case VSConstants.VSStd97CmdID.GotoDefn: gotoDefinition = true; break;

            case VSConstants.VSStd97CmdID.GotoRef:
                Trace.WriteLine("GoToReference() not implemenred yet");
                break;

            default: Trace.Assert(false); break;
            }

            Source.Goto(TextView, gotoDefinition, line, col);
        }
Example #8
0
 public override string Goto(Microsoft.VisualStudio.VSConstants.VSStd97CmdID cmd, IVsTextView textView, int line, int col, out TextSpan span)
 {
     span = new TextSpan();
     switch (cmd)
     {
     case VSConstants.VSStd97CmdID.GotoDefn:
     //var def = idetoolsfuncs.GetDef(m_filename, line, col, m_projectfile);
     //if (def.type == symTypes.none) {
     //    break;
     //} else {
     //    span = new TextSpan();
     //    span.iStartLine = def.line - 1;
     //    span.iEndIndex = def.col;
     //    span.iStartIndex = 0;
     //    span.iEndLine = def.line - 1;
     //    return def.filePath;
     //}
     default:
         break;
     }
     return(null);
 }
Example #9
0
 public override string Goto(Microsoft.VisualStudio.VSConstants.VSStd97CmdID cmd, IVsTextView textView, int line, int col, out TextSpan span)
 {
     // Not implemented.
     span = new TextSpan();
     return(null);
 }
Example #10
0
        /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.HandleGoto"]/*' />
        /// <summary>Handles VsCommands.GotoDefn, VsCommands.GotoDecl and VsCommands.GotoRef by
        /// calling OnSyncGoto on the Source object and opening the text editor on the resulting
        /// URL, then scrolling to the resulting span.</summary>
        public virtual void HandleGoto(VsCommands cmd) {
            TextSpan ts = new TextSpan();

            // Get the caret position
            NativeMethods.ThrowOnFailure(this.textView.GetCaretPos(out ts.iStartLine, out ts.iStartIndex));
            ts.iEndLine = ts.iStartLine;
            ts.iEndIndex = ts.iStartIndex;

            // Get the tip text at that location. 
            // Wait, since the user specifically requested this one...
            TextSpan span;
            string url = this.source.OnSyncGoto(cmd, this.textView, ts.iEndLine, ts.iEndIndex, out span);

            if (url == null || url.Trim().Length == 0) { // nothing to show
                return;
            }

            // Open the referenced document, and scroll to the given location.
            IVsUIHierarchy hierarchy;
            uint itemID;
            IVsWindowFrame frame;
            IVsTextView view;

            VsShell.OpenDocument(this.service.Site, url, NativeMethods.LOGVIEWID_Code, out hierarchy, out itemID, out frame, out view);
            if (view != null) {
                TextSpanHelper.MakePositive(ref span);
                NativeMethods.ThrowOnFailure(view.EnsureSpanVisible(span));
                NativeMethods.ThrowOnFailure(view.SetSelection(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex));
            }
        }
Example #11
0
        /// <summary>Handles VsCommands.GotoDefn, VsCommands.GotoDecl and VsCommands.GotoRef by
        /// calling OnSyncGoto on the Source object and opening the text editor on the resulting
        /// URL, then scrolling to the resulting span.</summary>
        public virtual void HandleGoto(VsCommands cmd, int line, int col) {

            // Get the tip text at that location. 
            this.gotoCmd = cmd;
            this.source.BeginBackgroundRequest(line, col, new TokenInfo(), BackgroundRequestReason.Goto, this.textView, RequireFreshResults.No, 
                new BackgroundRequestResultHandler(HandleGotoResponse));
        }
Example #12
0
        public override void HandleGoto(VsCommands cmd)
        {
            int line, col;

            // Get the caret position
            ErrorHandler.ThrowOnFailure(this.TextView.GetCaretPos(out line, out col));
            bool gotoDefinition = false;
            switch (cmd)
            {
                case VSConstants.VSStd97CmdID.GotoDecl:
                case VSConstants.VSStd97CmdID.GotoDefn: gotoDefinition = true; break;

                case VSConstants.VSStd97CmdID.GotoRef:
                    Trace.WriteLine("GoToReference() not implemenred yet");
                    break;
                default: Trace.Assert(false); break;
            }

            Source.Goto(TextView, gotoDefinition, line, col);
        }
Example #13
0
        public override string Goto(Microsoft.VisualStudio.VSConstants.VSStd97CmdID cmd, Microsoft.VisualStudio.TextManager.Interop.IVsTextView textView, int line, int col, out Microsoft.VisualStudio.TextManager.Interop.TextSpan span)
        {
            span = new Microsoft.VisualStudio.TextManager.Interop.TextSpan();

            return(null);
        }
Example #14
0
        /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.HandlePreExec"]/*' />
        public virtual bool HandlePreExec(ref Guid guidCmdGroup, uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            this.wasCompletionActive = this.Source.IsCompletorActive;
            this.gotEnterKey         = false;

            if (guidCmdGroup == VsMenus.guidStandardCommandSet97)
            {
                VsCommands cmd = (VsCommands)nCmdId;
#if TRACE_EXEC
                if (cmd != VsCommands.SolutionCfg && cmd != VsCommands.SearchCombo)
                {
                    Trace.WriteLine(String.Format("ExecCommand: {0}", cmd.ToString()));
                }
#endif
                switch (cmd)
                {
                case VsCommands.GotoDefn:
                case VsCommands.GotoDecl:
                case VsCommands.GotoRef:
                    HandleGoto(cmd);
                    return(true);
                }
            }
            else if (guidCmdGroup == VsMenus.guidStandardCommandSet2K)
            {
                VsCommands2K cmd = (VsCommands2K)nCmdId;
                switch (cmd)
                {
                case VsCommands2K.FORMATDOCUMENT:
                    this.ReformatDocument();
                    return(true);

                case VsCommands2K.FORMATSELECTION:
                    this.ReformatSelection();
                    return(true);

                case VsCommands2K.COMMENT_BLOCK:
                    this.CommentSelection();
                    return(true);

                case VsCommands2K.UNCOMMENT_BLOCK:
                    this.UncommentSelection();
                    return(true);

                case VsCommands2K.COMPLETEWORD: {
                    int line, col;
                    NativeMethods.ThrowOnFailure(this.textView.GetCaretPos(out line, out col));
                    this.source.Completion(this.textView, this.source.GetTokenInfo(line, col), ParseReason.CompleteWord);
                    return(true);
                }

                case VsCommands2K.SHOWMEMBERLIST: {
                    int line, col;
                    NativeMethods.ThrowOnFailure(this.textView.GetCaretPos(out line, out col));
                    this.source.Completion(this.textView, this.source.GetTokenInfo(line, col), ParseReason.DisplayMemberList);
                    return(true);
                }

                case VsCommands2K.PARAMINFO: {
                    int line;
                    int col;
                    NativeMethods.ThrowOnFailure(this.textView.GetCaretPos(out line, out col));
                    this.source.MethodTip(this.textView, line, col, this.source.GetTokenInfo(line, col));
                    return(true);
                }

                case VsCommands2K.QUICKINFO: {
                    HandleQuickInfo();
                    return(true);
                }

                case VsCommands2K.SHOWCONTEXTMENU:
                    this.ShowContextMenu(VsMenus.IDM_VS_CTXT_CODEWIN, VsMenus.guidSHLMainMenu, this);
                    return(true);

                //                    case VsCommands2K.HANDLEIMEMESSAGE:
                //                        if (pvaOut != IntPtr.Zero) {
                //                            Marshal.GetNativeVariantForObject(false, pvaOut); //debug this make sure it's right ...
                //                        }
                //                        break;

                case VsCommands2K.OUTLN_STOP_HIDING_ALL:
                    this.source.OutliningEnabled = false;
                    break;

                case VsCommands2K.OUTLN_START_AUTOHIDING:
                    this.source.OutliningEnabled = true;
                    break;

                case VsCommands2K.AUTOCOMPLETE:
                    // See if completion set just completed.
                    OnAutoComplete();
                    return(true);
                }
            }
            else if (guidCmdGroup == typeof(LanguageServiceCommands).GUID)
            {
                switch ((LanguageServiceCommands)nCmdId)
                {
                case LanguageServiceCommands.RunTasks:
                    this.source.LanguageService.RunTasks();
                    return(true);
                }
            }
            return(false);
        }
Example #15
0
        /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.QueryCommandStatus"]/*' />
        /// <summary>
        /// Override this method to intercept the IOleCommandTarget::QueryStatus call.
        /// </summary>
        /// <param name="guidCmdGroup"></param>
        /// <param name="cmd"></param>
        /// <param name="pCmdText">null if info not required by caller</param>
        /// <returns>Usually returns a combination of OLECMDF flags, for example
        /// OLECMDF_ENABLED | OLECMDF_SUPPORTED.
        /// Return E_FAIL if want to delegate to the next command target.
        /// </returns>
        protected virtual int QueryCommandStatus(ref Guid guidCmdGroup, uint nCmdId)
        {
            ExpansionProvider ep = GetExpansionProvider();

            if (ep != null && ep.InTemplateEditingMode)
            {
                int hr = 0;
                if (ep.HandleQueryStatus(ref guidCmdGroup, nCmdId, out hr))
                {
                    return(hr);
                }
            }
            if (guidCmdGroup == VsMenus.guidStandardCommandSet97)
            {
                VsCommands cmd = (VsCommands)nCmdId;

                switch (cmd)
                {
                case VsCommands.GotoDefn:
                case VsCommands.GotoDecl:
                case VsCommands.GotoRef:
                    return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);
                }
            }
            else if (guidCmdGroup == VsMenus.guidStandardCommandSet2K)
            {
                VsCommands2K cmd = (VsCommands2K)nCmdId;

                switch (cmd)
                {
                case VsCommands2K.FORMATDOCUMENT:
                    if (this.CanReformat())
                    {
                        return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);
                    }
                    break;

                case VsCommands2K.FORMATSELECTION:
                    if (this.CanReformat())
                    {
                        return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);
                    }
                    break;

                case VsCommands2K.COMMENT_BLOCK:
                case VsCommands2K.UNCOMMENT_BLOCK:
                    if (this.commentSupported)
                    {
                        return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);
                    }
                    break;

                case VsCommands2K.SHOWMEMBERLIST:
                case VsCommands2K.COMPLETEWORD:
                case VsCommands2K.PARAMINFO:
                    return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);

                case VsCommands2K.QUICKINFO:
                    if (this.service.Preferences.EnableQuickInfo)
                    {
                        return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);
                    }
                    break;

                //                    case VsCommands2K.HANDLEIMEMESSAGE:
                //                        return 0;

                // Let the core editor handle this.  Stop outlining also removes user
                // defined hidden sections so it is handy to keep this enabled.
                //                    case VsCommands2K.OUTLN_STOP_HIDING_ALL:
                //                        int rc = (int)OLECMDF.OLECMDF_SUPPORTED;
                //                        if (this.source.OutliningEnabled) {
                //                            rc |= (int)OLECMDF.OLECMDF_ENABLED;
                //                        }
                //                        return rc;

                case VsCommands2K.OUTLN_START_AUTOHIDING:
                    if (!this.source.OutliningEnabled)
                    {
                        return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);
                    }
                    break;

                case VsCommands2K.AUTOCOMPLETE:
                    return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);
                }
            }
            else if (guidCmdGroup == typeof(LanguageServiceCommands).GUID)
            {
                switch ((LanguageServiceCommands)nCmdId)
                {
                case LanguageServiceCommands.RunTasks:
                    return((int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED);
                }
            }

            return((int)NativeMethods.E_FAIL); // delegate to next command target.
        }
Example #16
0
        /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.HandleGoto"]/*' />
        /// <summary>Handles VsCommands.GotoDefn, VsCommands.GotoDecl and VsCommands.GotoRef by
        /// calling OnSyncGoto on the Source object and opening the text editor on the resulting
        /// URL, then scrolling to the resulting span.</summary>
        public virtual void HandleGoto(VsCommands cmd)
        {
            int line, col;

            // Get the caret position
            NativeMethods.ThrowOnFailure(this.textView.GetCaretPos(out line, out col));

            // Get the tip text at that location.
            this.gotoCmd = cmd;
            this.source.BeginParse(line, col, new TokenInfo(), ParseReason.Goto, this.textView,
                new ParseResultHandler(HandleGotoResponse));
        }