List<RunnerAndConfigurationSettings> (@NotNull PsiFile psiFile, boolean resetCache) { if (resetCache) { psiFile.putUserData(CURRENT_FILE_RUN_CONFIGS_KEY, null); } // Without this cache, an expensive method `ConfigurationContext.getConfigurationsFromContext()` is called too often for 2 reasons: // - there are several buttons on the toolbar (Run, Debug, Profile, etc.), each runs ExecutorAction.update() during each action update session // - the state of the buttons on the toolbar is updated several times a second, even if no files are being edited // The following few lines do pretty much the same as CachedValuesManager.getCachedValue(), but it's implemented without calling that // method because it appeared to be too hard to satisfy both IdempotenceChecker.checkEquivalence() and CachedValueStabilityChecker.checkProvidersEquivalent(). // The reason is that RunnerAndConfigurationSettings class doesn't implement equals(), and that CachedValueProvider would need to capture // ConfigurationContext, which doesn't implement equals() either. // Effectively, we need only one boolean value: whether the action is enabled or not, so it shouldn't be a problem that // RunnerAndConfigurationSettings and ConfigurationContext don't implement equals() and this code doesn't pass CachedValuesManager checks. long psiModCount = PsiModificationTracker.getInstance(psiFile.getProject()).getModificationCount(); RunCurrentFileInfo cache = psiFile.getUserData(CURRENT_FILE_RUN_CONFIGS_KEY); if (cache == null || cache.myPsiModCount != psiModCount) { // The 'Run current file' feature doesn't depend on the caret position in the file, that's why ConfigurationContext is created like this. ConfigurationContext configurationContext = new ConfigurationContext(psiFile); // The 'Run current file' feature doesn't reuse existing run configurations (by design). List<ConfigurationFromContext> configurationsFromContext = configurationContext.createConfigurationsFromContext(); List<RunnerAndConfigurationSettings> runConfigs = configurationsFromContext != null ? ContainerUtil.map(configurationsFromContext, ConfigurationFromContext::getConfigurationSettings) : emptyList(); VirtualFile vFile = psiFile.getVirtualFile(); String filePath = vFile != null ? vFile.getPath() : null; for (RunnerAndConfigurationSettings config : runConfigs) { ((RunnerAndConfigurationSettingsImpl)config).setFilePathIfRunningCurrentFile(filePath); } cache = new RunCurrentFileInfo(psiModCount, runConfigs); psiFile.putUserData(CURRENT_FILE_RUN_CONFIGS_KEY, cache); } return cache.myRunConfigs; }