Exemplo n.º 1
0
        private static GraphNode?GetLocationNode(Location location, IGraphContext context, ProjectId projectId, CancellationToken cancellationToken)
        {
            var span = location.GetLineSpan();

            if (location.SourceTree == null)
            {
                return(null);
            }

            var lineText       = location.SourceTree.GetText(cancellationToken).Lines[span.StartLinePosition.Line].ToString();
            var filePath       = location.SourceTree.FilePath;
            var sourceLocation = GraphBuilder.TryCreateSourceLocation(filePath, span.Span);

            if (sourceLocation == null)
            {
                return(null);
            }

            var label = string.Format("{0} ({1}, {2}): {3}",
                                      System.IO.Path.GetFileName(filePath),
                                      span.StartLinePosition.Line + 1,
                                      span.StartLinePosition.Character + 1,
                                      lineText.TrimStart());
            var locationNode = context.Graph.Nodes.GetOrCreate(sourceLocation.Value.CreateGraphNodeId(), label, CodeNodeCategories.SourceLocation);

            locationNode[CodeNodeProperties.SourceLocation]      = sourceLocation.Value;
            locationNode[RoslynGraphProperties.ContextProjectId] = projectId;
            locationNode[DgmlNodeProperties.Icon] = IconHelper.GetIconName("Reference", Accessibility.NotApplicable);

            return(locationNode);
        }