diff --git a/platform/core-api/src/com/intellij/psi/LanguageSubstitutors.java b/platform/core-api/src/com/intellij/psi/LanguageSubstitutors.java index c3098f46068d..6734be1952b8 100644 --- a/platform/core-api/src/com/intellij/psi/LanguageSubstitutors.java +++ b/platform/core-api/src/com/intellij/psi/LanguageSubstitutors.java @@ -34,7 +34,7 @@ import org.jetbrains.annotations.NotNull; public final class LanguageSubstitutors extends LanguageExtension { public static final LanguageSubstitutors INSTANCE = new LanguageSubstitutors(); private static final Logger LOG = Logger.getInstance(LanguageSubstitutors.class); - private static final Key SUBSTITUTED_LANG_KEY = Key.create("SUBSTITUTED_LANG_KEY"); + private static final Key> PROJECT_KEY_FOR_SUBSTITUTED_LANG_KEY = Key.create("PROJECT_KEY_FOR_SUBSTITUTED_LANG_KEY"); private static final Key REPARSING_SCHEDULED = Key.create("REPARSING_SCHEDULED"); private LanguageSubstitutors() { @@ -46,26 +46,27 @@ public final class LanguageSubstitutors extends LanguageExtension projectKey = getOrCreateProjectKey(project); + Language prevSubstitutedLang = projectKey.get(file); final Language prevLang = ObjectUtils.notNull(prevSubstitutedLang, originalLang); if (!prevLang.is(substitutedLang)) { - if (file.replace(SUBSTITUTED_LANG_KEY, prevSubstitutedLang, substitutedLang)) { + if (file.replace(projectKey, prevSubstitutedLang, substitutedLang)) { if (prevSubstitutedLang == null) { return; // no need to reparse for the first language substitution } @@ -87,6 +88,21 @@ public final class LanguageSubstitutors extends LanguageExtension getOrCreateProjectKey(@NotNull Project project) { + Key key = PROJECT_KEY_FOR_SUBSTITUTED_LANG_KEY.get(project); + if (key == null) { + synchronized (PROJECT_KEY_FOR_SUBSTITUTED_LANG_KEY) { + key = PROJECT_KEY_FOR_SUBSTITUTED_LANG_KEY.get(project); + if (key == null) { + key = new Key("Substituted lang key for " + project.getName()); + PROJECT_KEY_FOR_SUBSTITUTED_LANG_KEY.set(project, key); + } + } + } + return key; + } + public static void cancelReparsing(@NotNull VirtualFile file) { REPARSING_SCHEDULED.set(file, null); }