TextRange (@NotNull CharSequence text, int offset) { TemplateTextLexer lexer = new TemplateTextLexer(); lexer.start(text); while (true) { IElementType tokenType = lexer.getTokenType(); if (tokenType == null) { return null; } int start = lexer.getTokenStart(); if (start < offset) { int end = lexer.getTokenEnd(); if (end >= offset) { return tokenType == TemplateTokenType.VARIABLE ? new TextRange(start + 1, end - 1) : null; } } lexer.advance(); } }