@Override
      public @Nullable PsiElement getPsiElementAtStartOffset() {
        Project project = getProject();
        int templateStartOffset = getTemplateStartOffset();
        int offset = templateStartOffset > 0 ? getTemplateStartOffset() - 1 : getTemplateStartOffset();

        Editor editor = getEditor();
        if (editor == null) {
          return null;
        }

        PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());

        PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
        return file == null ? null : file.findElementAt(offset);
      }
@Override
      public @Nullable PsiElement getPsiElementAtStartOffset()