From 01883f5e3877bfb5edd3af9d4dcb1d5d7875e5a8 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 3 Jan 2020 18:18:08 +0100 Subject: [PATCH] SSR: fix error border after changing file type put callback in current document instead of document from dialog creation GitOrigin-RevId: c81c5e63db08def242ffcc4846b07af5a6d67cf0 --- .../JavaStructuralSearchProfile.java | 11 +-------- .../StructuralSearchProfile.java | 8 ++----- .../plugin/ui/StructuralSearchDialog.java | 24 ++++++------------- .../StructuralSearchHighlightInfoFilter.java | 6 ++++- 4 files changed, 15 insertions(+), 34 deletions(-) diff --git a/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java b/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java index abc07b90d2e9..66c7e428a3fa 100644 --- a/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java +++ b/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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-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. package com.intellij.structuralsearch; import com.intellij.codeInsight.AnnotationUtil; @@ -495,17 +495,8 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile { return result.toString(); } - @Override - public boolean highlightProblemsInEditor() { - return true; - } - @Override public boolean shouldShowProblem(HighlightInfo highlightInfo, PsiFile file, PatternContext context) { - if (!Registry.is("ssr.in.editor.problem.highlighting")) { - return false; - } - final PsiErrorElement error = findErrorElementAt(file, highlightInfo.startOffset, highlightInfo.getDescription()); if (error == null) { return false; diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/StructuralSearchProfile.java b/platform/structuralsearch/source/com/intellij/structuralsearch/StructuralSearchProfile.java index 2c867bde1d3e..add47d9e5299 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/StructuralSearchProfile.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/StructuralSearchProfile.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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-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. package com.intellij.structuralsearch; import com.intellij.codeInsight.daemon.impl.HighlightInfo; @@ -174,12 +174,8 @@ public abstract class StructuralSearchProfile { throw new UnsupportedPatternException(SSRBundle.message("replacement.not.supported.for.filetype", fileType)); } - public boolean highlightProblemsInEditor() { - return false; - } - public boolean shouldShowProblem(HighlightInfo highlightInfo, PsiFile file, PatternContext context) { - return true; + return false; } // only for nodes not filtered by lexical-nodes filter; they can be by default diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/StructuralSearchDialog.java b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/StructuralSearchDialog.java index ee0ad5508cee..70b70ff597fe 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/StructuralSearchDialog.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/StructuralSearchDialog.java @@ -1,7 +1,6 @@ -// Copyright 2000-2019 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-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. package com.intellij.structuralsearch.plugin.ui; -import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.codeInsight.highlighting.HighlightManager; import com.intellij.codeInsight.template.TemplateBuilder; import com.intellij.codeInsight.template.impl.TemplateEditorUtil; @@ -262,21 +261,12 @@ public class StructuralSearchDialog extends DialogWrapper implements ProjectMana } }, myDisposable, replace); editor.putUserData(SubstitutionShortInfoHandler.CURRENT_CONFIGURATION_KEY, myConfiguration); - if (profile.highlightProblemsInEditor()) { - document.putUserData(STRUCTURAL_SEARCH_ERROR_CALLBACK, () -> { - putClientProperty("JComponent.outline", "error"); - repaint(); - getOKAction().setEnabled(false); - removeMatchHighlights(); - }); - } - else { - final Project project = getProject(); - final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(getDocument()); - if (file != null) { - DaemonCodeAnalyzer.getInstance(project).setHighlightingEnabled(file, false); - } - } + getDocument().putUserData(STRUCTURAL_SEARCH_ERROR_CALLBACK, () -> { + putClientProperty("JComponent.outline", "error"); + repaint(); + getOKAction().setEnabled(false); + removeMatchHighlights(); + }); TextCompletionUtil.installCompletionHint(editor); editor.putUserData(STRUCTURAL_SEARCH_DIALOG, StructuralSearchDialog.this); diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/StructuralSearchHighlightInfoFilter.java b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/StructuralSearchHighlightInfoFilter.java index e5bce9784769..404f1e0e0a97 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/StructuralSearchHighlightInfoFilter.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/StructuralSearchHighlightInfoFilter.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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-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. package com.intellij.structuralsearch.plugin.ui; import com.intellij.codeInsight.daemon.impl.HighlightInfo; @@ -6,6 +6,7 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfoFilter; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; +import com.intellij.openapi.util.registry.Registry; import com.intellij.psi.*; import com.intellij.structuralsearch.PatternContext; import com.intellij.structuralsearch.StructuralSearchProfile; @@ -38,6 +39,9 @@ public class StructuralSearchHighlightInfoFilter implements HighlightInfoFilter if (profile == null) { return true; } + if (!Registry.is("ssr.in.editor.problem.highlighting")) { + return false; + } final PatternContext context = StructuralSearchUtil.findPatternContextByID(contextId, profile); final boolean result = profile.shouldShowProblem(highlightInfo, file, context); if (result) {