List<PsiToken> (int tokenStart, List<Exclusion> affecting) { int tokenEnd = tokenStart + length(); if (affecting.size() == 1 && affecting.get(0).start < tokenStart && affecting.get(0).end > tokenEnd) { return Collections.emptyList(); } List<PsiToken> shreds = new ArrayList<>(); int startInPsi = rangeInPsi.getStartOffset(); int prevEnd = tokenStart; for (Exclusion range : affecting) { if (range.start > prevEnd) { shreds.add(withRange(TextRange.from(startInPsi + prevEnd - tokenStart, range.start - prevEnd))); } if (range.kind != ExclusionKind.exclude) { var tokenKind = range.kind == ExclusionKind.markup ? TextContentImpl.TokenKind.markup : TextContentImpl.TokenKind.unknown; shreds.add(new PsiToken("", psi, TextRange.from(startInPsi + range.start - tokenStart, 0), tokenKind)); } prevEnd = range.end; } Exclusion lastRange = affecting.get(affecting.size() - 1); if (tokenEnd > lastRange.end) { shreds.add(withRange(new TextRange(startInPsi + lastRange.end - tokenStart, startInPsi + length()))); } return shreds; }