Exemple #1
0
        public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken)
        {
            DevSkimError error = GetErrorUnderCaret(range);

            if (error != null && error.Actionable)
            {
                List <ISuggestedAction> fixActions = new List <ISuggestedAction>();

                ITrackingSpan trackingSpan = range.Snapshot.CreateTrackingSpan(error.Span, SpanTrackingMode.EdgeInclusive);

                // Create list of fixes if the rule has them..
                if (error.Rule.Fixes != null)
                {
                    foreach (CodeFix fix in error.Rule.Fixes)
                    {
                        fixActions.Add(new FixSuggestedAction(trackingSpan, error.Rule, fix));
                    }
                }

                int suppressDays = Settings.GetSettings().SuppressDays;

                List <ISuggestedAction> suppActions = new List <ISuggestedAction>();
                var line = range.Snapshot.GetLineFromPosition(range.Start);
                trackingSpan = line.Snapshot.CreateTrackingSpan(line.Extent, SpanTrackingMode.EdgeInclusive);

                suppActions.Add(new SuppressSuggestedAction(trackingSpan, error.Rule, suppressDays));
                suppActions.Add(new SuppressSuggestedAction(trackingSpan, error.Rule));

                // If there is multiple issues on the line, offer "Suppress all"
                if (SkimShim.HasMultipleProblems(trackingSpan.GetText(range.Snapshot),
                                                 trackingSpan.TextBuffer.ContentType.TypeName))
                {
                    suppActions.Add(new SuppressSuggestedAction(trackingSpan, null, suppressDays));
                    suppActions.Add(new SuppressSuggestedAction(trackingSpan, null));
                }

                VSPackage.LogEvent(string.Format("Lightbulb invoked on {0} {1}", error.Rule.Id, error.Rule.Name));

                // We don't want empty group and spacer in the pop-up menu
                if (fixActions.Count > 0)
                {
                    return new SuggestedActionSet[] { new SuggestedActionSet(fixActions), new SuggestedActionSet(suppActions) }
                }
                ;
                else
                {
                    return new SuggestedActionSet[] { new SuggestedActionSet(suppActions) }
                };
            }

            return(Enumerable.Empty <SuggestedActionSet>());
        }