@Nullable public static Lexer getLexerBasedOnLexerHighlighter(CharSequence text, VirtualFile virtualFile, Project project) { EditorHighlighter highlighter = null; PsiFile psiFile = virtualFile != null ? PsiManager.getInstance(project).findFile(virtualFile) : null; final Document document = psiFile != null ? PsiDocumentManager.getInstance(project).getDocument(psiFile) : null; final EditorHighlighter cachedEditorHighlighter; boolean alreadyInitializedHighlighter = false; if (document != null && (cachedEditorHighlighter = getEditorHighlighterForCachesBuilding(document)) != null && PlatformIdTableBuilding.checkCanUseCachedEditorHighlighter(text, cachedEditorHighlighter)) { highlighter = cachedEditorHighlighter; alreadyInitializedHighlighter = true; } else if (virtualFile != null) { highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(project, virtualFile); } if (highlighter != null) { return new LexerEditorHighlighterLexer(highlighter, alreadyInitializedHighlighter); } return null; }
@Nullable @Override public Lexer getIndexingLexer(@NotNull PsiFile file) { if (!(file instanceof LatteFile)) { return null; } VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) { virtualFile = file.getViewProvider().getVirtualFile(); } try { LayeredLexer.ourDisableLayersFlag.set(Boolean.TRUE); EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file.getProject(), virtualFile); return new LexerEditorHighlighterLexer(highlighter, false); } finally { LayeredLexer.ourDisableLayersFlag.set(Boolean.FALSE); } }
public void restart(@NotNull CharSequence text) { lexer.start(text); if (lexer instanceof LexerEditorHighlighterLexer) { HighlighterIterator iterator = ((LexerEditorHighlighterLexer)lexer).getHighlighterIterator(); if (iterator instanceof LayeredHighlighterIterator) { layeredHighlighterIterator = (LayeredHighlighterIterator)iterator; } else { layeredHighlighterIterator = null; } } }
public void resetPosition(int startOffset) { if (lexer instanceof LexerEditorHighlighterLexer) { ((LexerEditorHighlighterLexer)lexer).resetPosition(startOffset); HighlighterIterator iterator = ((LexerEditorHighlighterLexer)lexer).getHighlighterIterator(); if (iterator instanceof LayeredHighlighterIterator) { layeredHighlighterIterator = (LayeredHighlighterIterator)iterator; } else { layeredHighlighterIterator = null; } } else { CharSequence text = lexer.getBufferSequence(); lexer.start(text, startOffset, text.length()); } }
public void restart(@Nonnull CharSequence text) { lexer.start(text); if (lexer instanceof LexerEditorHighlighterLexer) { HighlighterIterator iterator = ((LexerEditorHighlighterLexer)lexer).getHighlighterIterator(); if (iterator instanceof LayeredHighlighterIterator) { layeredHighlighterIterator = (LayeredHighlighterIterator)iterator; } else { layeredHighlighterIterator = null; } } }