package com.jantvrdik.intellij.latte.psi;

import com.intellij.lexer.Lexer;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.search.IndexPatternBuilder;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import com.jantvrdik.intellij.latte.lexer.LatteLexer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;


public class LatteIndexPatternBuilder implements IndexPatternBuilder {

	@Nullable
	@Override
	public Lexer getIndexingLexer(@NotNull PsiFile file) {
		return file instanceof LatteFile ? new LatteLexer() : null;
	}

	@Nullable
	@Override
	public TokenSet getCommentTokenSet(@NotNull PsiFile file) {
		return TokenSet.create(LatteTypes.T_MACRO_COMMENT);
	}

	@Override
	public int getCommentStartDelta(IElementType tokenType) {
		return 0;
	}

	@Override
	public int getCommentEndDelta(IElementType tokenType) {
		return 2;
	}
}

@@ -63,20 +63,244 @@
 .lexer.L
-exer
+ayeredLexer;%0Aimport com.intellij.lexer.Lexer;%0Aimport com.intellij.openapi.editor.highlighter.EditorHighlighter;%0Aimport com.intellij.openapi.editor.highlighter.EditorHighlighterFactory;%0Aimport com.intellij.openapi.vfs.VirtualFile
 ;%0Aimport
@@ -379,24 +379,89 @@
 ernBuilder;%0A
+import com.intellij.psi.impl.search.LexerEditorHighlighterLexer;%0A
 import com.i
@@ -534,62 +534,8 @@
 et;%0A
-import com.jantvrdik.intellij.latte.lexer.LatteLexer;%0A
 impo
@@ -773,67 +773,539 @@
 %7B%0A%09%09
-return file instanceof LatteFile ? new Lat
+if (!(file instanceof LatteFile)) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09VirtualFile virtualFile = file.getVirtualFile();%0A%09%09if (virtualFile == null) %7B%0A%09%09%09virtualFile = file.getViewProvider().getVirtualFile();%0A%09%09%7D%0A%0A%09%09try %7B%0A%09%09%09LayeredLexer.ourDisableLayersFlag.set(Boolean.TRUE);%0A%09%09%09EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file.getProject(), virtualFile);%0A%09%09%09return new LexerEditorHighligh
 te
+r
 Lexer(
-) : null;
+highlighter, false);%0A%09%09%7D finally %7B%0A%09%09%09LayeredLexer.ourDisableLayersFlag.set(Boolean.FALSE);%0A%09%09%7D
 %0A%09%7D%0A
@@ -1606,16 +1606,82 @@
 %7B%0A%09%09
-return 2
+if (tokenType == LatteTypes.T_MACRO_COMMENT) %7B%0A%09%09%09return 2;%0A%09%09%7D%0A%09%09return 0
 ;%0A%09%7D

support for todo in outer html