git: enable progress output foldings for vcs console only
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Wed, 12 Aug 2020 00:29:51 +0000 (03:29 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Wed, 12 Aug 2020 19:05:10 +0000 (19:05 +0000)
GitOrigin-RevId: b2984d2590868a77d33d293fba9cc737af2faf30

platform/execution-impl/src/com/intellij/execution/ConsoleFolding.java
platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java
plugins/git4idea/src/git4idea/console/GitConsoleFolding.kt

index 1c200d5971fc97ddb4a36c67d42ad8405ac433fe..9d909bc120133c8082826f00e681caf255d39adc 100644 (file)
@@ -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
index 5462ae1aaa017a19c1febfb4da767242360667d8..a497dccb91c16b081f22fef07100ccc61ac5365a 100644 (file)
@@ -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,11 +1146,25 @@ 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);
     if (line == 0 && myCommandLineFolding.shouldFoldLine(myProject, lineText)) {
@@ -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;
       }
     }
index 57c94d985a3295de56611d39d58bb3cc7bc13342..f9093aa0470ee8d9dec5fca29ce43f0c3c09c044 100644 (file)
@@ -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