don't reparse file if a language is substituted with a dialect of the language (in this case, PushedFilePropertiesUpdater does the job) (IDEA-CR-11333)

This commit is contained in:
Sergey Simonchik
2016-06-08 15:12:54 +03:00
parent 426691f472
commit 36b9ba9501
@@ -59,11 +59,11 @@ public final class LanguageSubstitutors extends LanguageExtension<LanguageSubsti
@NotNull final Language substitutedLang) {
Language prevSubstitutedLang = SUBSTITUTED_LANG_KEY.get(file);
final Language prevLang = ObjectUtils.notNull(prevSubstitutedLang, originalLang);
if (!substitutedLang.equals(prevLang)) {
if (ApplicationManager.getApplication().isDispatchThread() && myReparsingInProgress) {
return; // avoid recursive reparsing
}
if (!haveCommonAncestorLanguage(substitutedLang, prevLang)) {
if (file.replace(SUBSTITUTED_LANG_KEY, prevSubstitutedLang, substitutedLang)) {
if (ApplicationManager.getApplication().isDispatchThread() && myReparsingInProgress) {
return; // avoid recursive reparsing
}
invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
@@ -78,6 +78,22 @@ public final class LanguageSubstitutors extends LanguageExtension<LanguageSubsti
}
}
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;
}
private static void invokeLaterIfNeeded(@NotNull Runnable runnable, @NotNull ModalityState modalityState) {
if (ApplicationManager.getApplication().isDispatchThread()) {
runnable.run();