@Internal
  public static @Nullable PsiElement getElementFromLookup(
    @NotNull Project project,
    @NotNull Editor editor,
    @Nullable PsiFile file,
    @NotNull LookupElement item
  ) {
    int offset = editor.getCaretModel().getOffset();
    if (offset > 0 && offset == editor.getDocument().getTextLength()) offset--;
    PsiReference ref = TargetElementUtil.findReference(editor, offset);
    PsiElement contextElement = file == null ? null : ObjectUtils.coalesce(file.findElementAt(offset), file);
    PsiElement targetElement = ref != null ? ref.getElement() : contextElement;
    if (targetElement != null) {
      PsiUtilCore.ensureValid(targetElement);
    }

    DocumentationProvider documentationProvider = getProviderFromElement(file);
    PsiManager psiManager = PsiManager.getInstance(project);
    PsiElement fromProvider = targetElement == null ? null :
                              documentationProvider.getDocumentationElementForLookupItem(psiManager, item.getObject(), targetElement);
    if (fromProvider == null) {
      return CompletionUtil.getTargetElement(item);
    }
    storeIsFromLookup(fromProvider, true);
    return fromProvider;
  }
@Internal
  public static @Nullable PsiElement getElementFromLookup(
    @NotNull Project project,
    @NotNull Editor editor,
    @Nullable PsiFile file,
    @NotNull LookupElement item
  )