debug logging for undo/redo operations (for IDEA-156074)

This commit is contained in:
Dmitry Batrak
2018-03-26 18:00:37 +03:00
parent fbce4f4142
commit df83fdedb5
2 changed files with 37 additions and 7 deletions
@@ -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<LinkedList<UndoableGroup>> 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<UndoableGroup> 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<UndoableGroup> 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<UndoableGroup> 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<UndoableGroup> eachStack : getAffectedStacks(true, Collections.singleton(ref))) {
for (UndoableGroup eachGroup : eachStack) {
eachGroup.invalidateActionsFor(ref);
@@ -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.