From 93a685b07e0cef6df84b8e8579e41b79a4522fa8 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Wed, 12 Aug 2020 03:29:51 +0300 Subject: [PATCH] git: enable progress output foldings for vcs console only GitOrigin-RevId: b2984d2590868a77d33d293fba9cc737af2faf30 --- .../intellij/execution/ConsoleFolding.java | 5 ++++ .../execution/impl/ConsoleViewImpl.java | 24 +++++++++++++------ .../src/git4idea/console/GitConsoleFolding.kt | 6 +++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/platform/execution-impl/src/com/intellij/execution/ConsoleFolding.java b/platform/execution-impl/src/com/intellij/execution/ConsoleFolding.java index 1c200d5971fc..9d909bc12013 100644 --- a/platform/execution-impl/src/com/intellij/execution/ConsoleFolding.java +++ b/platform/execution-impl/src/com/intellij/execution/ConsoleFolding.java @@ -1,6 +1,7 @@ // 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. package com.intellij.execution; +import com.intellij.execution.ui.ConsoleView; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; @@ -41,6 +42,10 @@ public abstract class ConsoleFolding { return getPlaceholderText(lines); } + public boolean isEnabledForConsole(@NotNull ConsoleView consoleView) { + return true; + } + /** * @param line to check if should be folded * @return {@code true} if line should be folded, {@code false} if not diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java index 5462ae1aaa01..a497dccb91c1 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java @@ -1086,11 +1086,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo existingRegion = regions[0]; } } - String lastFoldingFqn = USED_FOLDING_FQN_KEY.get(existingRegion); - ConsoleFolding lastFolding = lastFoldingFqn != null - ? ConsoleFolding.EP_NAME.getByKey(lastFoldingFqn, ConsoleViewImpl.class, - consoleFolding -> consoleFolding.getClass().getName()) - : null; + ConsoleFolding lastFolding = findFoldingByRegion(existingRegion); int lastStartLine = Integer.MAX_VALUE; if (lastFolding != null) { int offset = existingRegion.getStartOffset(); @@ -1150,10 +1146,24 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo FoldRegion region = placeholder == null ? null : myEditor.getFoldingModel().addFoldRegion(oStart, oEnd, placeholder); if (region != null) { region.setExpanded(isExpanded); - region.putUserData(USED_FOLDING_FQN_KEY, folding.getClass().getName()); + region.putUserData(USED_FOLDING_FQN_KEY, getFoldingFqn(folding)); } } + @Nullable + @Contract("null -> null") + private ConsoleFolding findFoldingByRegion(@Nullable FoldRegion region) { + String lastFoldingFqn = USED_FOLDING_FQN_KEY.get(region); + if (lastFoldingFqn == null) return null; + ConsoleFolding consoleFolding = ConsoleFolding.EP_NAME.getByKey(lastFoldingFqn, ConsoleViewImpl.class, ConsoleViewImpl::getFoldingFqn); + return consoleFolding != null && consoleFolding.isEnabledForConsole(this) ? consoleFolding : null; + } + + @NotNull + private static String getFoldingFqn(@NotNull ConsoleFolding consoleFolding) { + return consoleFolding.getClass().getName(); + } + @Nullable private ConsoleFolding foldingForLine(int line, @NotNull Document document) { String lineText = EditorHyperlinkSupport.getLineText(document, line, false); @@ -1162,7 +1172,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo } for (ConsoleFolding extension : ConsoleFolding.EP_NAME.getExtensions()) { - if (extension.shouldFoldLine(myProject, lineText)) { + if (extension.isEnabledForConsole(this) && extension.shouldFoldLine(myProject, lineText)) { return extension; } } diff --git a/plugins/git4idea/src/git4idea/console/GitConsoleFolding.kt b/plugins/git4idea/src/git4idea/console/GitConsoleFolding.kt index 57c94d985a32..f9093aa0470e 100644 --- a/plugins/git4idea/src/git4idea/console/GitConsoleFolding.kt +++ b/plugins/git4idea/src/git4idea/console/GitConsoleFolding.kt @@ -2,11 +2,13 @@ package git4idea.console import com.intellij.execution.ConsoleFolding +import com.intellij.execution.ui.ConsoleView import com.intellij.openapi.project.Project import com.intellij.openapi.util.TextRange import com.intellij.openapi.util.text.StringUtil import com.intellij.vcs.console.VcsConsoleFolding import com.intellij.vcs.console.VcsConsoleFolding.Placeholder +import com.intellij.vcs.console.VcsConsoleView import git4idea.commands.GitImplBase import java.util.regex.Matcher import java.util.regex.Pattern @@ -50,4 +52,8 @@ class GitProgressOutputConsoleFolding : ConsoleFolding() { override fun shouldFoldLine(project: Project, line: String): Boolean { return GitImplBase.looksLikeProgress(line) } + + override fun isEnabledForConsole(consoleView: ConsoleView): Boolean { + return consoleView is VcsConsoleView + } } \ No newline at end of file -- 2.23.3