private @Nullable PsiElement getElementAtCaret(@NotNull PsiFile file, boolean tryInjected) {
    Editor editor = getEditor();
    if (editor == null) return null;
    int offset = editor.getCaretModel().getOffset();
    if (tryInjected) {
      InjectedLanguageManager manager = InjectedLanguageManager.getInstance(getProject());
      PsiElement injectedElementAt = manager.findInjectedElementAt(file, offset);
      if (injectedElementAt != null) return injectedElementAt;
    }
    PsiElement elementAt = file.findElementAt(offset);
    if (offset > 0 && (elementAt == null || elementAt instanceof PsiWhiteSpace)) {
      elementAt = file.findElementAt(offset - 1);
    }
    return elementAt;
  }
private @Nullable PsiElement getElementAtCaret(@NotNull PsiFile file, boolean tryInjected)