internal static ExpressionEvaluatorDispatcher Create(Microsoft.VisualStudio.Shell.Interop.IVsDebugger vsDebugger,
                                                             IExpressionEvaluatorContainer container,
                                                             IExpressionsCache expressionCache)
        {
            ExpressionEvaluatorDispatcher result = new ExpressionEvaluatorDispatcher(container, expressionCache);
            uint debugEventsCookie = VSConstants.VSCOOKIE_NIL;

            result._debuggerEvents = new DebuggerEvents(vsDebugger);
            result._debuggerEvents.OnEnterBreakMode  += result.OnEnterBreakMode;
            result._debuggerEvents.OnEnterDesignMode += result.debuggerSink_OnEnterDesignMode;
            vsDebugger.AdviseDebuggerEvents(result._debuggerEvents, out debugEventsCookie).ThrowOnFailure();
            return(result);
        }
Esempio n. 2
0
        /// <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 override int GetFullDataTipText(string textValue, TextSpan ts, out string fullTipText)
        {
            IVsTextLines textLines;

            fullTipText = textValue;

            ErrorHandler.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 = Source.LanguageService.GetIVsDebugger();

                if (debugger != null && Source.LanguageService.IsDebugging)
                {
                    var tsdeb = new TextSpan[1] {
                        new TextSpan()
                    };
                    if (!TextSpanHelper.IsEmpty(ts))
                    {
                        // While debugging we always want to evaluate the expression user is hovering over
                        ErrorHandler.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 LANGTRACE
            } catch (COMException e) {
                Trace.WriteLine("COMException: GetDataTipValue, errorcode=" + e.ErrorCode);
#else
            }
            catch (System.Runtime.InteropServices.COMException)
            {
#endif
            }

            if (string.IsNullOrEmpty(fullTipText))
            {
                fullTipText = textValue;
            }

            return(NativeMethods.S_OK);
        }