Example #1
0
        /// <summary>
        /// Gets debugger tooltip information for the specified position.
        /// A descriptive text for the element or a DebuggerGridControl
        /// showing its current value (when in debugging mode) can be returned
        /// through the ToolTipInfo object.
        /// Returns <c>null</c>, if no tooltip information is available.
        /// </summary>
        internal static ToolTipInfo GetToolTipInfo(TextArea textArea, ToolTipRequestEventArgs e)
        {
            TextLocation      logicPos         = e.LogicalPosition;
            IDocument         doc              = textArea.Document;
            IExpressionFinder expressionFinder = ParserService.GetExpressionFinder(textArea.MotherTextEditorControl.FileName);

            if (expressionFinder == null)
            {
                return(null);
            }
            LineSegment seg = doc.GetLineSegment(logicPos.Y);

            if (logicPos.X > seg.Length - 1)
            {
                return(null);
            }
            string           textContent      = doc.TextContent;
            ExpressionResult expressionResult = expressionFinder.FindFullExpression(textContent, seg.Offset + logicPos.X);
            string           expression       = (expressionResult.Expression ?? "").Trim();

            if (expression.Length > 0)
            {
                // Look if it is variable
                ResolveResult result = ParserService.Resolve(expressionResult, logicPos.Y + 1, logicPos.X + 1, textArea.MotherTextEditorControl.FileName, textContent);
                bool          debuggerCanShowValue;
                string        toolTipText = GetText(result, expression, out debuggerCanShowValue);
                if (Control.ModifierKeys == Keys.Control)
                {
                    toolTipText          = "expr: " + expressionResult.ToString() + "\n" + toolTipText;
                    debuggerCanShowValue = false;
                }
                if (toolTipText != null)
                {
                    if (debuggerCanShowValue && currentDebugger != null)
                    {
                        return(new ToolTipInfo(currentDebugger.GetTooltipControl(expressionResult.Expression)));
                    }
                    return(new ToolTipInfo(toolTipText));
                }
            }
            else
            {
                                #if DEBUG
                if (Control.ModifierKeys == Keys.Control)
                {
                    return(new ToolTipInfo("no expr: " + expressionResult.ToString()));
                }
                                #endif
            }
            return(null);
        }
Example #2
0
        /// <summary>
        /// Gets debugger tooltip information for the specified position.
        /// A descriptive string for the element or a DebuggerTooltipControl
        /// showing its current value (when in debugging mode) can be returned
        /// through the ToolTipRequestEventArgs.SetTooltip() method.
        /// </summary>
        public static void HandleToolTipRequest(ToolTipRequestEventArgs e)
        {
            if (!e.InDocument)
            {
                return;
            }

            var logicPos = e.LogicalPosition;
            var doc      = (TextDocument)e.Editor.Document;
            var line     = doc.GetLineByNumber(logicPos.Line);

            if (line.Offset + logicPos.Column >= doc.TextLength)
            {
                return;
            }

            var c = doc.GetText(line.Offset + logicPos.Column, 1);

            if (string.IsNullOrEmpty(c) || c == "\n" || c == "\t")
            {
                return;
            }

            string variable =
                ParserService.SimpleParseAt(doc.Text, doc.GetOffset(new TextLocation(logicPos.Line, logicPos.Column)));

            if (currentDebugger == null || !currentDebugger.IsDebugging || !currentDebugger.CanEvaluate)
            {
                e.ContentToShow = null;
            }
            else
            {
                try {
                    e.ContentToShow = currentDebugger.GetTooltipControl(e.LogicalPosition, variable);
                } catch {
                    return;
                }
            }
        }
