PsiElement (@NotNull PsiElement element, @NotNull PsiFile hostFile, int hostOffset, @NotNull PsiDocumentManager documentManager) { Ref<PsiElement> out = new Ref<>(); enumerate(element, hostFile, true, (injectedPsi, places) -> { for (PsiLanguageInjectionHost.Shred place : places) { TextRange hostRange = place.getHost().getTextRange(); if (hostRange.cutOut(place.getRangeInsideHost()).grown(1).contains(hostOffset)) { DocumentWindowImpl document = (DocumentWindowImpl)documentManager.getCachedDocument(injectedPsi); if (document == null) return; int injectedOffset = document.hostToInjected(hostOffset); PsiElement injElement = injectedPsi.findElementAt(injectedOffset); out.set(injElement == null ? injectedPsi : injElement); } } }); return out.get(); }