public IAnalysisIssueVisualization Convert(IAnalysisIssueBase issue, ITextSnapshot textSnapshot = null)
        {
            var issueSpan = textSnapshot == null
                ? (SnapshotSpan?)null
                : issueSpanCalculator.CalculateSpan(issue, textSnapshot);

            var flows = Convert(issue.Flows);

            var issueVisualization = new AnalysisIssueVisualization(flows, issue, issueSpan);

            if (textSnapshot != null)
            {
                CalculateSpanForSecondaryLocationsInSameFile(issueVisualization, textSnapshot);
            }

            return(issueVisualization);
        }
 /// <summary>
 /// Calculate spans for locations that don't have a span, or have a span in a different text buffer.
 /// </summary>
 /// <remarks>
 /// All spans for issues in the this file should have been calculated when the file was analysed (whether primary or secondary).
 /// However, there could be secondary locations relating to issues in other files that have not been calculated.
 /// Also, if a file has been closed and re-opened, a new text buffer would've been created. So we need to recalculate the spans since the locations would have spans that belong to the old text buffer.
 /// </remarks>
 private void EnsureUpdatedSpansExist(IEnumerable <IAnalysisIssueLocationVisualization> locVizs, ITextSnapshot currentSnapshot)
 {
     foreach (var locViz in locVizs)
     {
         if (!locViz.Span.HasValue || locViz.Span.Value.IsEmpty || locViz.Span.Value.Snapshot.TextBuffer != currentSnapshot.TextBuffer)
         {
             locViz.Span = spanCalculator.CalculateSpan(locViz.Location, currentSnapshot);
         }
     }
 }
        private SnapshotSpan GetOrCalculateLocationSpan(IAnalysisIssueLocationVisualization locationVisualization, ITextView textView)
        {
            var shouldCalculateSpan = !locationVisualization.Span.HasValue;

            if (shouldCalculateSpan)
            {
                locationVisualization.Span = spanCalculator.CalculateSpan(locationVisualization.Location, textView.TextBuffer.CurrentSnapshot);
            }

            return(locationVisualization.Span.Value);
        }