Skip to content

Commit 3b3c340

Browse files
committed
Add definition element name of for directory to bind variable suggestions
1 parent 9786e3a commit 3b3c340

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/kotlin/org/domaframework/doma/intellij/contributor/sql/provider/SqlParameterCompletionProvider.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class SqlParameterCompletionProvider : CompletionProvider<CompletionParameters>(
275275
val searchText = cleanString(getSearchElementText(position))
276276
var topElementType: PsiType? = null
277277
if (elements.isEmpty() && daoMethod != null) {
278-
getElementTypeByFieldAccess(originalFile, elements, daoMethod, result)
278+
getElementTypeByFieldAccess(originalFile, position, elements, daoMethod, result)
279279
return
280280
}
281281
val top = elements.first()
@@ -301,7 +301,7 @@ class SqlParameterCompletionProvider : CompletionProvider<CompletionParameters>(
301301
isBatchAnnotation = psiDaoMethod.daoType.isBatchAnnotation()
302302
if (isFieldAccessByForItem(top, elements, searchText, isBatchAnnotation, result)) return
303303
topElementType =
304-
getElementTypeByFieldAccess(originalFile, elements, daoMethod, result) ?: return
304+
getElementTypeByFieldAccess(originalFile, position, elements, daoMethod, result) ?: return
305305
}
306306

307307
setCompletionFieldAccess(
@@ -351,18 +351,26 @@ class SqlParameterCompletionProvider : CompletionProvider<CompletionParameters>(
351351
*/
352352
private fun getElementTypeByFieldAccess(
353353
originalFile: PsiFile,
354+
position: PsiElement,
354355
elements: List<PsiElement>,
355356
daoMethod: PsiMethod,
356357
result: CompletionResultSet,
357358
): PsiType? {
358-
val topText = cleanString(getSearchElementText(elements.firstOrNull()))
359+
val topElement = elements.firstOrNull()
360+
val topText = cleanString(getSearchElementText(topElement))
359361
val matchParams = daoMethod.searchParameter(topText)
360362
val findParam = matchParams.find { it.name == topText }
361363
if (elements.size <= 1 && findParam == null) {
362-
// TODO Add For Directive Items
363364
matchParams.map { match ->
364365
result.addElement(LookupElementBuilder.create(match.name))
365366
}
367+
// Add ForDirective Items
368+
val forDirectives = ForDirectiveUtil.getForDirectiveBlocks(position)
369+
forDirectives.forEach {
370+
result.addElement(LookupElementBuilder.create(it.item.text))
371+
result.addElement(LookupElementBuilder.create("${it.item.text}_has_next"))
372+
result.addElement(LookupElementBuilder.create("${it.item.text}_index"))
373+
}
366374
return null
367375
}
368376
if (findParam == null) {

0 commit comments

Comments
 (0)