/// <summary>
        /// Gets the highlight for the specified StyleCop Violation.
        /// </summary>
        /// <param name="violation">
        /// The <see cref="StyleCop.ViolationEventArgs"/> instance containing the event data.
        /// </param>
        /// <param name="documentRange">
        /// <see cref="DocumentRange"/>where the Violation happened.
        /// </param>
        /// <param name="fileName">
        /// <see cref="CsElement"/>of the violation.
        /// </param>
        /// <param name="lineNumber">
        /// Line number where the violation happened.
        /// </param>
        /// <returns>
        /// An <see cref="IHighlighting"/> for the specified Violation.
        /// </returns>
        public static IHighlighting GetHighlight(ViolationEventArgs violation, DocumentRange documentRange, string fileName, int lineNumber)
        {
            string ruleID      = violation.Violation.Rule.CheckId;
            string highlightID = HighlightingRegistering.GetHighlightID(ruleID);

            // To get the correct severity for a highlight we need to specify the current solution.
            ISolutionManager solutionManager = Shell.Instance.GetComponent <ISolutionManager>();
            Severity         severity        = HighlightingSettingsManager.Instance.GetConfigurableSeverity(highlightID, solutionManager.CurrentSolution);

            switch (severity)
            {
            case Severity.ERROR:
                return(new StyleCopViolationError(violation, documentRange, fileName, lineNumber));

            case Severity.HINT:
                return(new StyleCopViolationHint(violation, documentRange, fileName, lineNumber));

            case Severity.INFO:
                return(new StyleCopViolationError(violation, documentRange, fileName, lineNumber));

            case Severity.SUGGESTION:
                return(new StyleCopViolationSuggestion(violation, documentRange, fileName, lineNumber));

            case Severity.WARNING:
                return(new StyleCopViolationWarning(violation, documentRange, fileName, lineNumber));

            default:
                return(new StyleCopViolationDoNotShow(violation, documentRange, fileName, lineNumber));
            }
        }
        /// <summary>
        /// Gets the highlight for the specified StyleCop Violation.
        /// </summary>
        /// <param name="violation">
        /// The <see cref="StyleCop.ViolationEventArgs"/> instance containing the event data.
        /// </param>
        /// <param name="documentRange">
        /// <see cref="DocumentRange"/>where the Violation happened.
        /// </param>
        /// <param name="fileName">
        /// <see cref="CsElement"/>of the violation.
        /// </param>
        /// <param name="lineNumber">
        /// Line number where the violation happened.
        /// </param>
        /// <returns>
        /// An <see cref="IHighlighting"/> for the specified Violation.
        /// </returns>
        public static IHighlighting GetHighlight(ViolationEventArgs violation, DocumentRange documentRange, string fileName, int lineNumber)
        {
            string ruleID      = violation.Violation.Rule.CheckId;
            string highlightID = HighlightingRegistering.GetHighlightID(ruleID);

            Severity severity = HighlightingSettingsManager.Instance.Settings.GetSeverity(highlightID);

            switch (severity)
            {
            case Severity.ERROR:
                return(new StyleCopViolationError(violation, documentRange, fileName, lineNumber));

            case Severity.HINT:
                return(new StyleCopViolationHint(violation, documentRange, fileName, lineNumber));

            case Severity.INFO:
                return(new StyleCopViolationError(violation, documentRange, fileName, lineNumber));

            case Severity.SUGGESTION:
                return(new StyleCopViolationSuggestion(violation, documentRange, fileName, lineNumber));

            case Severity.WARNING:
                return(new StyleCopViolationWarning(violation, documentRange, fileName, lineNumber));

            default:
                return(new StyleCopViolationDoNotShow(violation, documentRange, fileName, lineNumber));
            }
        }
