コード例 #1
0
        /// <summary>
        /// Finds the proper text to be used for a tree node
        /// </summary>
        /// <param name="node"> node to find name for </param>
        /// <returns>name of the node to display on tree </returns>
        public static string TextSelector(Object node)
        {
            if (node is ProxyNode)
            {
                node = ((ProxyNode)node).Original;
            }
            string text = node switch
            {
                Project p => p.Name,
                Target t => "Target " + t.Name,
                Folder f => f.Name,
                ProjectEvaluation pe => pe.Name,
                   Microsoft.Build.Logging.StructuredLogger.Task ta => "Task " + ta.Title + " duration " + ta.DurationText,
                AddItem a => "Add Item " + a.Name,
                RemoveItem r => "Remove Item " + r.Name,
                Item i => i.NameAndEquals + " " + i.ShortenedText,
                Metadata m => m.NameAndEquals + " " + m.ShortenedValue,
                EvaluationProfileEntry epe => epe.Title + " " + epe.DurationText + " " + epe.ShortenedElementDescription,
                Property p => p.NameAndEquals + " " + p.ShortenedValue,
                Parameter p => p.Name,
                Message m => m.ShortenedText,
                Import i => "Import " + i.Name + " " + i.Location,
                NoImport ni => "NoImport " + ni.Name + " " + ni.Location + " " + ni.Text,
                Error e => e.ToString(),
                Warning w => w.ToString(),
                Note n => n.Text,
                SourceFile sf => sf.Name,
                SourceFileLine sfl => sfl.LineNumber + " " + sfl.LineText,
                ProxyNode pn => pn.TypeName,
                TimedNode t => t.Name,
                   _ => node.ToString()
            };

            return(text);
        }
コード例 #2
0
        private IEnumerable BuildFindResults(object resultsObject, bool moreAvailable = false)
        {
            if (resultsObject == null)
            {
                return(null);
            }

            var results = resultsObject as IEnumerable <(string, IEnumerable <(int, string)>)>;

            var root = new Folder();

            // root.Children.Add(new Message { Text = "Elapsed " + Elapsed.ToString() });

            if (results != null)
            {
                foreach (var file in results)
                {
                    var folder = new SourceFile()
                    {
                        Name           = Path.GetFileName(file.Item1),
                        SourceFilePath = file.Item1,
                        IsExpanded     = true
                    };
                    root.AddChild(folder);
                    foreach (var line in file.Item2)
                    {
                        var sourceFileLine = new SourceFileLine()
                        {
                            LineNumber = line.Item1 + 1,
                            LineText   = line.Item2
                        };
                        folder.AddChild(sourceFileLine);
                    }
                }
            }

            if (!root.HasChildren && !string.IsNullOrEmpty(findInFilesControl.SearchText))
            {
                root.Children.Add(new Message
                {
                    Text = "No results found."
                });
            }

            return(root.Children);
        }
