diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs index 31f29ff98e..5d2a530e29 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs @@ -339,7 +339,7 @@ namespace ICSharpCode.SharpDevelop.Services /// public Value GetValueFromName(string variableName) { - if (debuggedProcess == null || debuggedProcess.IsRunning || debuggedProcess.SelectedStackFrame == null) { + if (!CanEvaluate) { return null; } else { return ExpressionEvaluator.Evaluate(variableName, SupportedLanguage.CSharp, debuggedProcess.SelectedStackFrame); @@ -374,22 +374,29 @@ namespace ICSharpCode.SharpDevelop.Services } } + bool CanEvaluate + { + get { + return debuggedProcess != null && !debuggedProcess.IsRunning && debuggedProcess.SelectedStackFrame != null; + } + } + /// /// Gets the tooltip control that shows the value of given variable. /// Return null if no tooltip is available. /// public object GetTooltipControl(string variableName) { - ExpressionNode expressionNode; + if (!CanEvaluate) { + return null; + } try { - Value val = GetValueFromName(variableName); - if (val == null) return null; - expressionNode = new ExpressionNode(ExpressionNode.GetImageForLocalVariable(), variableName, val.ExpressionTree); + var tooltipExpression = ExpressionEvaluator.ParseExpression(variableName, SupportedLanguage.CSharp); + ExpressionNode expressionNode = new ExpressionNode(ExpressionNode.GetImageForLocalVariable(), variableName, tooltipExpression); + return new DebuggerTooltipControl(expressionNode); } catch (GetValueException) { return null; } - - return new DebuggerTooltipControl(expressionNode); } public bool CanSetInstructionPointer(string filename, int line, int column) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs index 12b2eec024..81ded8fc84 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs @@ -54,6 +54,23 @@ namespace Debugger return new ExpressionEvaluator(context).Evaluate(code, false); } + /// + /// Parses string representation of an expression (eg. "a.b[10] + 2") into NRefactory Expression tree. + /// + public static Expression ParseExpression(string code, SupportedLanguage language) + { + SnippetParser parser = new SnippetParser(language); + INode astRoot = parser.Parse(code); + if (parser.Errors.Count > 0) { + throw new GetValueException(parser.Errors.ErrorOutput); + } + Expression astExpression = astRoot as Expression; + if (astExpression == null) { + throw new GetValueException("Code must be expression"); + } + return astExpression; + } + public static string FormatValue(Value val) { if (val == null) {