@Override
  public final void expand(@NotNull String key, @NotNull CustomTemplateCallback callback) {
    ZenCodingGenerator defaultGenerator = findApplicableDefaultGenerator(callback, false);
    Editor editor = callback.getEditor();
    if (defaultGenerator == null) {
      LOG.error("Cannot find defaultGenerator for key `" + key + "` at " + editor.getCaretModel().getOffset() + " offset",
                CoreAttachmentFactory.createAttachment(editor.getDocument()));
      return;
    }
    PsiFile file = callback.getFile();
    CaretModel caretModel = editor.getCaretModel();
    Project project = callback.getProject();
    Caret startCaret = caretModel.getCurrentCaret();

    ReadAction
      .nonBlocking(() -> {
        Ref<CollectCustomTemplateCallback> result = Ref.create();
        runForCaret(startCaret, editor, () -> {
          try {
            CollectCustomTemplateCallback collectCallback = new CollectCustomTemplateCallback(editor, file);
            expand(key, collectCallback, defaultGenerator, Collections.emptyList(), true, Registry.intValue("emmet.segments.limit"));
            result.set(collectCallback);
          }
          catch (EmmetException e) {
            CommonRefactoringUtil.showErrorHint(project, editor, e.getMessage(), XmlBundle.message("emmet.error"), "");
          }
        });

        return result.get();
      })
      .finishOnUiThread(ModalityState.current(), (collectCallback) -> {
        if (collectCallback == null) return;

        TemplateImpl template = collectCallback.getGeneratedTemplate();
        if (template == null) return;

        writeActionForCaret(startCaret, editor, file, () -> {
          //original callback
          callback.deleteTemplateKey(key);
          callback.startTemplate(template, null, null);
          PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
        });
      })
      .expireWhen(() -> editor.isDisposed() || !file.isValid() || !startCaret.isValid())
      .submit(EMMET_EXECUTOR);
  }
@Override
  public final void expand(@NotNull String key, @NotNull CustomTemplateCallback callback)