Skip to content

Commit f01203f

Browse files
committed
Fix the code completion logic invoked after function parameters so it correctly retrieves the preceding elements.
1 parent 8a3241f commit f01203f

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/main/kotlin/org/domaframework/doma/intellij/common/util/ForDirectiveUtil.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ class ForDirectiveUtil {
434434
completeResult = null,
435435
validationResult = null,
436436
)
437-
val parametersExpr = PsiTreeUtil.nextLeaf(topElement)?.parent as? SqlElParameters
437+
val parametersExpr = topElement.nextSibling as? SqlElParameters
438438
if (parametersExpr == null) {
439439
val topPropertyField = referenceClazz.findStaticField(searchText)
440440

src/main/kotlin/org/domaframework/doma/intellij/contributor/sql/processor/SqlCompletionBlockProcessor.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,20 @@ abstract class SqlCompletionBlockProcessor {
5050
}.toList()
5151

5252
var inParameter = false
53+
val rightLists: MutableList<PsiElement> = mutableListOf()
5354
val formatElements = mutableListOf<PsiElement>()
5455
prevElements.forEach { prev ->
55-
if (prev.elementType == SqlTypes.RIGHT_PAREN) inParameter = true
56-
if (!inParameter) {
56+
if (prev.elementType == SqlTypes.RIGHT_PAREN) {
57+
inParameter = true
58+
rightLists.add(prev)
59+
}
60+
if (!inParameter && rightLists.isEmpty()) {
5761
formatElements.add(prev)
5862
}
59-
if (prev.elementType == SqlTypes.LEFT_PAREN) inParameter = false
63+
if (prev.elementType == SqlTypes.LEFT_PAREN) {
64+
inParameter = false
65+
rightLists.removeLastOrNull()
66+
}
6067
}
6168

6269
val filterElements =
@@ -72,7 +79,7 @@ abstract class SqlCompletionBlockProcessor {
7279
}.plus(targetElement)
7380
.sortedBy { it.textOffset }
7481

75-
return if (filterElements.isNotEmpty()) filterElements else emptyList()
82+
return filterElements.ifEmpty { emptyList() }
7683
}
7784

7885
private fun isSqlElSymbol(element: PsiElement): Boolean =

0 commit comments

Comments
 (0)