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
This commit is contained in:
peter
2015-07-29 21:13:03 +02:00
parent 8f2f2bda65
commit c24c692f80
2 changed files with 15 additions and 2 deletions
@@ -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;
@@ -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);
}