Exemplo n.º 1
0
        /// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.GetFullDataTipText"]/*' />
        /// <summary>This method checks to see if the IVsDebugger is running, and if so,
        /// calls it to get additional information about the current token and returns a combined result.
        /// You can return an HRESULT here like TipSuccesses2.TIP_S_NODEFAULTTIP.</summary>
        public virtual int GetFullDataTipText(string textValue, TextSpan ts, out string fullTipText)
        {
            IVsTextLines textLines;

            fullTipText = textValue;

            NativeMethods.ThrowOnFailure(this.textView.GetBuffer(out textLines));

            // Now, check if the debugger is running and has anything to offer
            try {
                Microsoft.VisualStudio.Shell.Interop.IVsDebugger debugger = this.service.GetIVsDebugger();
                if (debugger != null && this.mgr.LanguageService.IsDebugging)
                {
                    TextSpan[] tsdeb = new TextSpan[1] {
                        new TextSpan()
                    };
                    if (!TextSpanHelper.IsEmpty(ts))
                    {
                        // While debugging we always want to evaluate the expression user is hovering over
                        NativeMethods.ThrowOnFailure(textView.GetWordExtent(ts.iStartLine, ts.iStartIndex, (uint)WORDEXTFLAGS.WORDEXT_FINDEXPRESSION, tsdeb));
                        // If it failed to find something, then it means their is no expression so return S_FALSE
                        if (TextSpanHelper.IsEmpty(tsdeb[0]))
                        {
                            return(NativeMethods.S_FALSE);
                        }
                    }
                    string debugTextTip = null;
                    int    hr           = debugger.GetDataTipValue(textLines, tsdeb, null, out debugTextTip);
                    fullTipText = debugTextTip;
                    if (hr == (int)TipSuccesses2.TIP_S_NODEFAULTTIP)
                    {
                        return(hr);
                    }
                    if (!string.IsNullOrEmpty(debugTextTip) && debugTextTip != textValue)
                    {
                        // The debugger in this case returns "=value [type]" which we can
                        // append to the variable name so we get "x=value[type]" as the full tip.
                        int i = debugTextTip.IndexOf('=');
                        if (i >= 0)
                        {
                            string spacer = (i < debugTextTip.Length - 1 && debugTextTip[i + 1] == ' ') ? " " : "";
                            fullTipText = textValue + spacer + debugTextTip.Substring(i);
                        }
                    }
                }
#if DEBUG
            } catch (COMException e) {
                Trace.WriteLine("COMException: GetDataTipValue, errorcode=" + e.ErrorCode);
#else
            } catch (COMException) {
#endif
            }
            if (string.IsNullOrEmpty(fullTipText))
            {
                fullTipText = textValue;
            }
            return(NativeMethods.S_OK);
        }
Exemplo n.º 2
0
        public virtual string GetFullDataTipText(string text, TextSpan ts)
        {
            IVsTextLines textLines;

            this.textView.GetBuffer(out textLines);

            // Now, check if the debugger is running and has anything to offer
            string debugDataTip = null;

            try {
                Microsoft.VisualStudio.Shell.Interop.IVsDebugger debugger = this.service.GetIVsDebugger();
                if (debugger != null)
                {
                    TextSpan[] tsdeb = new TextSpan[1] {
                        ts
                    };
                    bool selection = ((ts.iStartLine != ts.iEndLine) || (ts.iStartIndex != ts.iEndIndex));
                    if (!selection)
                    {
                        // The debugger can't determine the current word by itself.
                        // Do it for them...
                        textView.GetWordExtent(ts.iStartLine, ts.iStartIndex, (uint)WORDEXTFLAGS.WORDEXT_FINDWORD | (uint)WORDEXTFLAGS.WORDEXT_CURRENT, tsdeb);
                    }
                    // What a royal pain!
//          Microsoft.VisualStudio.Shell.Interop.TextSpan[] tsa = new Microsoft.VisualStudio.Shell.Interop.TextSpan[1];
//          tsa[0].iEndIndex = tsdeb[0].iEndIndex;
//          tsa[0].iEndLine = tsdeb[0].iEndLine;
//          tsa[0].iStartIndex = tsdeb[0].iStartIndex;
//          tsa[0].iStartLine = tsdeb[0].iStartLine;

                    debugger.GetDataTipValue(textLines, tsdeb, null, out debugDataTip);
                }
            } catch (COMException e) {
                Trace.WriteLine("GetDataTipValue=" + e.ErrorCode);
            }

            if (debugDataTip == null || debugDataTip == "")
            {
                return(text);
            }

            int i = debugDataTip.IndexOf('=');

            if (i < 0)
            {
                return(text);
            }
            else
            {
                string spacer = (i < debugDataTip.Length - 1 && debugDataTip[i + 1] == ' ') ? " " : "";
                return(text + spacer + debugDataTip.Substring(i));
            }
        }