in src/Sarif.Viewer.VisualStudio.Core/Models/SarifErrorListItem.cs [455:546]
internal void RemapFilePath(string originalPath, string remappedPath)
{
ThreadHelper.ThrowIfNotOnUIThread();
var uri = new Uri(remappedPath, UriKind.Absolute);
FileRegionsCache regionsCache = CodeAnalysisResultManager.Instance.RunIndexToRunDataCache[this.RunIndex].FileRegionsCache;
if (this.FileName.Equals(originalPath, StringComparison.OrdinalIgnoreCase))
{
this.FileName = remappedPath;
}
foreach (LocationModel location in this.Locations)
{
if (location.FilePath.Equals(originalPath, StringComparison.OrdinalIgnoreCase))
{
location.FilePath = remappedPath;
location.Region = regionsCache.PopulateTextRegionProperties(location.Region, uri, true);
}
}
foreach (LocationModel location in this.RelatedLocations)
{
if (location.FilePath.Equals(originalPath, StringComparison.OrdinalIgnoreCase))
{
location.FilePath = remappedPath;
location.Region = regionsCache.PopulateTextRegionProperties(location.Region, uri, true);
}
}
foreach (AnalysisStep analysisStep in this.AnalysisSteps)
{
var nodesToProcess = new Stack<AnalysisStepNode>();
foreach (AnalysisStepNode topLevelNode in analysisStep.TopLevelNodes)
{
nodesToProcess.Push(topLevelNode);
}
while (nodesToProcess.Count > 0)
{
AnalysisStepNode current = nodesToProcess.Pop();
try
{
if (current.FilePath?.Equals(originalPath, StringComparison.OrdinalIgnoreCase) == true)
{
current.FilePath = remappedPath;
current.Region = regionsCache.PopulateTextRegionProperties(current.Region, uri, true);
}
}
catch (ArgumentException)
{
// An argument exception is thrown if the node does not have a region.
// Since there's no region, there's no document to attach to.
// Just move on with processing the child nodes.
}
foreach (AnalysisStepNode childNode in current.Children)
{
nodesToProcess.Push(childNode);
}
}
}
foreach (StackCollection stackCollection in this.Stacks)
{
foreach (StackFrameModel stackFrame in stackCollection)
{
if (stackFrame.FilePath.Equals(originalPath, StringComparison.OrdinalIgnoreCase))
{
stackFrame.FilePath = remappedPath;
stackFrame.Region = regionsCache.PopulateTextRegionProperties(stackFrame.Region, uri, true);
}
}
}
foreach (FixModel fixModel in this.Fixes)
{
foreach (ArtifactChangeModel fileChangeModel in fixModel.ArtifactChanges)
{
if (fileChangeModel.FilePath.Equals(originalPath, StringComparison.OrdinalIgnoreCase))
{
fileChangeModel.FilePath = remappedPath;
}
}
}
// After the file-paths have been remapped, we need to refresh the tags
// as it may now be possible to create the persistent spans (since the file paths are now potentially valid)
// or their file paths may have moved from one valid location to a different valid location.
SarifLocationTagHelpers.RefreshTags();
}