DocumentWindow (Project project, Editor editor, int offset) { PsiFile hostFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (hostFile != null) { // inspired by com.intellij.codeInsight.editorActions.TypedHandler.injectedEditorIfCharTypedIsSignificant() List<DocumentWindow> injected = InjectedLanguageManager.getInstance(project).getCachedInjectedDocumentsInRange(hostFile, TextRange.create(offset, offset)); for (DocumentWindow documentWindow : injected ) { if (documentWindow.isValid() && documentWindow.containsRange(offset, offset)) { return documentWindow; } } } return null; }