From df83fdedb535e8b7c2f31d78e36e964ccf10dfdd Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Mon, 26 Mar 2018 17:57:18 +0300 Subject: [PATCH] debug logging for undo/redo operations (for IDEA-156074) --- .../command/impl/UndoRedoStacksHolder.java | 26 ++++++++++++++++--- .../openapi/command/impl/UndoableGroup.java | 18 ++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedoStacksHolder.java b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedoStacksHolder.java index 58ccce826b36..ca087dda55d1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedoStacksHolder.java +++ b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoRedoStacksHolder.java @@ -1,10 +1,9 @@ -/* - * Copyright 2000-2017 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-2018 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.openapi.command.impl; import com.intellij.openapi.command.undo.DocumentReference; import com.intellij.openapi.command.undo.DocumentReferenceManager; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.UserDataHolder; @@ -18,6 +17,8 @@ import org.jetbrains.annotations.TestOnly; import java.util.*; class UndoRedoStacksHolder { + private static final Logger LOG = Logger.getInstance(UndoRedoStacksHolder.class); + private final Key> STACK_IN_DOCUMENT_KEY = Key.create("STACK_IN_DOCUMENT_KEY"); private final boolean myUndo; @@ -131,7 +132,14 @@ class UndoRedoStacksHolder { return result; } + private String getStacksDescription() { + return myUndo ? "undo stacks" : "redo stacks"; + } + void addToStacks(@NotNull UndoableGroup group) { + if (LOG.isDebugEnabled()) { + LOG.debug("Adding to " + getStacksDescription() + ": " + group.dumpState()); + } for (LinkedList each : getAffectedStacks(group)) { doAddToStack(each, group, each == myGlobalStack ? UndoManagerImpl.getGlobalUndoLimit() : UndoManagerImpl.getDocumentUndoLimit()); } @@ -147,6 +155,9 @@ class UndoRedoStacksHolder { } void removeFromStacks(@NotNull UndoableGroup group) { + if (LOG.isDebugEnabled()) { + LOG.debug("Removing from " + getStacksDescription() + ": " + group.dumpState()); + } for (LinkedList each : getAffectedStacks(group)) { assert each.getLast() == group; each.removeLast(); @@ -172,6 +183,9 @@ class UndoRedoStacksHolder { for (int i = stack.size() - 1; i >= 0; i--) { UndoableGroup group = stack.get(i); if (!group.isTemporary()) break; + if (LOG.isDebugEnabled()) { + LOG.debug("Converting to permanent: " + group); + } group.makePermanent(); } } @@ -190,6 +204,9 @@ class UndoRedoStacksHolder { } private void clearStacksFrom(@NotNull UndoableGroup from) { + if (LOG.isDebugEnabled()) { + LOG.debug("Clearing " + getStacksDescription() + " from " + from.dumpState()); + } for (LinkedList each : getAffectedStacks(from)) { int pos = each.indexOf(from); if (pos == -1) continue; @@ -260,6 +277,9 @@ class UndoRedoStacksHolder { } void invalidateActionsFor(@NotNull DocumentReference ref) { + if (LOG.isDebugEnabled()) { + LOG.debug("Invalidating actions in " + getStacksDescription() + " for " + ref); + } for (List eachStack : getAffectedStacks(true, Collections.singleton(ref))) { for (UndoableGroup eachGroup : eachStack) { eachGroup.invalidateActionsFor(ref); diff --git a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoableGroup.java b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoableGroup.java index 866fad20060e..316c563386fd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoableGroup.java +++ b/platform/platform-impl/src/com/intellij/openapi/command/impl/UndoableGroup.java @@ -1,9 +1,8 @@ -/* - * Copyright 2000-2017 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-2018 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.openapi.command.impl; import com.intellij.CommonBundle; +import com.intellij.diagnostic.Dumpable; import com.intellij.history.LocalHistory; import com.intellij.history.LocalHistoryAction; import com.intellij.openapi.application.ApplicationManager; @@ -24,7 +23,7 @@ import org.jetbrains.annotations.Nullable; import java.util.*; -class UndoableGroup { +class UndoableGroup implements Dumpable { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.command.impl.UndoableGroup"); private final String myCommandName; @@ -101,6 +100,9 @@ class UndoableGroup { } private void undoOrRedo(boolean isUndo) { + if (LOG.isDebugEnabled()) { + LOG.debug("Performing " + (isUndo ? "undo" : "redo") + " for " + dumpState()); + } LocalHistoryAction action; if (myProject != null && isGlobal()) { String actionName = CommonBundle.message(isUndo ? "local.vcs.action.name.undo.command" : "local.vcs.action.name.redo.command", myCommandName); @@ -160,6 +162,14 @@ class UndoableGroup { if (exception[0] != null) reportUndoProblem(exception[0], isUndo); } + @NotNull + @Override + public String dumpState() { + return "UndoableGroup[project=" + myProject + ", name=" + myCommandName + ", global=" + myGlobal + ", transparent=" + myTransparent + + ", stamp=" + myCommandTimestamp + ", policy=" + myConfirmationPolicy + ", temporary=" + myTemporary + ", valid=" + myValid + + ", actions=" + myActions + "]"; + } + private static DocumentEx getDocumentToSetBulkMode(UndoableAction action) { // We use bulk update only for EditorChangeAction, cause we know that it only changes document. Other actions can do things // not allowed in bulk update.