From 974fafdd67f6686c1c4c3e054b9f28cae2baa761 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 28 Dec 2011 17:05:01 +0100 Subject: [PATCH] EA-32053, EA-31726 diagnostics for lookup start invalidation when selecting an item by typing a char --- .../codeInsight/lookup/impl/LookupImpl.java | 10 ++++++++-- .../lookup/impl/LookupTypedHandler.java | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index f99fa1eb5e95..591de6083392 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -845,16 +845,22 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable } public void performGuardedChange(Runnable change) { + performGuardedChange(change, null); + } + + public void performGuardedChange(Runnable change, @Nullable final String debug) { checkValid(); assert myLookupStartMarker.isValid(); assert !myChangeGuard; myChangeGuard = true; - Document document = myEditor.getDocument(); + final Document document = myEditor.getDocument(); RangeMarkerSpy spy = new RangeMarkerSpy(myLookupStartMarker) { @Override protected void invalidated(DocumentEvent e) { - LOG.error("Lookup start marker invalidated, say thanks to the "+ e); + LOG.error("Lookup start marker invalidated, say thanks to the " + e + + ", doc=" + document + + ", debug=" + debug); } }; document.addDocumentListener(spy); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java index fea1130d9a8f..ae06c5012d1b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java @@ -36,15 +36,21 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorModificationUtil; import com.intellij.openapi.editor.SelectionModel; +import com.intellij.openapi.editor.event.DocumentAdapter; +import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.editor.ex.ScrollingModelEx; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Pair; import com.intellij.psi.PsiFile; +import com.intellij.psi.impl.DebugUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; public class LookupTypedHandler extends TypedHandlerDelegate { private static boolean inside = false; @@ -165,6 +171,14 @@ public class LookupTypedHandler extends TypedHandlerDelegate { final ScrollingModelEx scrollingModel = (ScrollingModelEx)editor.getScrollingModel(); scrollingModel.accumulateViewportChanges(); try { + final List> events = new ArrayList>(); + final DocumentAdapter listener = new DocumentAdapter() { + @Override + public void documentChanged(DocumentEvent e) { + events.add(Pair.create(e, DebugUtil.currentStackTrace())); + } + }; + editor.getDocument().addDocumentListener(listener); if (smartUndo) { CommandProcessor.getInstance().executeCommand(editor.getProject(), new Runnable() { @Override @@ -173,6 +187,7 @@ public class LookupTypedHandler extends TypedHandlerDelegate { } }, null, "Just insert the completion char"); } + editor.getDocument().removeDocumentListener(listener); CommandProcessor.getInstance().executeCommand(editor.getProject(), new Runnable() { @Override @@ -180,7 +195,7 @@ public class LookupTypedHandler extends TypedHandlerDelegate { if (smartUndo) { AccessToken token = WriteAction.start(); try { - lookup.performGuardedChange(restore); + lookup.performGuardedChange(restore, events.toString()); } finally { token.finish();