public static void clearCaches(
     @NotNull PsiFile injected, @NotNull DocumentWindowImpl documentWindow) {
   VirtualFileWindowImpl virtualFile = (VirtualFileWindowImpl) injected.getVirtualFile();
   PsiManagerEx psiManagerEx = (PsiManagerEx) injected.getManager();
   if (psiManagerEx.getProject().isDisposed()) return;
   psiManagerEx.getFileManager().setViewProvider(virtualFile, null);
   PsiElement context =
       InjectedLanguageManager.getInstance(injected.getProject()).getInjectionHost(injected);
   PsiFile hostFile;
   if (context != null) {
     hostFile = context.getContainingFile();
   } else {
     VirtualFile delegate = virtualFile.getDelegate();
     hostFile = delegate.isValid() ? psiManagerEx.findFile(delegate) : null;
   }
   if (hostFile != null) {
     // modification of cachedInjectedDocuments must be under PsiLock
     synchronized (PsiLock.LOCK) {
       List<DocumentWindow> cachedInjectedDocuments = getCachedInjectedDocuments(hostFile);
       for (int i = cachedInjectedDocuments.size() - 1; i >= 0; i--) {
         DocumentWindow cachedInjectedDocument = cachedInjectedDocuments.get(i);
         if (cachedInjectedDocument == documentWindow) {
           cachedInjectedDocuments.remove(i);
         }
       }
     }
   }
 }
 @Nullable
 public static DocumentWindow getDocumentWindow(@NotNull PsiElement element) {
   PsiFile file = element.getContainingFile();
   if (file == null) return null;
   VirtualFile virtualFile = file.getVirtualFile();
   if (virtualFile instanceof VirtualFileWindow)
     return ((VirtualFileWindow) virtualFile).getDocumentWindow();
   return null;
 }
 public static Editor openEditorFor(@NotNull PsiFile file, @NotNull Project project) {
   Document document = PsiDocumentManager.getInstance(project).getDocument(file);
   // may return editor injected in current selection in the host editor, not for the file passed
   // as argument
   VirtualFile virtualFile = file.getVirtualFile();
   if (virtualFile == null) {
     return null;
   }
   if (virtualFile instanceof VirtualFileWindow) {
     virtualFile = ((VirtualFileWindow) virtualFile).getDelegate();
   }
   Editor editor =
       FileEditorManager.getInstance(project)
           .openTextEditor(new OpenFileDescriptor(project, virtualFile, -1), false);
   if (editor == null || editor instanceof EditorWindow || editor.isDisposed()) return editor;
   if (document instanceof DocumentWindowImpl) {
     return EditorWindow.create((DocumentWindowImpl) document, (EditorImpl) editor, file);
   }
   return editor;
 }