Skip to content

Commit 6db946f

Browse files
authored
Merge pull request #166 from domaframework/fix/code-completion-fix-for-directive-element-name
Do not suggest element names you define in the for directive element
2 parents d2a238a + 3ed0ce1 commit 6db946f

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,14 @@ class SqlParameterCompletionProvider : CompletionProvider<CompletionParameters>(
365365
result.addElement(LookupElementBuilder.create(match.name))
366366
}
367367
// Add ForDirective Items
368-
val forDirectives = ForDirectiveUtil.getForDirectiveBlocks(position)
368+
val parentForDirectiveExpr =
369+
PsiTreeUtil.getParentOfType(position, SqlElForDirective::class.java)
370+
?: PsiTreeUtil.getChildOfType(position.parent, SqlElForDirective::class.java)
371+
val forDirectives =
372+
ForDirectiveUtil.getForDirectiveBlocks(position).filter {
373+
PsiTreeUtil.getParentOfType(it.item, SqlElForDirective::class.java) !=
374+
parentForDirectiveExpr
375+
}
369376
addForDirectiveSuggestions(forDirectives, result)
370377
return null
371378
}

src/main/kotlin/org/domaframework/doma/intellij/extension/psi/SqlElForDirectiveExtension.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ import org.domaframework.doma.intellij.psi.SqlBlockComment
2525
import org.domaframework.doma.intellij.psi.SqlElFieldAccessExpr
2626
import org.domaframework.doma.intellij.psi.SqlElForDirective
2727
import org.domaframework.doma.intellij.psi.SqlElIdExpr
28+
import org.domaframework.doma.intellij.psi.SqlElPrimaryExpr
2829
import org.domaframework.doma.intellij.psi.SqlElStaticFieldAccessExpr
2930
import org.domaframework.doma.intellij.psi.SqlTypes
3031

3132
fun SqlElForDirective.getForItem(): PsiElement? =
3233
PsiTreeUtil
33-
.getChildOfType(this, SqlElIdExpr::class.java)
34+
.getChildOfType(this, SqlElPrimaryExpr::class.java)
3435

3536
fun SqlElForDirective.getForItemDeclaration(): ForDeclarationItem? {
3637
val parentCommentBlock =

src/test/kotlin/org/domaframework/doma/intellij/complate/sql/SqlCompleteTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class SqlCompleteTest : DomaSqlTest() {
289289
innerDirectiveCompleteTest(
290290
"$testDapName/completeDirectiveInsideFor.sql",
291291
listOf("project"),
292-
listOf("employee"),
292+
listOf("employee", "member", "%for"),
293293
)
294294
}
295295

0 commit comments

Comments
 (0)