Example #3
0
        /// <summary>
        /// Gets the actions for changing the highlight options for StyleCop rules.
        /// </summary>
        /// <param name="highlighting">
        /// The current highlighting.
        /// </param>
        /// <param name="solution">
        /// The solution.
        /// </param>
        /// <param name="highlightingRange">
        /// The current highlighting range.
        /// </param>
        /// <param name="sourceFile">
        /// The file.
        /// </param>
        /// <returns>
        /// The available actions.
        /// </returns>
        public IEnumerable <JB::JetBrains.Util.Pair <IBulbAction, BulbMenuItemViewDescription> > GetActions(
            IHighlighting highlighting, ISolution solution, DocumentRange highlightingRange, IPsiSourceFile sourceFile)
        {
            StyleCopHighlightingBase violation = highlighting as StyleCopHighlightingBase;

            if (violation == null)
            {
                yield break;
            }

            string ruleId      = violation.CheckId;
            string highlightId = HighlightingRegistering.GetHighlightID(ruleId);

            ChangeStyleCopRuleAction changeStyleCopRuleAction = new ChangeStyleCopRuleAction(
                this.highlightingSettingsManager, this.settingsStore, highlightId, this.commonIconsComponent)
            {
                Text =
                    "Inspection Options for \"" + violation.ToolTip
                    + "\""
            };

            yield return
                (JB::JetBrains.Util.Pair.Of <IBulbAction, BulbMenuItemViewDescription>(
                     changeStyleCopRuleAction,
                     new BulbMenuItemViewDescription(AnchorsForConfigureHighlightingSubmenu.ConfigureItem, BulbThemedIcons.DisableBulb.Id, changeStyleCopRuleAction.Text)));
        }
        /// <summary>
        /// Gets the highlight for the specified StyleCop Violation.
        /// </summary>
        /// <param name="violation">
        /// The <see cref="StyleCop.ViolationEventArgs"/> instance containing the event data.
        /// </param>
        /// <param name="documentRange">
        /// <see cref="DocumentRange"/>where the Violation happened.
        /// </param>
        /// <param name="fileName">
        /// <see cref="CsElement"/>of the violation.
        /// </param>
        /// <param name="lineNumber">
        /// Line number where the violation happened.
        /// </param>
        /// <returns>
        /// An <see cref="IHighlighting"/> for the specified Violation.
        /// </returns>
        public static IHighlighting GetHighlight(ViolationEventArgs violation, DocumentRange documentRange, string fileName, int lineNumber)
        {
            string ruleID      = violation.Violation.Rule.CheckId;
            string highlightID = HighlightingRegistering.GetHighlightID(ruleID);

            VSSolutionManager solutionManager = Shell.Instance.GetComponent <VSSolutionManager>();

            IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, solutionManager.CurrentSolution);

            Severity severity = HighlightingSettingsManager.Instance.GetConfigurableSeverity(highlightID, settingsStore);

            switch (severity)
            {
            case Severity.ERROR:
                return(new StyleCopHighlightingError(violation, documentRange, fileName, lineNumber));

            case Severity.HINT:
                return(new StyleCopHighlightingHint(violation, documentRange, fileName, lineNumber));

            case Severity.INFO:
                return(new StyleCopHighlightingError(violation, documentRange, fileName, lineNumber));

            case Severity.SUGGESTION:
                return(new StyleCopHighlightingSuggestion(violation, documentRange, fileName, lineNumber));

            case Severity.WARNING:
                return(new StyleCopHighlightingWarning(violation, documentRange, fileName, lineNumber));

            default:
                return(new StyleCopHighlightingDoNotShow(violation, documentRange, fileName, lineNumber));
            }
        }
        /// <summary>
        /// Gets the actions for changing the highlight options for StyleCop rules.
        /// </summary>
        /// <param name="highlighting">
        /// The current highlighting.
        /// </param>
        /// <param name="highlightingRange">
        /// The current highlighting range.
        /// </param>
        /// <param name="sourceFile">
        /// The file.
        /// </param>
        /// <param name="configureAnchor">The anchor for configuration items</param>
        /// <returns>
        /// The available actions.
        /// </returns>
        public IEnumerable <IntentionAction> GetActions(IHighlighting highlighting, DocumentRange highlightingRange, IPsiSourceFile sourceFile,
                                                        IAnchor configureAnchor)
        {
            StyleCopHighlightingBase violation = highlighting as StyleCopHighlightingBase;

            if (violation == null)
            {
                yield break;
            }

            string ruleId      = violation.CheckId;
            string highlightId = HighlightingRegistering.GetHighlightID(ruleId);

            ChangeStyleCopRuleAction changeStyleCopRuleAction = new ChangeStyleCopRuleAction(
                this.highlightingSettingsManager,
                this.settingsStore,
                highlightId,
                this.commonIconsComponent)
            {
                Text = "Inspection Options for \"" + violation.ToolTip + "\""
            };

            yield return
                (new IntentionAction(changeStyleCopRuleAction, changeStyleCopRuleAction.Text, BulbThemedIcons.ContextAction.Id, IntentionsAnchors.ContextActionsAnchor));
        }
        /// <summary>
        /// Gets the highlight for the specified StyleCop Violation.
        /// </summary>
        /// <param name="solution">
        /// The current solution.
        /// </param>
        /// <param name="violation">
        /// The <see cref="StyleCop.ViolationEventArgs"/> instance containing the event data.
        /// </param>
        /// <param name="documentRange">
        /// <see cref="DocumentRange"/>where the Violation happened.
        /// </param>
        /// <returns>
        /// An <see cref="IHighlighting"/> for the specified Violation.
        /// </returns>
        public static IHighlighting GetHighlight(ISolution solution, ViolationEventArgs violation, DocumentRange documentRange)
        {
            string ruleID      = violation.Violation.Rule.CheckId;
            string highlightID = HighlightingRegistering.GetHighlightID(ruleID);

            Severity severity = HighlightingSettingsManager.Instance.GetConfigurableSeverity(highlightID, solution);

            switch (severity)
            {
            case Severity.ERROR:
                return(new StyleCopHighlightingError(violation, documentRange));

            case Severity.HINT:
                return(new StyleCopHighlightingHint(violation, documentRange));

            case Severity.INFO:
                return(new StyleCopHighlightingError(violation, documentRange));

            case Severity.SUGGESTION:
                return(new StyleCopHighlightingSuggestion(violation, documentRange));

            case Severity.WARNING:
                return(new StyleCopHighlightingWarning(violation, documentRange));

            default:
                return(new StyleCopHighlightingDoNotShow(violation, documentRange));
            }
        }
        /// <summary>
        /// Gets the highlight for the specified StyleCop Violation.
        /// </summary>
        /// <param name="solution">
        /// The current solution.
        /// </param>
        /// <param name="violation">
        /// The <see cref="StyleCop.ViolationEventArgs"/> instance containing the event data.
        /// </param>
        /// <param name="documentRange">
        /// <see cref="DocumentRange"/>where the Violation happened.
        /// </param>
        /// <returns>
        /// An <see cref="IHighlighting"/> for the specified Violation.
        /// </returns>
        public static IHighlighting GetHighlight(ISolution solution, ViolationEventArgs violation, DocumentRange documentRange)
        {
            string ruleID      = violation.Violation.Rule.CheckId;
            string highlightID = HighlightingRegistering.GetHighlightID(ruleID);

            if (ruleID == "SA0102") // Syntax error from parser
            {
                return(new StyleCopErrorHighlighting(violation, documentRange));
            }

            Severity severity = HighlightingSettingsManager.Instance.GetConfigurableSeverity(highlightID, sourceFile: null, solution: solution);

            return(new StyleCopHighlighting(violation, documentRange, severity, highlightID));
        }
