public ContentRepairSuggestion AlternateFix(string name, Func <IProgress <AsyncProgressEntry>, CancellationToken, Task <bool> > fix, bool affectsData = true,
                                             bool showProgressDialog = true)
 {
     Fixes.Add(new ContentRepairSuggestionFix(this, name, fix)
     {
         AffectsData        = affectsData,
         ShowProgressDialog = showProgressDialog
     });
     return(this);
 }
Esempio n. 2
0
        public SarifErrorListItem(Run run, Result result, string logFilePath, ProjectNameCache projectNameCache) : this()
        {
            IRule rule;

            run.TryGetRule(result.RuleId, result.RuleKey, out rule);
            Message           = result.GetMessageText(rule, concise: false);
            ShortMessage      = result.GetMessageText(rule, concise: true);
            FileName          = result.GetPrimaryTargetFile();
            ProjectName       = projectNameCache.GetName(FileName);
            Category          = result.GetCategory();
            Region            = result.GetPrimaryTargetRegion();
            Level             = result.Level;
            SuppressionStates = result.SuppressionStates;
            LogFilePath       = logFilePath;

            if (Region != null)
            {
                LineNumber   = Region.StartLine;
                ColumnNumber = Region.StartColumn;
            }

            Tool       = run.Tool.ToToolModel();
            Rule       = rule.ToRuleModel(result.RuleId);
            Invocation = run.Invocation.ToInvocationModel();

            if (string.IsNullOrWhiteSpace(run.Id))
            {
                WorkingDirectory = Path.Combine(Path.GetTempPath(), run.GetHashCode().ToString());
            }
            else
            {
                WorkingDirectory = Path.Combine(Path.GetTempPath(), run.Id);
            }

            if (result.Locations != null)
            {
                foreach (Location location in result.Locations)
                {
                    Locations.Add(location.ToAnnotatedCodeLocationModel());
                }
            }

            if (result.RelatedLocations != null)
            {
                foreach (AnnotatedCodeLocation annotatedCodeLocation in result.RelatedLocations)
                {
                    RelatedLocations.Add(annotatedCodeLocation.ToAnnotatedCodeLocationModel());
                }
            }

            if (result.CodeFlows != null)
            {
                foreach (CodeFlow codeFlow in result.CodeFlows)
                {
                    CallTrees.Add(codeFlow.ToCallTree());
                }

                CallTrees.Verbosity = 100;
                CallTrees.IntelligentExpand();
            }

            if (result.Stacks != null)
            {
                foreach (Stack stack in result.Stacks)
                {
                    Stacks.Add(stack.ToStackCollection());
                }
            }

            if (result.Fixes != null)
            {
                foreach (Fix fix in result.Fixes)
                {
                    Fixes.Add(fix.ToFixModel());
                }
            }
        }
Esempio n. 3
0
        public SarifErrorListItem(Run run, Result result, string logFilePath, ProjectNameCache projectNameCache) : this()
        {
            if (!SarifViewerPackage.IsUnitTesting)
            {
#pragma warning disable VSTHRD108 // Assert thread affinity unconditionally
                ThreadHelper.ThrowIfNotOnUIThread();
#pragma warning restore VSTHRD108 // Assert thread affinity unconditionally
            }
            _runId = CodeAnalysisResultManager.Instance.CurrentRunId;
            ReportingDescriptor rule = result.GetRule(run);
            Tool         = run.Tool.ToToolModel();
            Rule         = rule.ToRuleModel(result.RuleId);
            Invocation   = run.Invocations?[0]?.ToInvocationModel();
            Message      = result.GetMessageText(rule, concise: false).Trim();
            ShortMessage = result.GetMessageText(rule, concise: true).Trim();
            if (!Message.EndsWith("."))
            {
                ShortMessage = ShortMessage.TrimEnd('.');
            }
            FileName    = result.GetPrimaryTargetFile(run);
            ProjectName = projectNameCache.GetName(FileName);
            Category    = result.GetCategory();
            Region      = result.GetPrimaryTargetRegion();
            Level       = result.Level != FailureLevel.Warning ? result.Level : Rule.FailureLevel;

            if (result.Suppressions?.Count > 0)
            {
                VSSuppressionState = VSSuppressionState.Suppressed;
            }

            LogFilePath = logFilePath;

            if (Region != null)
            {
                LineNumber   = Region.StartLine;
                ColumnNumber = Region.StartColumn;
            }

            Tool             = run.Tool.ToToolModel();
            Rule             = rule.ToRuleModel(result.RuleId);
            Invocation       = run.Invocations?[0]?.ToInvocationModel();
            WorkingDirectory = Path.Combine(Path.GetTempPath(), _runId.ToString());

            if (result.Locations?.Any() == true)
            {
                // Adding in reverse order will make them display in the correct order in the UI.
                for (int i = result.Locations.Count - 1; i >= 0; --i)
                {
                    Locations.Add(result.Locations[i].ToLocationModel(run));
                }
            }

            if (result.RelatedLocations?.Any() == true)
            {
                for (int i = result.RelatedLocations.Count - 1; i >= 0; --i)
                {
                    RelatedLocations.Add(result.RelatedLocations[i].ToLocationModel(run));
                }
            }

            if (result.CodeFlows != null)
            {
                foreach (CodeFlow codeFlow in result.CodeFlows)
                {
                    CallTree callTree = codeFlow.ToCallTree(run);
                    if (callTree != null)
                    {
                        CallTrees.Add(callTree);
                    }
                }

                CallTrees.Verbosity = 100;
                CallTrees.IntelligentExpand();
            }

            if (result.Stacks != null)
            {
                foreach (Stack stack in result.Stacks)
                {
                    Stacks.Add(stack.ToStackCollection());
                }
            }

            if (result.Fixes != null)
            {
                foreach (Fix fix in result.Fixes)
                {
                    Fixes.Add(fix.ToFixModel());
                }
            }
        }