PsiChangeHandler: don't track ranges forever for events outside pom transactions...
authorpeter <peter@jetbrains.com>
Thu, 21 Apr 2016 19:21:20 +0000 (21:21 +0200)
committerpeter <peter@jetbrains.com>
Thu, 21 Apr 2016 19:38:09 +0000 (21:38 +0200)
java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java
platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PsiChangeHandler.java

index 23ff59689c079e4eac6e0ff23e1f507a30b9818b..70d76c6a1691004add21177691e7a9b463f48ae6 100644 (file)
@@ -120,10 +120,7 @@ import com.intellij.testFramework.*;
 import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
 import com.intellij.ui.HintListener;
 import com.intellij.ui.LightweightHint;
-import com.intellij.util.ArrayUtil;
-import com.intellij.util.ExceptionUtil;
-import com.intellij.util.ReflectionUtil;
-import com.intellij.util.TimeoutUtil;
+import com.intellij.util.*;
 import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.io.storage.HeavyProcessLatch;
 import com.intellij.util.ui.UIUtil;
@@ -2280,5 +2277,27 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase {
       EditorFactory.getInstance().releaseEditor(myEditor);
     }
   }
+
+  public void testFileReload() throws Exception {
+    VirtualFile file = createFile("a.java", "").getVirtualFile();
+    Document document = getDocument(file);
+    assertNotNull(document);
+
+    FileStatusMap fileStatusMap = myDaemonCodeAnalyzer.getFileStatusMap();
+
+    WriteCommandAction.runWriteCommandAction(getProject(), () -> {
+      PlatformTestUtil.tryGcSoftlyReachableObjects();
+      assertNull(PsiDocumentManager.getInstance(getProject()).getCachedPsiFile(document));
+
+      document.insertString(0, "class X { void foo() {}}");
+      assertEquals(TextRange.from(0, document.getTextLength()), fileStatusMap.getFileDirtyScope(document, Pass.UPDATE_ALL));
+
+      FileContentUtilCore.reparseFiles(file);
+      assertEquals(TextRange.from(0, document.getTextLength()), fileStatusMap.getFileDirtyScope(document, Pass.UPDATE_ALL));
+
+      findClass("X").getMethods()[0].delete();
+      assertEquals(TextRange.from(0, document.getTextLength()), fileStatusMap.getFileDirtyScope(document, Pass.UPDATE_ALL));
+    });
+  }
 }
 
index 4f331cb88dbcfcf8d6b9c529f2716cd4b092b026..463af0726872be27375c14b1df41686888c224c8 100644 (file)
@@ -203,8 +203,15 @@ class PsiChangeHandler extends PsiTreeChangeAdapter implements Disposable {
     }
 
     if (!child.isValid()) return;
-    Document document = PsiDocumentManager.getInstance(myProject).getCachedDocument(file);
+
+    PsiDocumentManagerImpl pdm = (PsiDocumentManagerImpl)PsiDocumentManager.getInstance(myProject);
+    Document document = pdm.getCachedDocument(file);
     if (document != null) {
+      if (pdm.getSynchronizer().getTransaction(document) == null) {
+        myFileStatusMap.markAllFilesDirty(child);
+        return;
+      }
+
       List<Pair<PsiElement, Boolean>> toUpdate = changedElements.get(document);
       if (toUpdate == null) {
         toUpdate = new SmartList<>();