From a007ab5ea2241d95ea113e25a38665e206b90ad2 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 21 May 2015 15:26:11 +0300 Subject: [PATCH] ignore changes in workspace.xml during highlighting --- .../src/com/intellij/psi/PsiTreeChangeEvent.java | 10 +++++++--- .../psi/impl/PsiTreeChangeEventImpl.java | 6 +++++- .../psi/impl/file/impl/FileManagerImpl.java | 16 ++++++++++++---- .../daemon/impl/PsiChangeHandler.java | 14 +++++++++++++- .../psi/impl/file/impl/PsiVFSListener.java | 6 ++---- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/platform/core-api/src/com/intellij/psi/PsiTreeChangeEvent.java b/platform/core-api/src/com/intellij/psi/PsiTreeChangeEvent.java index 14bc8d126a8d..b3c3de7d7a66 100644 --- a/platform/core-api/src/com/intellij/psi/PsiTreeChangeEvent.java +++ b/platform/core-api/src/com/intellij/psi/PsiTreeChangeEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,12 @@ public abstract class PsiTreeChangeEvent extends EventObject { @NonNls public static final String PROP_ROOTS = "roots"; @NonNls public static final String PROP_FILE_TYPES = "propFileTypes"; - @NonNls public static final String PROP_UNLOADED_PSI = "propUnloadedPsi"; + + @NonNls + /** + * In the event with this property the {@link #getOldValue()} contains virtual file of the change + */ + public static final String PROP_UNLOADED_PSI = "propUnloadedPsi"; protected PsiElement myParent; protected PsiElement myOldParent; @@ -99,6 +104,5 @@ public abstract class PsiTreeChangeEvent extends EventObject { public PsiFile getFile() { return myFile; } - } diff --git a/platform/core-impl/src/com/intellij/psi/impl/PsiTreeChangeEventImpl.java b/platform/core-impl/src/com/intellij/psi/impl/PsiTreeChangeEventImpl.java index 0805dc95d7c3..5248fce2a32d 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/PsiTreeChangeEventImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/PsiTreeChangeEventImpl.java @@ -127,6 +127,10 @@ public class PsiTreeChangeEventImpl extends PsiTreeChangeEvent{ @NotNull @Override public String toString() { - return "PsiTreeChangeEventImpl{" + myCode + (isGenericChange ? " (generic)" : "") + '}'; + return "PsiTreeChangeEventImpl{" + myCode + + (isGenericChange ? " (generic)" : "") + + (myPropertyName == null ? "" : " ("+myPropertyName+")") + + (myFile == null ? "" : " in file "+myFile.getName()) + +'}'; } } diff --git a/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java b/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java index e3cfa40c7e56..fb94cb4c5157 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java @@ -154,11 +154,19 @@ public class FileManagerImpl implements FileManager { if (parentDir != null) { event.setParent(parentDir); myManager.childrenChanged(event); - } else { - event.setPropertyName(PsiTreeChangeEvent.PROP_UNLOADED_PSI); - myManager.beforePropertyChange(event); - myManager.propertyChanged(event); } + else { + firePropertyChangedForUnloadedPsi(event, vFile); + } + } + + void firePropertyChangedForUnloadedPsi(@NotNull PsiTreeChangeEventImpl event, @NotNull VirtualFile vFile) { + event.setPropertyName(PsiTreeChangeEvent.PROP_UNLOADED_PSI); + event.setOldValue(vFile); + event.setNewValue(vFile); + + myManager.beforePropertyChange(event); + myManager.propertyChanged(event); } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PsiChangeHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PsiChangeHandler.java index b2acbad9c634..c198ead746f4 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PsiChangeHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PsiChangeHandler.java @@ -31,9 +31,11 @@ import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectCoreUtil; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.impl.PsiDocumentManagerBase; import com.intellij.psi.impl.PsiDocumentManagerImpl; @@ -186,6 +188,11 @@ class PsiChangeHandler extends PsiTreeChangeAdapter implements Disposable { public void propertyChanged(@NotNull PsiTreeChangeEvent event) { String propertyName = event.getPropertyName(); if (!propertyName.equals(PsiTreeChangeEvent.PROP_WRITABLE)) { + Object oldValue = event.getOldValue(); + if (oldValue instanceof VirtualFile && ProjectCoreUtil.isProjectOrWorkspaceFile((VirtualFile)oldValue)) { + // ignore workspace.xml + return; + } myFileStatusMap.markAllFilesDirty(event); } } @@ -223,6 +230,11 @@ class PsiChangeHandler extends PsiTreeChangeAdapter implements Disposable { myFileStatusMap.markAllFilesDirty(child); return; } + VirtualFile virtualFile = file.getVirtualFile(); + if (virtualFile != null && ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)) { + // ignore workspace.xml + return; + } int fileLength = file.getTextLength(); if (!file.getViewProvider().isPhysical()) { @@ -248,7 +260,7 @@ class PsiChangeHandler extends PsiTreeChangeAdapter implements Disposable { } @Nullable - private static PsiElement getChangeHighlightingScope(PsiElement element) { + private static PsiElement getChangeHighlightingScope(@NotNull PsiElement element) { DefaultChangeLocalityDetector defaultDetector = null; for (ChangeLocalityDetector detector : Extensions.getExtensions(EP_NAME)) { if (detector instanceof DefaultChangeLocalityDetector) { diff --git a/platform/lang-impl/src/com/intellij/psi/impl/file/impl/PsiVFSListener.java b/platform/lang-impl/src/com/intellij/psi/impl/file/impl/PsiVFSListener.java index 56e175eb2ac4..f32043c2d2c5 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/file/impl/PsiVFSListener.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/file/impl/PsiVFSListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -687,9 +687,7 @@ public class PsiVFSListener extends VirtualFileAdapter { private void handleVfsChangeWithoutPsi(@NotNull VirtualFile vFile) { if (!myReportedUnloadedPsiChange && isInRootModel(vFile)) { PsiTreeChangeEventImpl event = new PsiTreeChangeEventImpl(myManager); - event.setPropertyName(PsiTreeChangeEvent.PROP_UNLOADED_PSI); - myManager.beforePropertyChange(event); - myManager.propertyChanged(event); + myFileManager.firePropertyChangedForUnloadedPsi(event, vFile); myReportedUnloadedPsiChange = true; } }