diff --git a/core/src/main/kotlin/com/alecstrong/sql/psi/core/psi/mixins/JoinClauseMixin.kt b/core/src/main/kotlin/com/alecstrong/sql/psi/core/psi/mixins/JoinClauseMixin.kt index b6a0241c..4643e410 100644 --- a/core/src/main/kotlin/com/alecstrong/sql/psi/core/psi/mixins/JoinClauseMixin.kt +++ b/core/src/main/kotlin/com/alecstrong/sql/psi/core/psi/mixins/JoinClauseMixin.kt @@ -53,39 +53,39 @@ internal abstract class JoinClauseMixin( private val queryExposed = ModifiableFileLazy { var queryAvailable = tableOrSubqueryList[0].queryExposed() - tableOrSubqueryList.drop(1) - .zip(joinConstraintList) - .zip(joinOperatorList) zip2@{ (subquery, constraint), operator -> - queryAvailable += subquery.queryExposed().let { query -> - when { - query.isEmpty() -> return@zip2 - else -> { - var columns = query.flatMap { it.columns } - var synthesizedColumns = query.flatMap { it.synthesizedColumns } + for ((index, subquery) in tableOrSubqueryList.drop(1).withIndex()) { + val constraint: SqlJoinConstraint? = if (index in joinConstraintList.indices) joinConstraintList[index] else null + val operator: SqlJoinOperator = joinOperatorList[index] + val query = subquery.queryExposed() - if (supportsJoinOperator(operator)) { - columns = columns.map { it.copy(nullable = true) } - synthesizedColumns = synthesizedColumns.map { it.copy(nullable = true) } - } - if (constraint.node?.findChildByType( - SqlTypes.USING, - ) != null - ) { - val columnNames = constraint.columnNameList.map { it.name } - columns = columns.map { - it.copy(hiddenByUsing = it.element is PsiNamedElement && it.element.name in columnNames) - } - } - QueryResult( - table = query.first().table, - columns = columns, - synthesizedColumns = synthesizedColumns, - joinConstraint = constraint, - ) + queryAvailable += when { + query.isEmpty() -> continue + else -> { + var columns = query.flatMap { it.columns } + var synthesizedColumns = query.flatMap { it.synthesizedColumns } + + if (supportsJoinOperator(operator)) { + columns = columns.map { it.copy(nullable = true) } + synthesizedColumns = synthesizedColumns.map { it.copy(nullable = true) } + } + if (constraint != null && constraint.node?.findChildByType( + SqlTypes.USING, + ) != null + ) { + val columnNames = constraint.columnNameList.map { it.name } + columns = columns.map { + it.copy(hiddenByUsing = it.element is PsiNamedElement && it.element.name in columnNames) } } + QueryResult( + table = query.first().table, + columns = columns, + synthesizedColumns = synthesizedColumns, + joinConstraint = constraint, + ) } } + } return@ModifiableFileLazy queryAvailable }