diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndex.java b/src/main/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndex.java index a02b42b..be2616f 100644 --- a/src/main/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndex.java +++ b/src/main/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndex.java @@ -45,27 +45,34 @@ public static JBehaveStepsIndex getInstance(Project project) { @NotNull public Collection findStepDefinitions(@NotNull JBehaveStep step) { - Module module = ModuleUtilCore.findModuleForPsiElement(step); - - if (module == null) { - return emptyList(); - } + return CachedValuesManager.getCachedValue(step, (CachedValueProvider>) () -> { + Module module = ModuleUtilCore.findModuleForPsiElement(step); + + if (module == null) { + return new CachedValueProvider.Result<>( + emptyList(), + JBehaveStepDefClassesModificationTracker.getInstance(step.getProject()), + ProjectRootModificationTracker.getInstance(step.getProject())); + } - var definitionsByClass = new HashMap(2); - String stepText = step.getStepText(); + var definitionsByClass = new HashMap(2); + String stepText = step.getStepText(); - for (var javaStepDefinition : loadStepsFor(module)) { - if (javaStepDefinition.supportsStepAndMatches(step, stepText)) { - Integer currentHighestPriority = getPriorityByDefinition(definitionsByClass.get(javaStepDefinition.getClass())); - Integer newPriority = getPriorityByDefinition(javaStepDefinition); + for (var javaStepDefinition : loadStepsFor(module)) { + if (javaStepDefinition.supportsStepAndMatches(step, stepText)) { + Integer currentHighestPriority = getPriorityByDefinition(definitionsByClass.get(javaStepDefinition.getClass())); + Integer newPriority = getPriorityByDefinition(javaStepDefinition); - if (newPriority > currentHighestPriority) { - definitionsByClass.put(javaStepDefinition.getClass(), javaStepDefinition); + if (newPriority > currentHighestPriority) { + definitionsByClass.put(javaStepDefinition.getClass(), javaStepDefinition); + } } } - } - return definitionsByClass.values(); + return new CachedValueProvider.Result<>(definitionsByClass.values(), + JBehaveStepDefClassesModificationTracker.getInstance(step.getProject()), + ProjectRootModificationTracker.getInstance(step.getProject())); + }); } @NotNull