From fedf5281274719bf18b05668c16feab2eee74c96 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 27 Sep 2013 23:44:40 -0700 Subject: [PATCH] Cache files in the provider This is required when, for example, very many exceptions are thrown in tests, and the console goes crazy calling JetExceptionFilter --- .../project/PluginJetFilesProvider.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/idea/src/org/jetbrains/jet/plugin/project/PluginJetFilesProvider.java b/idea/src/org/jetbrains/jet/plugin/project/PluginJetFilesProvider.java index 00c99f027d4..f40dedc1d19 100644 --- a/idea/src/org/jetbrains/jet/plugin/project/PluginJetFilesProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/project/PluginJetFilesProvider.java @@ -33,6 +33,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.psi.search.FileTypeIndex; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.util.*; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -49,8 +50,23 @@ import java.util.Set; public class PluginJetFilesProvider extends JetFilesProvider { private final Project project; + private final ParameterizedCachedValue, GlobalSearchScope> cache; + public PluginJetFilesProvider(Project project) { this.project = project; + this.cache = CachedValuesManager.getManager(project).createParameterizedCachedValue( + new ParameterizedCachedValueProvider, GlobalSearchScope>() { + @Nullable + @Override + public CachedValueProvider.Result> compute(GlobalSearchScope param) { + return new CachedValueProvider.Result>( + computeAllInScope(param), + PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT + ); + } + }, + false + ); } public static final Function> WHOLE_PROJECT_DECLARATION_PROVIDER = new Function>() { @@ -105,6 +121,10 @@ public class PluginJetFilesProvider extends JetFilesProvider { @Override public Collection allInScope(@NotNull GlobalSearchScope scope) { + return cache.getValue(scope); + } + + private Collection computeAllInScope(GlobalSearchScope scope) { final PsiManager manager = PsiManager.getInstance(project); Collection jetFiles = ContainerUtil.map(