mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
[json schema] nested completions - properly handle the case with multiple child nodes (named + regex at once)
GitOrigin-RevId: 6a2b408f0d84612d6c1373d0f2740a8ec1d588df
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4690be09a5
commit
a976ac8093
@@ -80,7 +80,16 @@ private fun JsonPointerPosition.toPathItems() =
|
||||
|
||||
private tailrec fun NestedCompletionsNode.navigate(index: Int, steps: List<String>): NestedCompletionsNode? =
|
||||
if (index !in steps.indices) this
|
||||
else children.firstOrNull { it.matches(steps[index]) }?.node?.navigate(index + 1, steps)
|
||||
else {
|
||||
val matchingNodes = children.filter { it.matches(steps[index]) }
|
||||
matchingNodes.getPreferredChild()?.node?.navigate(index + 1, steps)
|
||||
}
|
||||
|
||||
// some schemas provide both named and regex nodes for the same name
|
||||
// we need to prioritize named options over regex options
|
||||
private fun Collection<ChildNode>.getPreferredChild(): ChildNode? {
|
||||
return firstOrNull { it is ChildNode.NamedChildNode } ?: firstOrNull()
|
||||
}
|
||||
|
||||
private fun ChildNode.matches(name: String): Boolean = when (this) {
|
||||
is ChildNode.Isolated.RegexNode -> regex.matches(name)
|
||||
|
||||
Reference in New Issue
Block a user