diff --git a/platform/core-api/src/com/intellij/psi/LanguageSubstitutors.java b/platform/core-api/src/com/intellij/psi/LanguageSubstitutors.java index 1dca825fd2da..c3098f46068d 100644 --- a/platform/core-api/src/com/intellij/psi/LanguageSubstitutors.java +++ b/platform/core-api/src/com/intellij/psi/LanguageSubstitutors.java @@ -35,8 +35,7 @@ public final class LanguageSubstitutors extends LanguageExtension SUBSTITUTED_LANG_KEY = Key.create("SUBSTITUTED_LANG_KEY"); - - private boolean myReparsingInProgress; + private static final Key REPARSING_SCHEDULED = Key.create("REPARSING_SCHEDULED"); private LanguageSubstitutors() { super("com.intellij.lang.substitutor"); @@ -55,9 +54,9 @@ public final class LanguageSubstitutors extends LanguageExtension" + substitutedLang.getID()); - myReparsingInProgress = true; - FileContentUtilCore.reparseFiles(file); - myReparsingInProgress = false; + if (file.replace(REPARSING_SCHEDULED, true, null)) { + LOG.info("Reparsing " + file.getPath() + " because of language substitution " + + prevLang.getID() + "->" + substitutedLang.getID()); + FileContentUtilCore.reparseFiles(file); + } } }, ModalityState.defaultModalityState()); } } } - private static boolean haveCommonAncestorLanguage(@NotNull Language lang1, @NotNull Language lang2) { - Language rootLang1 = findRootLanguage(lang1); - Language rootLang2 = findRootLanguage(lang2); - return rootLang1.is(rootLang2); - } - - @NotNull - private static Language findRootLanguage(@NotNull Language lang) { - Language parent = lang.getBaseLanguage(); - while (parent != null) { - lang = parent; - parent = lang.getBaseLanguage(); - } - return lang; + public static void cancelReparsing(@NotNull VirtualFile file) { + REPARSING_SCHEDULED.set(file, null); } } 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 1b2589f7a714..a83b2a670d22 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 @@ -146,6 +146,7 @@ public class FileManagerImpl implements FileManager { } public void forceReload(@NotNull VirtualFile vFile) { + LanguageSubstitutors.cancelReparsing(vFile); if (findCachedViewProvider(vFile) == null) { return; }