From 34ac59acaaf26ae6ebf014134d507bc89b614bab Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Tue, 19 Aug 2025 19:28:53 +0800 Subject: [PATCH] fix: allow Inline Vulnerability Severity Alerts level change. Signed-off-by: Chao Wang --- .../componentanalysis/CAAnnotator.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jboss/tools/intellij/componentanalysis/CAAnnotator.java b/src/main/java/org/jboss/tools/intellij/componentanalysis/CAAnnotator.java index 845ed44..091d55e 100644 --- a/src/main/java/org/jboss/tools/intellij/componentanalysis/CAAnnotator.java +++ b/src/main/java/org/jboss/tools/intellij/componentanalysis/CAAnnotator.java @@ -14,6 +14,7 @@ import com.github.packageurl.PackageURL; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.codeInsight.daemon.HighlightDisplayKey; +import com.intellij.codeHighlighting.HighlightDisplayLevel; import com.intellij.codeInspection.InspectionProfile; import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.lang.annotation.AnnotationBuilder; @@ -165,7 +166,7 @@ public void apply(@NotNull PsiFile file, Map annotationResul if (!quickfixes.isEmpty() && this.isQuickFixApplicable(e)) { quickfixes.forEach((source, report) ->{ AnnotationBuilder builder = holder - .newAnnotation(getHighlightSeverity(report), messageBuilder.toString()) + .newAnnotation(getHighlightSeverity(report, e), messageBuilder.toString()) .tooltip(tooltipBuilder.toString()) .range(e); if(CAIntentionAction.isQuickFixAvailable(report)) { @@ -189,16 +190,24 @@ public void apply(@NotNull PsiFile file, Map annotationResul } @NotNull - private static HighlightSeverity getHighlightSeverity(DependencyReport report) { - if(CAIntentionAction.thereAreNoIssues(report) && CAIntentionAction.thereIsRecommendation(report)) - { - return HighlightSeverity.WEAK_WARNING; + private HighlightSeverity getHighlightSeverity(DependencyReport report, @NotNull PsiElement context) { + // Get the configured severity from the inspection settings + final InspectionProfileEntry inspection = this.getInspection(context, this.getInspectionShortName()); + if (inspection != null) { + final InspectionProfile profile = InspectionProjectProfileManager.getInstance(context.getProject()).getCurrentProfile(); + final HighlightDisplayKey key = HighlightDisplayKey.find(this.getInspectionShortName()); + if (key != null) { + HighlightDisplayLevel level = profile.getErrorLevel(key, context); + return level.getSeverity(); + } } - else - { + + // Fallback to original logic if inspection settings can't be determined + if(CAIntentionAction.thereAreNoIssues(report) && CAIntentionAction.thereIsRecommendation(report)) { + return HighlightSeverity.WEAK_WARNING; + } else { return HighlightSeverity.ERROR; } - } abstract protected String getInspectionShortName();