Don't force out of block modification after exception in analyze, use special dependency

This commit is contained in:
Nikolay Krasko
2013-10-02 19:49:31 +04:00
parent 27ae5d0d64
commit 3fa2b990a6
4 changed files with 21 additions and 11 deletions
@@ -62,7 +62,8 @@ class JSDeclarationsCacheProvider extends DeclarationsCacheProvider {
return Result.<KotlinDeclarationsCache>create(
new KotlinDeclarationsCacheImpl(analyzeExhaust),
PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT
PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT,
KotlinCacheManager.getInstance(project).getDeclarationsTracker()
);
}
}
@@ -76,7 +76,8 @@ class JvmDeclarationsCacheProvider extends DeclarationsCacheProvider {
return Result.<KotlinDeclarationsCache>create(
new KotlinDeclarationsCacheImpl(analyzeExhaust),
PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT
PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT,
KotlinCacheManager.getInstance(project).getDeclarationsTracker()
);
}
}
@@ -20,6 +20,8 @@ import com.google.common.collect.Maps;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.DefaultModificationTracker;
import com.intellij.openapi.util.ModificationTracker;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.project.TargetPlatform;
@@ -32,6 +34,8 @@ public class KotlinCacheManager {
private final Map<TargetPlatform, DeclarationsCacheProvider> cacheProviders = Maps.newHashMap();
private final DefaultModificationTracker kotlinDeclarationsTracker = new DefaultModificationTracker();
public KotlinCacheManager(@NotNull Project project) {
cacheProviders.put(TargetPlatform.JVM, new JvmDeclarationsCacheProvider(project));
cacheProviders.put(TargetPlatform.JS, new JSDeclarationsCacheProvider(project));
@@ -79,4 +83,12 @@ public class KotlinCacheManager {
return provider;
}
public void invalidateCache() {
kotlinDeclarationsTracker.incModificationCount();
}
public ModificationTracker getDeclarationsTracker() {
return kotlinDeclarationsTracker;
}
}
@@ -25,8 +25,6 @@ import com.intellij.openapi.roots.libraries.LibraryUtil;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.impl.PsiModificationTrackerImpl;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.CachedValue;
import com.intellij.psi.util.CachedValueProvider;
@@ -109,13 +107,7 @@ public final class AnalyzerFacadeWithCache {
private static AnalyzeExhaust emptyExhaustWithDiagnosticOnFile(JetFile file, Throwable e) {
BindingTraceContext bindingTraceContext = new BindingTraceContext();
bindingTraceContext.report(Errors.EXCEPTION_WHILE_ANALYZING.on(file, e));
AnalyzeExhaust analyzeExhaust = AnalyzeExhaust.error(bindingTraceContext.getBindingContext(), e);
// Force invalidating of headers cache - temp decision for monitoring rewrite slice bug
PsiModificationTracker tracker = PsiManager.getInstance(file.getProject()).getModificationTracker();
((PsiModificationTrackerImpl) tracker).incOutOfCodeBlockModificationCounter();
return analyzeExhaust;
return AnalyzeExhaust.error(bindingTraceContext.getBindingContext(), e);
}
private static final SLRUCache<JetFile, CachedValue<CancelableResolveSession>> PER_FILE_SESSION_CACHE = new SLRUCache<JetFile, CachedValue<CancelableResolveSession>>(2, 3) {
@@ -176,6 +168,10 @@ public final class AnalyzerFacadeWithCache {
}
catch (Throwable e) {
handleError(e);
// Exception during body resolve analyze can harm internal caches in declarations cache
KotlinCacheManager.getInstance(file.getProject()).invalidateCache();
return emptyExhaustWithDiagnosticOnFile(file, e);
}
}