void (@NotNull Editor editor, @NotNull PsiFile file, @NotNull Project project, @NotNull Ref<? super PsiFile> featuresDump) { ProgressManager.getInstance().run(new Task.Modal(project, UsageViewBundle.message( "similar.usages.show.usage.features.action.calculating.usage.features.progress.title"), true) { @Override public void run(@NotNull ProgressIndicator indicator) { final Bag features = new Bag(); Ref<PsiElement> element = new Ref<>(); ApplicationManager.getApplication().runReadAction(() -> { PsiReference referenceAt = file.findReferenceAt(editor.getCaretModel().getOffset()); if (referenceAt == null) return; element.set(referenceAt.getElement()); if (!element.isNull()) { UsageSimilarityFeaturesProvider.EP_NAME.forEachExtensionSafe(provider -> { features.addAll(provider.getFeatures(element.get())); } ); } }); if (element.isNull()) { return; } writeCommandAction(project).compute(() -> { ScratchFileService fileService = ScratchFileService.getInstance(); try { VirtualFile scratchFile = fileService.findFile(RootType.findById("scratches"), getFeaturesFileName(file, element.get(), editor), ScratchFileService.Option.create_new_always); PsiFile psiFile = PsiManager.getInstance(project).findFile(scratchFile); featuresDump.set(psiFile); final Document document = psiFile != null ? PsiDocumentManager.getInstance(project).getDocument(psiFile) : null; if (document != null) { document.insertString(document.getTextLength(), StringUtil.join(features.getBag().object2IntEntrySet().stream().sorted( Map.Entry.comparingByKey()).collect(Collectors.toList()), ",\n")); PsiDocumentManager.getInstance(project).commitDocument(document); psiFile.navigate(true); } } catch (IOException e) { throw new RuntimeException(e); } return true; }); } }); }