Example #8
0
        /// <summary>
        /// Gets the actions for changing the highlight options for StyleCop rules.
        /// </summary>
        /// <param name="highlighting">
        /// The current highlighting.
        /// </param>
        /// <param name="highlightingRange">
        /// The current highlighting range.
        /// </param>
        /// <returns>
        /// The available actions.
        /// </returns>
        public IEnumerable <IDisableHighlightingAction> Actions(IHighlighting highlighting, DocumentRange highlightingRange)
        {
            StyleCopViolationBase violation = highlighting as StyleCopViolationBase;

            if (violation == null)
            {
                return(JB::JetBrains.Util.EmptyArray <IDisableHighlightingAction> .Instance);
            }

            string ruleID      = violation.CheckId;
            string highlightID = HighlightingRegistering.GetHighlightID(ruleID);

            return(new IDisableHighlightingAction[]
            {
                new ChangeStyleCopRuleAction {
                    HighlightID = highlightID, Text = "Inspection Options for \"" + violation.ToolTip + "\""
                }
            });
        }
Example #9
0
        /// <summary>
        /// Gets the highlight for the specified StyleCop Violation.
        /// </summary>
        /// <param name="solution">
        /// The current solution.
        /// </param>
        /// <param name="violation">
        /// The <see cref="StyleCop.ViolationEventArgs"/> instance containing the event data.
        /// </param>
        /// <param name="documentRange">
        /// <see cref="DocumentRange"/>where the Violation happened.
        /// </param>
        /// <returns>
        /// An <see cref="IHighlighting"/> for the specified Violation.
        /// </returns>
        public static IHighlighting GetHighlight(ISolution solution, ViolationEventArgs violation, DocumentRange documentRange)
        {
            string ruleID      = violation.Violation.Rule.CheckId;
            string highlightID = HighlightingRegistering.GetHighlightID(ruleID);

            if (ruleID == "SA0102") // Syntax error from parser
            {
                return(new StyleCopErrorHighlighting(violation, documentRange));
            }

            ISettingsStore             settingsStore             = solution.GetSettingsStore().SettingsStore;
            IContextBoundSettingsStore contextBoundSettingsStore =
                settingsStore.BindToContextTransient(ContextRange.Smart(documentRange.Document.ToDataContext()));

            Severity severity = HighlightingSettingsManager.Instance.GetConfigurableSeverity(
                highlightID,
                sourceFile: null,
                storeBoundToSourceFile: contextBoundSettingsStore);

            return(new StyleCopHighlighting(violation, documentRange, severity, highlightID));
        }