@Override
  public void handleInsert(@NotNull final InsertionContext context, @NotNull LookupElement item) {
    if (TemplateManager.getInstance(context.getProject()).getActiveTemplate(context.getEditor()) != null) {
      return; // Don't brake the template.
    }
    Object object = item.getObject();
    if (!(object instanceof MavenRepositoryArtifactInfo completionItem)) {
      return;
    }
    PsiFile contextFile = context.getFile();
    if (!(contextFile instanceof XmlFile)) return;
    Project project = context.getProject();
    MavenDomProjectModel model = MavenDomUtil.getMavenDomModel(contextFile, MavenDomProjectModel.class);
    if (model == null) {
      return;
    }
    final Map<DependencyConflictId, MavenDomDependency>
      managedDependencies = GenerateManagedDependencyAction.collectManagingDependencies(model);
    PsiElement element = contextFile.findElementAt(context.getStartOffset());
    if (!(element instanceof XmlText)) {
      element = PsiTreeUtil.getParentOfType(element, XmlText.class);
      if (element == null) {
        return;
      }
    }
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    MavenDomDependency dependency =
      GenerateDependencyAction.createDependency(model, context.getEditor(), managedDependencies, Collections.singletonList(completionItem));

    element.delete();
    if (dependency != null && dependency.getXmlTag() != null) {
      context.getEditor().getCaretModel().moveToOffset(dependency.getXmlTag().getTextOffset());
    }
    context.commitDocument();

    logMavenDependencyInsertion(context, item, completionItem);
  }
@Override
  public void handleInsert(@NotNull final InsertionContext context, @NotNull LookupElement item)