コード例 #3
0
        protected override void HandleStackTraceRequestAsync(IRequestResponder <StackTraceArguments, StackTraceResponse> responder)
        {
            // Create a list of stack frames or try to get cached ones.
            List <StackFrame> stackFrames;
            bool cachedStackFrames = ReferenceContainer.TryGetStackFrames(responder.Arguments.ThreadId, out stackFrames);

            // Verify we have a thread state for this thread, and a valid step to represent in it.
            if (!cachedStackFrames && ThreadStates.TryGetValue(responder.Arguments.ThreadId, out var threadState) && threadState.CurrentStepIndex.HasValue)
            {
                // Initialize our stack frame list
                stackFrames = new List <StackFrame>();

                // Obtain the callstack
                var callstack = threadState.ExecutionTraceAnalysis.GetCallStack(threadState.CurrentStepIndex.Value);

                // Loop through our scopes.
                for (int i = 0; i < callstack.Length; i++)
                {
                    // Grab our current call frame
                    var currentStackFrame = callstack[i];

                    // If the scope could not be resolved within a function, and no lines could be resolved, skip to the next frame.
                    // as this is not a code section we can describe in any meaningful way.
                    if (!currentStackFrame.ResolvedFunction && currentStackFrame.CurrentPositionLines.Length == 0)
                    {
                        continue;
                    }

                    // If we couldn't resolve the current position or there were no lines representing it
                    if (currentStackFrame.Error || currentStackFrame.CurrentPositionLines.Length == 0)
                    {
                        continue;
                    }

                    // Obtain the method name we are executing in.
                    string frameName = currentStackFrame.FunctionName;
                    if (string.IsNullOrEmpty(frameName))
                    {
                        frameName = "<undefined>";
                    }

                    // Determine the bounds of our stack frame.
                    int startLine   = 0;
                    int startColumn = 0;
                    int endLine     = 0;
                    int endColumn   = 0;

                    // Loop through all of our lines for this position.
                    for (int x = 0; x < currentStackFrame.CurrentPositionLines.Length; x++)
                    {
                        // Obtain our indexed line.
                        SourceFileLine line = currentStackFrame.CurrentPositionLines[x];

                        // Set our start position if relevant.
                        if (x == 0 || line.LineNumber <= startLine)
                        {
                            // Set our starting line number.
                            startLine = line.LineNumber;

                            // TODO: Determine our column start
                        }

                        // Set our end position if relevant.
                        if (x == 0 || line.LineNumber >= endLine)
                        {
                            // Set our ending line number.
                            endLine = line.LineNumber;

                            // TODO: Determine our column
                            endColumn = line.Length;
                        }
                    }

                    // Format agnostic path to platform specific path
                    var sourceFilePath = currentStackFrame.CurrentPositionLines[0].SourceFileMapParent.SourceFilePath;
                    if (Path.DirectorySeparatorChar == '\\')
                    {
                        sourceFilePath = sourceFilePath.Replace('/', Path.DirectorySeparatorChar);
                    }

                    // Create our source object
                    Source stackFrameSource = new Source()
                    {
                        Name = currentStackFrame.CurrentPositionLines[0].SourceFileMapParent.SourceFileName,
                        Path = Path.Join(ConfigurationProperties.WorkspaceDirectory, _contractsDirectory, sourceFilePath)
                    };

                    var stackFrame = new StackFrame()
                    {
                        Id        = ReferenceContainer.GetUniqueId(),
                        Name      = frameName,
                        Line      = startLine,
                        Column    = startColumn,
                        Source    = stackFrameSource,
                        EndLine   = endLine,
                        EndColumn = endColumn
                    };

                    // Add the stack frame to our reference list
                    ReferenceContainer.LinkStackFrame(threadState.ThreadId, stackFrame, currentStackFrame.CurrentPositionTraceIndex);

                    // Add our stack frame to the result list
                    stackFrames.Add(stackFrame);
                }
            }

            // Return our stack frames in our response.
            responder.SetResponse(new StackTraceResponse(stackFrames));
        }