Example #3
0
        /// <summary>
        /// Gets debugger tooltip information for the specified position.
        /// A descriptive string for the element or a DebuggerTooltipControl
        /// showing its current value (when in debugging mode) can be returned
        /// through the ToolTipRequestEventArgs.SetTooltip() method.
        /// </summary>
        public static void HandleToolTipRequest(ToolTipRequestEventArgs e)
        {
            if (!e.InDocument)
            {
                return;
            }

            var logicPos = e.LogicalPosition;
            var doc      = (TextDocument)e.Editor.Document;
            var line     = doc.GetLineByNumber(logicPos.Line);

            if (line.Offset + logicPos.Column >= doc.TextLength)
            {
                return;
            }

            var c = doc.GetText(line.Offset + logicPos.Column, 1);

            if (string.IsNullOrEmpty(c) || c == "\n" || c == "\t")
            {
                return;
            }

            string variable =
                ParserService.SimpleParseAt(doc.Text, doc.GetOffset(new TextLocation(logicPos.Line, logicPos.Column)));

            if (currentDebugger == null || !currentDebugger.IsDebugging || !currentDebugger.CanEvaluate)
            {
                e.ContentToShow = null;
            }
            else
            {
                try {
                    e.ContentToShow = currentDebugger.GetTooltipControl(e.LogicalPosition, variable);
                } catch {
                    return;
                }
            }

            // FIXME Do proper parsing
//
//			using (var sr = new StringReader(doc.Text))
//			{
//				var parser = new CSharpParser();
//				parser.Parse(sr);
//
//				IExpressionFinder expressionFinder = ParserService.GetExpressionFinder();
//				if (expressionFinder == null)
//					return;
//				var currentLine = doc.GetLine(logicPos.Y);
//				if (logicPos.X > currentLine.Length)
//					return;
//				string textContent = doc.Text;
//				ExpressionResult expressionResult = expressionFinder.FindFullExpression(textContent, doc.GetOffset(new TextLocation(logicPos.Line, logicPos.Column)));
//				string expression = (expressionResult.Expression ?? "").Trim();
//				if (expression.Length > 0) {
//					// Look if it is variable
//					ResolveResult result = ParserService.Resolve(expressionResult, logicPos.Y, logicPos.X, e.Editor.FileName, textContent);
//					bool debuggerCanShowValue;
//					string toolTipText = GetText(result, expression, out debuggerCanShowValue);
//					if (Control.ModifierKeys == Keys.Control) {
//						toolTipText = "expr: " + expressionResult.ToString() + "\n" + toolTipText;
//						debuggerCanShowValue = false;
//					}
//					if (toolTipText != null) {
//						if (debuggerCanShowValue && currentDebugger != null) {
//							object toolTip = currentDebugger.GetTooltipControl(e.LogicalPosition, expressionResult.Expression);
//							if (toolTip != null)
//								e.SetToolTip(toolTip);
//							else
//								e.SetToolTip(toolTipText);
//						} else {
//							e.SetToolTip(toolTipText);
//						}
//					}
//				}
//				else {
//					#if DEBUG
//					if (Control.ModifierKeys == Keys.Control) {
//						e.SetToolTip("no expr: " + expressionResult.ToString());
//					}
//					#endif
//				}
//			}
        }
Example #4
0
        /// <summary>
        /// Gets debugger tooltip information for the specified position.
        /// A descriptive string for the element or a DebuggerTooltipControl
        /// showing its current value (when in debugging mode) can be returned
        /// through the ToolTipRequestEventArgs.SetTooltip() method.
        /// </summary>
        internal static void HandleToolTipRequest(ToolTipRequestEventArgs e)
        {
            if (!e.InDocument)
            {
                return;
            }
            Location logicPos = e.LogicalPosition;
            var      doc      = e.Editor.Document;
            FileName fileName = e.Editor.FileName;

            IExpressionFinder expressionFinder = ParserService.GetExpressionFinder(fileName);

            if (expressionFinder == null)
            {
                return;
            }

            var currentLine = doc.GetLine(logicPos.Y);

            if (logicPos.X > currentLine.Length)
            {
                return;
            }
            string           textContent      = doc.Text;
            ExpressionResult expressionResult = expressionFinder.FindFullExpression(textContent, doc.PositionToOffset(logicPos.Line, logicPos.Column));
            string           expression       = (expressionResult.Expression ?? "").Trim();

            if (expression.Length > 0)
            {
                // Look if it is variable
                ResolveResult result = ParserService.Resolve(expressionResult, logicPos.Y, logicPos.X, fileName, textContent);
                bool          debuggerCanShowValue;
                string        toolTipText = GetText(result, expression, out debuggerCanShowValue);
                if (Control.ModifierKeys == Keys.Control)
                {
                    toolTipText          = "expr: " + expressionResult.ToString() + "\n" + toolTipText;
                    debuggerCanShowValue = false;
                }
                if (toolTipText != null)
                {
                    if (debuggerCanShowValue && currentDebugger != null)
                    {
                        object toolTip = currentDebugger.GetTooltipControl(e.LogicalPosition, expressionResult.Expression);
                        if (toolTip != null)
                        {
                            e.SetToolTip(toolTip);
                        }
                        else
                        {
                            e.SetToolTip(toolTipText);
                        }
                    }
                    else
                    {
                        e.SetToolTip(toolTipText);
                    }
                }
            }
            else
            {
                                #if DEBUG
                if (Control.ModifierKeys == Keys.Control)
                {
                    e.SetToolTip("no expr: " + expressionResult.ToString());
                }
                                #endif
            }
        }