if (pr == null) {
return Collections.emptyMap();
}
try {
Map<String, List<OffsetRange>> folds = new HashMap<String, List<OffsetRange>>();
BaseDocument document = (BaseDocument) pr.getSnapshot().getSource().getDocument(true);
TokenHierarchy<CoffeeScriptTokenId> th = (TokenHierarchy<CoffeeScriptTokenId>) pr.getSnapshot().getTokenHierarchy();
TokenSequence<CoffeeScriptTokenId> ts = th.tokenSequence(CoffeeScriptLanguage.getLanguage());
List<OffsetRange> ranges = new ArrayList<OffsetRange>();
Deque<IdentRegion> indents = new ArrayDeque<IdentRegion>();
while (ts.moveNext()) {
Token<CoffeeScriptTokenId> token = ts.token();
switch (token.id()) {
// case COMMENT:
// TokenSequence<CoffeeScriptTokenId> commentTS = ts.subSequence(ts.offset());
// int start = token.offset(th);
// int end = start + token.length();
// while (commentTS.moveNext()) {
// Token<CoffeeScriptTokenId> commentNextToken = commentTS.token();
// if (commentNextToken.id() == CoffeeScriptTokenId.COMMENT) {
// end = commentNextToken.offset(th) + commentNextToken.length();
// continue;
// }
// if (commentNextToken.id().getCategory() == CoffeeScriptTokenId.Category.WHITESPACE_CAT) {
// continue;
// }
// break;
// }
// addIndent(document, ranges, start, end);
// break;
case INDENT:
Integer indent = (Integer) token.getProperty("indent");
indents.push(new IdentRegion(token.offset(th), indent));
break;
case OUTDENT:
Integer outdent = (Integer) token.getProperty("indent");
int to = token.offset(th) + token.length();
addIndent(document, ranges, indents, outdent, to);
break;
}
}
addIndent(document, ranges, indents, -1, document.getLength());
folds.put("codeblocks", ranges);
return folds;
} catch (Exception e) {
Exceptions.printStackTrace(e);
}