diff --git a/platform/core-impl/src/com/intellij/psi/impl/PsiModificationTrackerImpl.java b/platform/core-impl/src/com/intellij/psi/impl/PsiModificationTrackerImpl.java index 80062cbd9a9c..bdf77b60364c 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/PsiModificationTrackerImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/PsiModificationTrackerImpl.java @@ -31,12 +31,14 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.PsiModificationTracker; import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.containers.ConcurrentFactoryMap; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.MessageBus; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Map; +import java.util.Set; import static com.intellij.psi.impl.PsiTreeChangeEventImpl.PsiEventType.CHILD_MOVED; import static com.intellij.psi.impl.PsiTreeChangeEventImpl.PsiEventType.PROPERTY_CHANGED; @@ -124,16 +126,18 @@ public class PsiModificationTrackerImpl implements PsiModificationTracker, PsiTr protected void incLanguageTrackers(@NotNull PsiTreeChangeEventImpl event) { if (!ourEnableLanguageTracker.asBoolean()) return; incLanguageModificationCount(Language.ANY); - for (PsiElement o : new PsiElement[]{ + PsiElement[] elements = { event.getFile(), event.getParent(), event.getOldParent(), event.getNewParent(), - event.getElement(), event.getChild(), event.getOldChild(), event.getNewChild() - }) { + event.getElement(), event.getChild(), event.getOldChild(), event.getNewChild()}; + Set languages = ContainerUtil.newHashSet(elements.length); + languages.add(Language.ANY); + for (PsiElement o : elements) { PsiFile file = o instanceof PsiFile ? (PsiFile)o : null; if (file == null) { try { IElementType type = PsiUtilCore.getElementType(o); Language language = type != null ? type.getLanguage() : o != null ? o.getLanguage() : null; - incLanguageModificationCount(language); + ContainerUtil.addIfNotNull(languages, language); } catch (PsiInvalidElementAccessException e) { PsiDocumentManagerBase.LOG.warn(e); @@ -141,10 +145,13 @@ public class PsiModificationTrackerImpl implements PsiModificationTracker, PsiTr } else { for (Language language : file.getViewProvider().getLanguages()) { - incLanguageModificationCount(language); + ContainerUtil.addIfNotNull(languages, language); } } } + for (Language language : languages) { + incLanguageModificationCount(language); + } } @Override diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index d5945fbe90e1..3ae906195a47 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -527,7 +527,7 @@ psi.modification.tracker.code-block=false psi.modification.tracker.code-block.description=Controls out-of-code-block PSI modification tracker optimization psi.modification.tracker.java-structure=false psi.modification.tracker.java-structure.description=Controls java-structure PSI modification tracker optimization -psi.modification.tracker.per-language=false +psi.modification.tracker.per-language=true psi.modification.tracker.per-language.description=Controls per-language PSI modification tracker optimization ide.suggest.file.when.creating.filename.like.directory=true