Skip to content

Commit

Permalink
Fix issue cannot open a SARIF log if there is any tool notification.
Browse files Browse the repository at this point in the history
  • Loading branch information
yongyan-gh committed Oct 20, 2023
1 parent e0a5a42 commit 84980e7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Sarif.Viewer.VisualStudio.Core/ErrorList/ErrorListService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,21 +701,22 @@ private int WriteRunToErrorList(Run run, string logFilePath, SarifLog sarifLog,
this.ShowFilteredSuppressionStateColumn();
}

if (!skipRemapping && dataCache.SarifErrors.Any())
var sarifResults = dataCache.SarifErrors.Where(r => r.SarifResult != null).ToList();
if (!skipRemapping && sarifResults.Any())
{
IEnumerable<string> relativeFilePaths = dataCache.SarifErrors.Select(x => x.FileName);
IEnumerable<string> uriBaseIds = dataCache.SarifErrors.Select(x => x.SarifResult.Locations?.FirstOrDefault()?.PhysicalLocation?.ArtifactLocation?.UriBaseId);
IEnumerable<string> relativeFilePaths = sarifResults.Select(x => x.FileName);
IEnumerable<string> uriBaseIds = sarifResults.Select(x => x.SarifResult.Locations?.FirstOrDefault()?.PhysicalLocation?.ArtifactLocation?.UriBaseId);

// now we need to map from relative file path to absolute.
string workingDirectory = dataCache.SarifErrors.FirstOrDefault().WorkingDirectory;
string workingDirectory = sarifResults.FirstOrDefault().WorkingDirectory;

// find the mapped path with codeanalysisresultmanager
List<string> resolvedFilePaths = CodeManagerInstance.ResolveFilePaths(dataCache, workingDirectory, logFilePath, uriBaseIds.ToList(), relativeFilePaths.ToList());
CodeManagerInstance.RemapFilePaths(dataCache.SarifErrors, relativeFilePaths.ToList(), resolvedFilePaths);
CodeManagerInstance.RemapFilePaths(sarifResults, relativeFilePaths.ToList(), resolvedFilePaths);

// remap regions and lineNumber of the sarif error list items
var codeFinderCache = new Dictionary<string, CodeFinder>(); // local file path -> codefinder
foreach (SarifErrorListItem item in dataCache.SarifErrors)
foreach (SarifErrorListItem item in sarifResults)
{
List<(Uri filePath, MatchQuery query)?> queries = item.GetMatchQueries();
if (queries != null)
Expand Down

0 comments on commit 84980e7

Please sign in to comment.