예제 #1
0
        /// <summary>
        /// Creates the tree view for the adornment recursively.
        /// </summary>
        /// <param name="expression">DTE expression to parse</param>
        /// <returns>TreeViewItem representing the expression</returns>
        private static TreeViewItem BuildTreeView(EnvDTE.Expression expression)
        {
            TreeViewItem newItem = null;

            if (expression.DataMembers == null || expression.DataMembers.Count == 0)
            {
                newItem = GetTreeViewItem(expression.Name, expression.Value);
            }
            else
            {
                List <EnvDTE.Expression> dataMembers = expression.DataMembers.Cast <EnvDTE.Expression>().ToList();

                newItem = GetTreeViewItem(expression.Name, expression.Type);
                var childItems = new List <TreeViewItem>();

                if (_itemCount < MaxItems && _itemDepth < MaxLevels)
                {
                    _itemDepth++;
                    foreach (EnvDTE.Expression member in dataMembers)
                    {
                        childItems.Add(BuildTreeView(member));
                    }

                    newItem.ItemsSource = childItems;
                }
            }

            return(newItem);
        }
        public int[] GetDimensions(EnvDTE.Expression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            int[] dims;
            switch (GetExpressionType(expression))
            {
            case ExpressionType.Matrix:
                dims = new int[2];
                EnvDTE.Expressions members = expression.DataMembers.Item("Item").DataMembers;
                dims[0] = ParseDimension(members.Item("NumRows").Value);
                dims[1] = ParseDimension(members.Item("NumCols").Value);
                break;

            case ExpressionType.Vector:
                dims    = new int[1];
                dims[0] = expression.DataMembers.Count - 1;
                break;

            default:
                throw new NotSupportedException(string.Format("'{0} is not supported.'", expression.Type));
            }
            return(dims);
        }
예제 #3
0
        public Common.Expression GetEntry(params string[] entryNames)
        {
            var dte = ((DTE2)GetDTE());

            if (dte.Debugger.CurrentStackFrame == null) // Ensure that debugger is running
            {
                throw new Exception($"Could not find locals. Debugger is not running.");
            }

            var expressions = dte.Debugger.CurrentStackFrame.Locals;

            EnvDTE.Expression entry = null;

            var i = 0;

            while (i < entryNames.Length && TryGetEntryInternal(entryNames[i], expressions, out entry))
            {
                i++;
                expressions = entry.DataMembers;
            }

            if ((i == entryNames.Length) && (entry != null))
            {
                return(new Common.Expression(entry));
            }

            var localHierarchicalName = string.Join("->", entryNames);
            var allLocalsString       = string.Join("\n", GetAllLocals(dte.Debugger.CurrentStackFrame.Locals));

            throw new Exception($"\nCould not find the local named {localHierarchicalName}.\nAll available locals are: \n{allLocalsString}");
        }
예제 #4
0
        /// <summary>
        /// Creates an object representation of the given expression in order to serialize it to a string.
        /// </summary>
        /// <param name="expression">DTE expression to serialize</param>
        /// <returns>Convenient dictionary object representation to serialize</returns>
        private static object BuildString(EnvDTE.Expression expression)
        {
            Dictionary <string, object> newItem = new Dictionary <string, object>();

            if (expression.DataMembers == null || expression.DataMembers.Count == 0 || expression.Type.Contains("Function"))
            {
                return(expression.Value);
            }
            else if (expression.Name == "[Methods]")
            {
                return(new object[] {});
            }
            else
            {
                List <EnvDTE.Expression> dataMembers = expression.DataMembers.Cast <EnvDTE.Expression>().ToList();

                if (_itemCount < MaxItems * 5 && _itemDepth < MaxLevels * 2)
                {
                    _itemDepth++;
                    foreach (var member in dataMembers)
                    {
                        newItem.Add(member.Name, BuildString(member));
                    }
                }
            }

            return(newItem);
        }
        public int[] GetDimensions(EnvDTE.Expression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            ThreadHelper.ThrowIfNotOnUIThread();

            int[] dims;
            switch (GetExpressionType(expression))
            {
            case ExpressionType.Matrix:
                dims = new int[2];
                EnvDTE.Expressions members = expression.DataMembers.Item("Item").DataMembers;
                dims[0] = ParseDimension(members.Item("NumRows").Value);
                dims[1] = ParseDimension(members.Item("NumCols").Value);
                break;

            case ExpressionType.Vector:
                dims    = new int[1];
                dims[0] = expression.DataMembers.Count - 1;
                break;

            default:
                throw new NotSupportedException($"'{expression.Type} is not supported.'");
            }
            return(dims);
        }
        public int GetMembersCount(EnvDTE.Expression expression)
        {
            int[] dims = GetDimensions(expression);
            if (dims.Length == 1)
            {
                return(dims[0]);
            }

            return(dims[0] * dims[1]);
        }
