private static boolean tryToOpenInScratch(@NotNull Project project, @NotNull String request) {
    final String fileName = "fus-event-log.json";
    try {
      final ThrowableComputable<NavigatablePsiElement, Exception> computable = () -> {
        final ScratchFileService fileService = ScratchFileService.getInstance();
        final VirtualFile file =
          fileService.findFile(RootType.findById("scratches"), fileName, ScratchFileService.Option.create_new_always);

        fileService.getScratchesMapping().setMapping(file, Language.findLanguageByID("JSON"));
        final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
        final Document document = psiFile != null ? PsiDocumentManager.getInstance(project).getDocument(psiFile) : null;
        if (document == null) {
          return null;
        }

        document.insertString(document.getTextLength(), request);
        PsiDocumentManager.getInstance(project).commitDocument(document);
        return psiFile;
      };

      final NavigatablePsiElement psiElement = writeCommandAction(project)
        .withName(StatisticsBundle.message("stats.creating.json.for.event.log.upload.results"))
        .withGlobalUndo().shouldRecordActionForActiveDocument(false)
        .withUndoConfirmationPolicy(UndoConfirmationPolicy.REQUEST_CONFIRMATION)
        .compute(computable);

      if (psiElement != null) {
        AppUIExecutor.onUiThread().expireWith(project).submit(() -> psiElement.navigate(true));
        return true;
      }
    }
    catch (Exception e) {
      // ignore
    }
    return false;
  }
private static boolean tryToOpenInScratch(@NotNull Project project, @NotNull String request)