From c24c692f80a4e28d8e10cd55a4dd2a8871292210 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 29 Jul 2015 21:09:30 +0200 Subject: [PATCH] PsiToDocumentSynchronizer shouldn't be the first one to load AST e.g. for file-level childrenChanged event AST may be missing, and that's OK --- .../psi/impl/PsiToDocumentSynchronizer.java | 4 ++-- .../openapi/editor/impl/RangeMarkerTest.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/platform/core-impl/src/com/intellij/psi/impl/PsiToDocumentSynchronizer.java b/platform/core-impl/src/com/intellij/psi/impl/PsiToDocumentSynchronizer.java index da0df7026158..ef5398db1f0c 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/PsiToDocumentSynchronizer.java +++ b/platform/core-impl/src/com/intellij/psi/impl/PsiToDocumentSynchronizer.java @@ -72,7 +72,7 @@ public class PsiToDocumentSynchronizer extends PsiTreeChangeAdapter { private void checkPsiModificationAllowed(@NotNull final PsiTreeChangeEvent event) { if (!toProcessPsiEvent()) return; final PsiFile psiFile = event.getFile(); - if (psiFile == null || psiFile.getNode() == null) return; + if (!(psiFile instanceof PsiFileEx) || !((PsiFileEx)psiFile).isContentsLoaded()) return; final Document document = myPsiDocumentManager.getCachedDocument(psiFile); if (document != null && myPsiDocumentManager.isUncommited(document)) { @@ -91,7 +91,7 @@ public class PsiToDocumentSynchronizer extends PsiTreeChangeAdapter { private void doSync(@NotNull final PsiTreeChangeEvent event, boolean force, @NotNull final DocSyncAction syncAction) { if (!toProcessPsiEvent()) return; final PsiFile psiFile = event.getFile(); - if (psiFile == null || psiFile.getNode() == null) return; + if (!(psiFile instanceof PsiFileEx) || !((PsiFileEx)psiFile).isContentsLoaded()) return; final DocumentEx document = getCachedDocument(psiFile, force); if (document == null) return; diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/RangeMarkerTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/RangeMarkerTest.java index 9d1331e000c6..885865143033 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/RangeMarkerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/RangeMarkerTest.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.editor.impl; +import com.intellij.lang.FileASTNode; import com.intellij.openapi.application.Result; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.command.impl.UndoManagerImpl; @@ -59,6 +60,7 @@ public class RangeMarkerTest extends LightPlatformTestCase { private PsiToDocumentSynchronizer synchronizer; private Document document; private PsiFile psiFile; + private FileASTNode fileNode; @Override protected void runTest() throws Throwable { @@ -96,6 +98,16 @@ public class RangeMarkerTest extends LightPlatformTestCase { synchronizer = documentManager.getSynchronizer(); } + @Override + protected void tearDown() throws Exception { + documentManager = null; + synchronizer = null; + psiFile = null; + fileNode = null; + document = null; + super.tearDown(); + } + public void testCreation() throws Exception { RangeMarker marker = createMarker("0123456789", 2, 5); @@ -940,6 +952,7 @@ public class RangeMarkerTest extends LightPlatformTestCase { private RangeMarkerEx createMarker(String text, final int start, final int end) { psiFile = createFile("x.txt", text); + fileNode = psiFile.getNode(); // the node should be loaded, otherwise PsiToDocumentSynchronizer will ignore our commands return createMarker(psiFile, start, end); }