예제 #7
0
        /// <summary>
        /// Creates the string representation of the object.
        /// </summary>
        /// <param name="expression">DTE expression for a given variable in the debugger</param>
        /// <param name="parallel">If true, builds out the string in parallel. Useful for large objects</param>
        /// <returns>Object</returns>
        public static object GetStringRepresentation(EnvDTE.Expression expression, bool prettyPrint = false, bool parallel = false)
        {
            _itemCount = _itemDepth = 0;

            var obj = BuildString(expression);

            _itemCount = _itemDepth = 0;

            return(JsonConvert.SerializeObject(obj, prettyPrint ? Formatting.Indented : Formatting.None));
        }
예제 #8
0
 private DebuggerVariable(EnvDTE.Debugger debugger, SnapshotPoint point, SnapshotSpan span, string name, EnvDTE.Expression expression)
 {
     this.debugger   = debugger;
     this.Point      = point;
     this.Span       = span;
     this.Name       = name;
     this.Type       = expression.Type;
     this.Value      = expression.Value;
     this.Expression = expression;
 }
예제 #9
0
        /// <summary>
        /// Creates the tree view for a given expression.
        /// </summary>
        /// <param name="expression">DTE expression for a debugger variable</param>
        /// <returns>Tree view for the adornment</returns>
        public static TreeView GetTreeView(EnvDTE.Expression expression)
        {
            TreeView treeView = new TreeView();

            _itemCount = _itemDepth = 0;

            treeView.ItemsSource = new List <TreeViewItem>()
            {
                BuildTreeView(expression)
            };

            _itemCount = _itemDepth = 0;
            return(treeView);
        }
예제 #10
0
        private bool TryGetEntryInternal(
            string entryName,
            EnvDTE.Expressions expressions,
            out EnvDTE.Expression expression
            )
        {
            expression = expressions
                         .Cast <EnvDTE.Expression>()
                         .FirstOrDefault(e => e.Name == entryName);
            if (expression != null)
            {
                return(true);
            }

            return(false);
        }
        private static ExpressionType GetExpressionType(EnvDTE.Expression expression)
        {
            string expressionName = expression.Type + new string(' ', 28);

            switch (expressionName.Substring(0, 28))
            {
            case "Microsoft.FSharp.Math.Matrix":
                return(ExpressionType.Matrix);

            case "Microsoft.FSharp.Math.Vector":
                return(ExpressionType.Vector);

            default:
                return(ExpressionType.UnKnown);
            }
        }
