more diagnostics for invalidated tail offset during completion (EA-90945 - ISE: Offse...
authorpeter <peter@jetbrains.com>
Fri, 4 Nov 2016 14:48:17 +0000 (15:48 +0100)
committerpeter <peter@jetbrains.com>
Fri, 4 Nov 2016 15:01:30 +0000 (16:01 +0100)
platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionAssertions.java

index 1cf3556092daf6fb2061d8b16b52e2f230ed345a..7793765e3a541f7bf14ee709b5f084889e75efe0 100644 (file)
@@ -18,12 +18,13 @@ package com.intellij.codeInsight.completion;
 import com.intellij.codeInsight.lookup.Lookup;
 import com.intellij.codeInsight.lookup.LookupElement;
 import com.intellij.diagnostic.LogEventException;
-import com.intellij.openapi.diagnostic.Attachment;
 import com.intellij.injected.editor.DocumentWindow;
 import com.intellij.injected.editor.EditorWindow;
 import com.intellij.lang.FileASTNode;
 import com.intellij.lang.injection.InjectedLanguageManager;
 import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.diagnostic.Attachment;
+import com.intellij.openapi.diagnostic.ExceptionWithAttachments;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
@@ -37,6 +38,7 @@ import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiFile;
 import com.intellij.psi.impl.DebugUtil;
 import com.intellij.psi.util.PsiUtilCore;
+import org.jetbrains.annotations.NotNull;
 
 import java.util.List;
 
@@ -219,6 +221,10 @@ class CompletionAssertions {
 
     @Override
     public int getTailOffset() {
+      if (!getOffsetMap().containsOffset(TAIL_OFFSET) && invalidateTrace != null) {
+        throw new TailInvalidException(invalidateTrace);
+      }
+
       int offset = super.getTailOffset();
       if (tailWatcher.getStartOffset() != tailWatcher.getEndOffset() && offset > 0) {
         watchTail(offset);
@@ -227,4 +233,19 @@ class CompletionAssertions {
       return offset;
     }
   }
+
+  private static class TailInvalidException extends IllegalStateException implements ExceptionWithAttachments {
+    private final String myInvalidationTrace;
+
+    TailInvalidException(@NotNull String invalidationTrace) {
+      super("Tail offset invalid");
+      myInvalidationTrace = invalidationTrace;
+    }
+
+    @NotNull
+    @Override
+    public Attachment[] getAttachments() {
+      return new Attachment[]{new Attachment("invalidated.trace", myInvalidationTrace)};
+    }
+  }
 }