[CMI] Improve CodeMetaInfoRenderer

1. Properly handle meta which start == end
2. Sort metainfos of one range by tag
This commit is contained in:
Dmitriy Novozhilov
2020-12-01 11:24:02 +03:00
parent 98a2f29f95
commit ceb44ddccd
@@ -56,13 +56,17 @@ object CodeMetaInfoRenderer {
current = next current = next
} }
} }
// Here we need to handle meta infos which has start == end and close them immediately
checkOpenedAndCloseStringIfNeeded(opened, i, builder)
builder.append(c) builder.append(c)
} }
checkOpenedAndCloseStringIfNeeded(opened, originalText.length, builder) checkOpenedAndCloseStringIfNeeded(opened, originalText.length, builder)
} }
private val metaInfoComparator = (compareBy<CodeMetaInfo> { it.start } then compareByDescending { it.end }) then compareBy { it.tag }
private fun getSortedCodeMetaInfos(metaInfos: Collection<CodeMetaInfo>): List<CodeMetaInfo> { private fun getSortedCodeMetaInfos(metaInfos: Collection<CodeMetaInfo>): List<CodeMetaInfo> {
return metaInfos.sortedWith(compareBy<CodeMetaInfo> { it.start }.then(compareByDescending { it.end })) return metaInfos.sortedWith(metaInfoComparator)
} }
private fun closeString(result: StringBuilder) = result.append("<!>") private fun closeString(result: StringBuilder) = result.append("<!>")