コード例 #4
0
        protected override void HandleStackTraceRequestAsync(IRequestResponder <StackTraceArguments, StackTraceResponse> responder)
        {
            // Create a list of stack frames or try to get cached ones.
            List <StackFrame> stackFrames;
            bool cachedStackFrames = ReferenceContainer.TryGetStackFrames(responder.Arguments.ThreadId, out stackFrames);

            // Verify we have a thread state for this thread, and a valid step to represent in it.
            if (!cachedStackFrames && ThreadStates.TryGetValue(responder.Arguments.ThreadId, out var threadState) && threadState.CurrentStepIndex.HasValue)
            {
                // Initialize our stack frame list
                stackFrames = new List <StackFrame>();

                // Obtain the callstack
                var callstack = threadState.ExecutionTraceAnalysis.GetCallStack(threadState.CurrentStepIndex.Value);

                // Loop through our scopes.
                for (int i = 0; i < callstack.Length; i++)
                {
                    // Grab our current call frame
                    var currentCallFrame = callstack[i];

                    // If the scope is invalid, then we skip it.
                    if (currentCallFrame.FunctionDefinition == null)
                    {
                        continue;
                    }

                    // We obtain our relevant source lines for this call stack frame.
                    SourceFileLine[] lines = null;

                    // If it's the most recent call, we obtain the line for the current trace.
                    int traceIndex = -1;
                    if (i == 0)
                    {
                        traceIndex = threadState.CurrentStepIndex.Value;
                        lines      = threadState.ExecutionTraceAnalysis.GetSourceLines(traceIndex);
                    }
                    else
                    {
                        // If it's not the most recent call, we obtain the position at our
                        var previousCallFrame = callstack[i - 1];
                        if (previousCallFrame.ParentFunctionCall != null)
                        {
                            traceIndex = previousCallFrame.ParentFunctionCallIndex.Value;
                            lines      = threadState.ExecutionTraceAnalysis.GetSourceLines(previousCallFrame.ParentFunctionCall);
                        }
                        else
                        {
                            throw new Exception("TODO: Stack Trace could not be generated because previous call frame's function call could not be resolved. Update behavior in this case.");
                        }
                    }

                    // Obtain the method name we are executing in.
                    string frameName = currentCallFrame.FunctionDefinition.Name;
                    if (string.IsNullOrEmpty(frameName))
                    {
                        frameName = currentCallFrame.FunctionDefinition.IsConstructor ? $".ctor ({currentCallFrame.ContractDefinition.Name})" : "<unresolved>";
                    }

                    // Determine the bounds of our stack frame.
                    int startLine   = 0;
                    int startColumn = 0;
                    int endLine     = 0;
                    int endColumn   = 0;

                    // Loop through all of our lines for this position.
                    for (int x = 0; x < lines.Length; x++)
                    {
                        // Obtain our indexed line.
                        SourceFileLine line = lines[x];

                        // Set our start position if relevant.
                        if (x == 0 || line.LineNumber <= startLine)
                        {
                            // Set our starting line number.
                            startLine = line.LineNumber;

                            // TODO: Determine our column start
                        }

                        // Set our end position if relevant.
                        if (x == 0 || line.LineNumber >= endLine)
                        {
                            // Set our ending line number.
                            endLine = line.LineNumber;

                            // TODO: Determine our column
                            endColumn = line.Length;
                        }
                    }

                    // Format agnostic path to platform specific path
                    var sourceFilePath = lines[0].SourceFileMapParent.SourceFilePath;
                    if (Path.DirectorySeparatorChar == '\\')
                    {
                        sourceFilePath = sourceFilePath.Replace('/', Path.DirectorySeparatorChar);
                    }

                    // Create our source object
                    Source stackFrameSource = new Source()
                    {
                        Name = lines[0].SourceFileMapParent.SourceFileName,
                        Path = Path.Join(ConfigurationProperties.WorkspaceDirectory, _contractsDirectory, sourceFilePath)
                    };

                    var stackFrame = new StackFrame()
                    {
                        Id        = ReferenceContainer.GetUniqueId(),
                        Name      = frameName,
                        Line      = startLine,
                        Column    = startColumn,
                        Source    = stackFrameSource,
                        EndLine   = endLine,
                        EndColumn = endColumn
                    };

                    // Add the stack frame to our reference list
                    ReferenceContainer.LinkStackFrame(threadState.ThreadId, stackFrame, traceIndex);

                    // Add our stack frame to the result list
                    stackFrames.Add(stackFrame);
                }
            }

            // Return our stack frames in our response.
            responder.SetResponse(new StackTraceResponse(stackFrames));
        }
コード例 #5
0
ファイル: SourceLineMatching.cs プロジェクト: zutobg/Meadow
        public static IEnumerable <AstNode> MatchAstNodesToSourceFileLine(AnalysisResults analysis, SourceFileLine sourceFileLine)
        {
            foreach (var node in analysis.FullNodeList)
            {
                if (node.SourceIndex != sourceFileLine.SourceFileMapParent.SourceFileIndex)
                {
                    continue;
                }

                if (node.SourceRange.Offset >= sourceFileLine.Offset && node.SourceRange.Offset < sourceFileLine.OffsetEnd)
                {
                    yield return(node);
                }
            }
        }