private static void initLanguageFromCaret(@NotNull Project project,
                                            @Nullable Editor editor,
                                            @Nullable PsiFile psiFile,
                                            @NotNull ScratchFileCreationHelper.Context context,
                                            @NotNull DataContext dataContext) {
    if (editor == null || psiFile == null) return;
    Caret caret = editor.getCaretModel().getPrimaryCaret();
    int offset = caret.getOffset();
    PsiElement element = InjectedLanguageManager.getInstance(project).findInjectedElementAt(psiFile, offset);
    PsiFile file = element != null ? element.getContainingFile() : psiFile;
    FileTypeManager fileTypeManager = FileTypeManager.getInstance();
    FileType fileType = ScratchImplUtil.getFileTypeFromName(file.getName(), fileTypeManager);
    context.language = fileType instanceof LanguageFileType ? file.getLanguage() : null;
    if (fileType != null) {
      context.fileExtension = ScratchImplUtil.getFileTypeExtensions(fileType, true, fileTypeManager).first();
    }
    if (context.language == PlainTextLanguage.INSTANCE && file.getFileType() instanceof InternalFileType) {
      context.language = StdLanguages.XML;
    }
    checkLanguageAndTryToFixText(project, context, dataContext);
  }
private static void initLanguageFromCaret(@NotNull Project project,
                                            @Nullable Editor editor,
                                            @Nullable PsiFile psiFile,
                                            @NotNull ScratchFileCreationHelper.Context context,
                                            @NotNull DataContext dataContext)