예제 #12
0
 private void GenerateInTaskAsync(EnvDTE.Expression experssion)
 {
     _ = Task.Run(async() =>
     {
         try
         {
             await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
             var generator        = new JsonGenerator();
             var json             = generator.GenerateJson(experssion);
             OutPut.Text          = json;
             OutPut.TextAlignment = TextAlignment.Left;
             CopyButton.IsEnabled = true;
         }
         catch (Exception ex)
         {
             TypeInfo.Text = $"Exception of type {ex.GetType()} occured";
             OutPut.Text   = ex.ToString();
         }
     });
 }
        public object[] GetValues(EnvDTE.Expression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            switch (GetExpressionType(expression))
            {
            case ExpressionType.Matrix:
                return(expression.DataMembers.Item("Item").DataMembers.Item("Values").DataMembers.Cast <EnvDTE.Expression>().Select(E => E.Value).ToArray());

            case ExpressionType.Vector:
                int count = expression.DataMembers.Count - 1;
                return(expression.DataMembers.Cast <EnvDTE.Expression>().Take(count).Select(E => E.Value).ToArray());

            default:
                throw new NotSupportedException(string.Format("'{0} is not supported.'", expression.Type));
            }
        }
예제 #14
0
        public void Evaluate(EnvDTE.Debugger debugger)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            Value = "<Unknown value>";

            if (IsLiteral)
            {
                Value = Expression;
                return;
            }

            try
            {
                if (debugger != null)
                {
                    EnvDTE.Expression expr = debugger.GetExpression(Expression, true);
                    if (expr != null)
                    {
                        Value = expr.Value;
                        Type  = expr.Type;
                    }

                    if (UseAddressForName)
                    {
                        EnvDTE.Expression nameExpr = debugger.GetExpression("&" + Expression, false);
                        if (nameExpr != null)
                        {
                            Name = nameExpr.Value;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Value = "Exception thrown: " + e.Message;
            }
        }
예제 #15
0
        public object[] GetValues(EnvDTE.Expression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            ThreadHelper.ThrowIfNotOnUIThread();

            switch (GetExpressionType(expression))
            {
            case ExpressionType.Matrix:
                return(expression.DataMembers.Item("Item").DataMembers.Item("Values").DataMembers
                       .Cast <EnvDTE.Expression>().Select(e => e.Value).ToArray());

            case ExpressionType.Vector:
                int count = expression.DataMembers.Count - 1;
                return(expression.DataMembers.Cast <EnvDTE.Expression>().Take(count).Select(e => e.Value).ToArray());

            default:
                throw new NotSupportedException($"'{expression.Type} is not supported.'");
            }
        }
        public string GetDisplayName(EnvDTE.Expression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            string formatter;

            int[] dimensions = GetDimensions(expression);
            switch (dimensions.Length)
            {
            case 2:
                formatter = "Matrix{0}{1},{2}{3}";
                return(string.Format(formatter, LeftBracket, dimensions[0], dimensions[1], RightBracket));

            case 1:
                formatter = "Vector{0}{1}{2}";
                return(string.Format(formatter, LeftBracket, dimensions[0], RightBracket));

            default:
                throw new NotSupportedException(string.Format("'{0} is not supported.'", expression.Type));
            }
        }
예제 #17
0
 public Expression(EnvDTE.Expression input)
 {
     Name  = input.Name;
     Type  = input.Type;
     Value = input.Value;
 }
예제 #18
0
 public object[] GetValues(EnvDTE.Expression expression)
 {
     return(_arrayLoader.GetValues(expression));
 }
예제 #19
0
 public int GetMembersCount(EnvDTE.Expression expression)
 {
     return(_arrayLoader.GetMembersCount(expression));
 }
예제 #20
0
 public int[] GetDimensions(EnvDTE.Expression expression)
 {
     return(_arrayLoader.GetDimensions(expression));
 }
예제 #21
0
 public string GetDisplayName(EnvDTE.Expression expression)
 {
     return(_arrayLoader.GetDisplayName(expression));
 }
예제 #22
0
 public bool IsExpressionTypeSupported(EnvDTE.Expression expression)
 {
     return(_arrayLoader.IsExpressionArrayType(expression));
 }
예제 #23
0
 public EnvDteDebugExpression(EnvDTE.Expression expression)
 {
     _expression = expression;
 }
 public bool IsExpressionTypeSupported(EnvDTE.Expression expression)
 {
     return(GetExpressionType(expression) != ExpressionType.UnKnown);
 }