EditorHighlighter (@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile psiFile) { if (!PsiDocumentManager.getInstance(project).isCommitted(editor.getDocument())) { return editor.getHighlighter(); } PsiElement elementAt = psiFile.findElementAt(editor.getCaretModel().getOffset()); for (PsiElement e : SyntaxTraverser.psiApi().parents(elementAt).takeWhile(Conditions.notEqualTo(psiFile))) { if (!(PsiUtilCore.getElementType(e) instanceof ILazyParseableElementType)) continue; Language language = ILazyParseableElementType.LANGUAGE_KEY.get(e.getNode()); if (language == null) continue; TextRange range = e.getTextRange(); int offset = range.getStartOffset(); SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, psiFile.getVirtualFile()); LexerEditorHighlighter highlighter = new LexerEditorHighlighter(syntaxHighlighter, editor.getColorsScheme()) { @NotNull @Override public HighlighterIterator createIterator(int startOffset) { return new HighlighterIteratorWrapper(super.createIterator(Math.max(startOffset - offset, 0))) { @Override public int getStart() { return super.getStart() + offset; } @Override public int getEnd() { return super.getEnd() + offset; } }; } }; highlighter.setText(editor.getDocument().getText(range)); return highlighter; } return editor.getHighlighter(); }