From 83587b3171c46f0c2093a821c5cddb00b7cda710 Mon Sep 17 00:00:00 2001 From: xterao Date: Tue, 19 Aug 2025 10:42:16 +0900 Subject: [PATCH] Fix DAO method recognition in autocomplete by handling null cases --- .../sql/provider/SqlParameterCompletionProvider.kt | 10 +++++----- .../complate/sql/SqlSpecificParamTypeCompleteTest.kt | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/domaframework/doma/intellij/contributor/sql/provider/SqlParameterCompletionProvider.kt b/src/main/kotlin/org/domaframework/doma/intellij/contributor/sql/provider/SqlParameterCompletionProvider.kt index 89e26105..b2c2cd97 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/contributor/sql/provider/SqlParameterCompletionProvider.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/contributor/sql/provider/SqlParameterCompletionProvider.kt @@ -189,7 +189,7 @@ class SqlParameterCompletionProvider : CompletionProvider( val daoMethod = findDaoMethod(originalFile) val searchText = cleanString(getSearchElementText(position)) var topElementType: PsiType? = null - if (elements.isEmpty() && daoMethod != null) { + if (elements.isEmpty()) { getElementTypeByFieldAccess(originalFile, position, elements, daoMethod, result) return } @@ -303,15 +303,15 @@ class SqlParameterCompletionProvider : CompletionProvider( originalFile: PsiFile, position: PsiElement, elements: List, - daoMethod: PsiMethod, + daoMethod: PsiMethod?, result: CompletionResultSet, ): PsiType? { val topElement = elements.firstOrNull() val topText = cleanString(getSearchElementText(topElement)) - val matchParams = daoMethod.searchParameter(topText) - val findParam = matchParams.find { it.name == topText } + val matchParams = daoMethod?.searchParameter(topText) + val findParam = matchParams?.find { it.name == topText } if (elements.size <= 1 && findParam == null) { - matchParams.map { match -> + matchParams?.map { match -> result.addElement(LookupElementBuilder.create(match.name)) } // Add ForDirective Items diff --git a/src/test/kotlin/org/domaframework/doma/intellij/complate/sql/SqlSpecificParamTypeCompleteTest.kt b/src/test/kotlin/org/domaframework/doma/intellij/complate/sql/SqlSpecificParamTypeCompleteTest.kt index 21134259..b422916c 100644 --- a/src/test/kotlin/org/domaframework/doma/intellij/complate/sql/SqlSpecificParamTypeCompleteTest.kt +++ b/src/test/kotlin/org/domaframework/doma/intellij/complate/sql/SqlSpecificParamTypeCompleteTest.kt @@ -92,7 +92,6 @@ class SqlSpecificParamTypeCompleteTest : DomaSqlTest() { myFixture.configureFromExistingVirtualFile(sqlFile) val lookupElements = myFixture.completeBasic() val suggestions = lookupElements.map { it.lookupString } - println(suggestions.map { it }) expectedSuggestions.forEach { expected -> assertTrue( "Expected '$expected' in completion suggestions: $suggestions",