private @Nullable PsiElement findTargetElementFromContext(@NotNull Editor editor, int offset, @Nullable PsiFile file) {
    if (LookupManager.getInstance(myProject).getActiveLookup() != null) {
      try {
        return assertSameProject(getElementFromLookup(editor, file));
      }
      catch (IndexNotReadyException e) {
        return null;
      }
    }
    var elementAndContext = findTargetElementAndContext(editor, offset, file);
    return elementAndContext == null ? null : elementAndContext.first;
  }
private @Nullable PsiElement findTargetElementFromContext(@NotNull Editor editor, int offset, @Nullable PsiFile file)