mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
[highlighting] provide an option to convert warning to no highlighting (fix available) (IDEA-297134)
GitOrigin-RevId: b0dc62f585cc0327d08c465b502ffdc7e04c9ea0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
73e650cf0a
commit
a2c3d6945e
@@ -0,0 +1,7 @@
|
||||
// "Disable highlighting, keep fix" "true"
|
||||
class MyTest {
|
||||
{
|
||||
int a = 0;
|
||||
a = a;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Disable highlighting, keep fix" "true"
|
||||
class MyTest {
|
||||
{
|
||||
int a = 0;
|
||||
a = <caret>a;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
******************************************************************************/
|
||||
package com.intellij.java.codeInsight.daemon.quickFix
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey
|
||||
import com.intellij.codeInsight.daemon.quickFix.ActionHint
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase
|
||||
import com.intellij.codeInspection.LocalInspectionTool
|
||||
import com.intellij.codeInspection.sillyAssignment.SillyAssignmentInspection
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager
|
||||
import com.intellij.testFramework.runInInitMode
|
||||
import org.jetbrains.annotations.NonNls
|
||||
|
||||
class DisableHighlightingActionTest : LightQuickFixParameterizedTestCase() {
|
||||
private var myKey: HighlightDisplayKey? = null
|
||||
override fun configureLocalInspectionTools(): Array<LocalInspectionTool> {
|
||||
return arrayOf(
|
||||
SillyAssignmentInspection()
|
||||
)
|
||||
}
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
myKey = HighlightDisplayKey.find(SillyAssignmentInspection().shortName)
|
||||
}
|
||||
|
||||
override fun getBasePath(): @NonNls String {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/disableHighlighting"
|
||||
}
|
||||
|
||||
override fun doAction(actionHint: ActionHint, testFullPath: String, testName: String) {
|
||||
//ensure action which access inspection profile can do that
|
||||
runInInitMode {
|
||||
super.doAction(actionHint, testFullPath, testName)
|
||||
}
|
||||
assertEquals(HighlightDisplayLevel.DO_NOT_SHOW,
|
||||
InspectionProjectProfileManager.getInstance(project).currentProfile.getErrorLevel(myKey!!, null))
|
||||
}
|
||||
}
|
||||
@@ -207,6 +207,7 @@ notification.title.unix.socket.connection=Unix socket connection
|
||||
command.name.gather.fixes=Collect fixes
|
||||
intention.family.name.fix.all.problems.like.this=Fix all problems like this
|
||||
intention.name.apply.all.fixes.in.file=Apply all ''{0}'' fixes in file
|
||||
intention.family.name.disable.highlighting.keep.fix=Disable highlighting, keep fix
|
||||
|
||||
file.read.error=Cannot read from file {0}.
|
||||
file.write.error=Cannot write to file {0}.
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.codeHighlighting.Pass;
|
||||
import com.intellij.codeInsight.daemon.GutterMark;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.impl.actions.DisableHighlightingIntentionAction;
|
||||
import com.intellij.codeInsight.daemon.impl.actions.IntentionActionWithFixAllOption;
|
||||
import com.intellij.codeInsight.intention.*;
|
||||
import com.intellij.codeInspection.*;
|
||||
@@ -934,6 +935,10 @@ public class HighlightInfo implements Segment {
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
IntentionAction action = IntentionActionDelegate.unwrap(myAction);
|
||||
if (!(action instanceof EmptyIntentionAction)) {
|
||||
newOptions.add(new DisableHighlightingIntentionAction(toolWrapper.getShortName()));
|
||||
}
|
||||
ContainerUtil.addIfNotNull(newOptions, fixAllIntention);
|
||||
if (wrappedTool instanceof CustomSuppressableInspectionTool) {
|
||||
IntentionAction[] suppressActions = ((CustomSuppressableInspectionTool)wrappedTool).getSuppressActions(element);
|
||||
@@ -947,7 +952,6 @@ public class HighlightInfo implements Segment {
|
||||
newOptions.addAll(ContainerUtil.map(suppressFixes, SuppressIntentionActionFromFix::convertBatchToSuppressIntentionAction));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (myProblemGroup instanceof SuppressableProblemGroup) {
|
||||
IntentionAction[] suppressActions = ((SuppressableProblemGroup)myProblemGroup).getSuppressActions(element);
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.daemon.impl.actions;
|
||||
|
||||
import com.intellij.analysis.AnalysisBundle;
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInspection.IntentionAndQuickFixAction;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModelKt;
|
||||
import com.intellij.codeInspection.ex.ToolsImpl;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DisableHighlightingIntentionAction extends IntentionAndQuickFixAction {
|
||||
private final String myShortName;
|
||||
|
||||
public DisableHighlightingIntentionAction(String shortName) {
|
||||
myShortName = shortName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getFamilyName() {
|
||||
return AnalysisBundle.message("intention.family.name.disable.highlighting.keep.fix");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
InspectionProfileImpl profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
|
||||
HighlightSeverity usedSeverity = profile.getErrorLevel(HighlightDisplayKey.find(myShortName), file).getSeverity();
|
||||
return usedSeverity.compareTo(HighlightSeverity.INFORMATION) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
return getFamilyName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, PsiFile file, @Nullable Editor editor) {
|
||||
InspectionProfileModifiableModelKt.modifyAndCommitProjectProfile(project, it -> {
|
||||
ToolsImpl tools = it.getToolsOrNull(myShortName, project);
|
||||
if (tools != null) {
|
||||
tools.setLevel(HighlightDisplayLevel.DO_NOT_SHOW);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -337,32 +337,26 @@ public final class ToolsImpl implements Tools {
|
||||
|
||||
@NotNull
|
||||
public HighlightDisplayLevel getLevel(PsiElement element) {
|
||||
if (myTools == null || element == null) return myDefaultState.getLevel();
|
||||
return getState(element).getLevel();
|
||||
}
|
||||
|
||||
public ScopeToolState getState(PsiElement element) {
|
||||
if (myTools == null || element == null) return myDefaultState;
|
||||
Project project = element.getProject();
|
||||
DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
|
||||
for (ScopeToolState state : myTools) {
|
||||
NamedScope scope = state.getScope(project);
|
||||
PackageSet set = scope != null ? scope.getValue() : null;
|
||||
if (set != null && set.contains(element.getContainingFile(), manager)) {
|
||||
return state.getLevel();
|
||||
return state;
|
||||
}
|
||||
}
|
||||
return myDefaultState.getLevel();
|
||||
return myDefaultState;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TextAttributesKey getAttributesKey(PsiElement element) {
|
||||
if (myTools == null || element == null) return myDefaultState.getEditorAttributesKey();
|
||||
Project project = element.getProject();
|
||||
DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
|
||||
for (ScopeToolState state : myTools) {
|
||||
NamedScope scope = state.getScope(project);
|
||||
PackageSet set = scope != null ? scope.getValue() : null;
|
||||
if (set != null && set.contains(element.getContainingFile(), manager)) {
|
||||
return state.getEditorAttributesKey();
|
||||
}
|
||||
}
|
||||
return myDefaultState.getEditorAttributesKey();
|
||||
return getState(element).getEditorAttributesKey();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -379,39 +373,15 @@ public final class ToolsImpl implements Tools {
|
||||
@Override
|
||||
public boolean isEnabled(PsiElement element) {
|
||||
if (!myEnabled) return false;
|
||||
if (myTools == null || element == null) return myDefaultState.isEnabled();
|
||||
Project project = element.getProject();
|
||||
DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
|
||||
for (ScopeToolState state : myTools) {
|
||||
NamedScope scope = state.getScope(project);
|
||||
if (scope != null) {
|
||||
PackageSet set = scope.getValue();
|
||||
if (set != null && set.contains(element.getContainingFile(), manager)) {
|
||||
return state.isEnabled();
|
||||
}
|
||||
}
|
||||
}
|
||||
return myDefaultState.isEnabled();
|
||||
return getState(element).isEnabled();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public InspectionToolWrapper<?,?> getEnabledTool(@Nullable PsiElement element, boolean includeDoNotShow) {
|
||||
if (!myEnabled) return null;
|
||||
if (myTools != null && element != null) {
|
||||
Project project = element.getProject();
|
||||
DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
|
||||
for (ScopeToolState state : myTools) {
|
||||
NamedScope scope = state.getScope(project);
|
||||
if (scope != null) {
|
||||
PackageSet set = scope.getValue();
|
||||
if (set != null && set.contains(element.getContainingFile(), manager)) {
|
||||
return state.isEnabled() && (includeDoNotShow || isAvailableInBatch(state)) ? state.getTool() : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return myDefaultState.isEnabled() && (includeDoNotShow || isAvailableInBatch(myDefaultState)) ? myDefaultState.getTool() : null;
|
||||
ScopeToolState state = getState(element);
|
||||
return state.isEnabled() && (includeDoNotShow || isAvailableInBatch(state)) ? state.getTool() : null;
|
||||
}
|
||||
|
||||
private static boolean isAvailableInBatch(ScopeToolState state) {
|
||||
@@ -555,6 +525,10 @@ public final class ToolsImpl implements Tools {
|
||||
}
|
||||
}
|
||||
|
||||
public void setLevel(HighlightDisplayLevel level, PsiElement element) {
|
||||
getState(element).setLevel(level);
|
||||
}
|
||||
|
||||
public void setLevel(@NotNull HighlightDisplayLevel level, @Nullable String scopeName, Project project) {
|
||||
if (scopeName == null) {
|
||||
myDefaultState.setLevel(level);
|
||||
|
||||
@@ -139,6 +139,7 @@ class ReportingTest : BasePlatformTestCase() {
|
||||
text.contains("Edit inspection")
|
||||
|| text.contains("Run inspection")
|
||||
|| text.contains("Disable inspection")
|
||||
|| text.contains("Disable highlighting, keep fix")
|
||||
|| text.contains("Fix all")
|
||||
|| text == CodeInsightBundle.message("assign.intention.shortcut")
|
||||
|| text == CodeInsightBundle.message("edit.intention.shortcut")
|
||||
|
||||
Reference in New Issue
Block a user