FIR: fix PsiElementFinderByType

Current implementation would return the input node if the type matches.
This is clear wrong since the method is supposed to return children.
This commit is contained in:
Tianyu Geng
2021-10-25 16:31:40 -07:00
committed by teamcityserver
parent 93561a1a55
commit f51b108821
2 changed files with 12 additions and 8 deletions
@@ -22,11 +22,13 @@ class LighterTreeElementFinderByType(
} }
private fun visitNode(node: LighterASTNode, currentDepth: Int): LighterASTNode? { private fun visitNode(node: LighterASTNode, currentDepth: Int): LighterASTNode? {
if (node.tokenType in types) { if (currentDepth != 0) {
if (index == 0) { if (node.tokenType in types) {
return node if (index == 0) {
return node
}
index--
} }
index--
} }
if (currentDepth == depth) return null if (currentDepth == depth) return null
@@ -19,11 +19,13 @@ class PsiElementFinderByType(
} }
private fun visitElement(element: PsiElement, currentDepth: Int): PsiElement? { private fun visitElement(element: PsiElement, currentDepth: Int): PsiElement? {
if (element.node.elementType in types) { if (currentDepth != 0) {
if (index == 0) { if (element.node.elementType in types) {
return element if (index == 0) {
return element
}
index--
} }
index--
} }
if (currentDepth == depth) return null if (currentDepth == depth) return null