Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented May 27, 2025

When code completion is invoked with the cursor immediately before a function’s argument-parameter element, the parameter placeholder was being duplicated in the suggestions. Adjust the behavior so that:

  • If the cursor is positioned just before the parameter element, () is not suggested.
  • If completion is triggered mid-method name, the suggestion includes the parentheses.

These changes ensure argument parameters are suggested correctly based on cursor position.

@xterao xterao self-assigned this May 27, 2025
@xterao xterao added bug Something isn't working fix Bug fixes labels May 27, 2025
@xterao xterao requested a review from Copilot May 27, 2025 02:53
@xterao xterao added this to the 0.8.0 Release milestone May 27, 2025
@xterao xterao linked an issue May 27, 2025 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adjusts SQL code completion so that parentheses are only suggested when the cursor is mid-method name, not immediately before an argument placeholder. Key changes include:

  • Introduce caretNextText to peek at the next character and conditionally omit () in lookup elements.
  • Refactor various collectors and handlers to accept and propagate caretNextText and use a shared createMethodLookupElement utility.
  • Add a new test case (completePropertyAfterStaticMethodCall) and update expected suggestions for batch insert and built-in function completions.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/test/testData/src/main/resources/META-INF/doma/example/dao/SqlCompleteTestDao/completePropertyAfterStaticMethodCall.sql New SQL test fixture for method call completion
src/test/testData/src/main/resources/META-INF/doma/example/dao/SqlCompleteTestDao/completeBatchInsert.sql Updated placeholder to test trailing‐parenthesis logic
src/test/testData/src/main/java/doma/example/dao/SqlCompleteTestDao.java Added DAO method for the new SQL test
src/test/kotlin/org/domaframework/doma/intellij/complate/sql/SqlCompleteTest.kt Registered new SQL test and updated expected built-in function names
src/main/kotlin/org/domaframework/doma/intellij/contributor/sql/provider/SqlParameterCompletionProvider.kt Added caretNextText capture and threaded it into directive handling
src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/collector/StaticPropertyCollector.kt Updated lookup element creation to use createMethodLookupElement with caretNextText
src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/collector/FunctionCallCollector.kt Renamed and refactored collector to accept caretNextText, removed conditional guard
src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/StaticDirectiveHandlerData.kt Removed unused DomaFunction data class
src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/StaticDirectiveHandler.kt Added caretNextText propagation and improved static‐access detection
src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/DirectiveCompletion.kt Updated handler constructor to include caretNextText
Comments suppressed due to low confidence (3)

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

  • The code unconditionally uses offset + 1 to create a TextRange, which can throw an exception if the caret is at the end of the document. Add a guard (e.g. if (offset < document.textLength)) or clamp the range to avoid out-of-bounds access.
val range = com.intellij.openapi.util.TextRange(offset, offset + 1)

src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/collector/FunctionCallCollector.kt:75

  • By removing the if (functions.isEmpty()) guard, the collector now always adds public methods and filters out duplicates, potentially changing completion results. Confirm that this change is intended or restore the guard to preserve original behavior.
functions.addAll(

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

  • [nitpick] The variable name caretNextText is a bit verbose; consider renaming it to nextChar or peekChar for clarity and brevity.
val caretNextText = parameters.editor.document.getText(range)

@xterao xterao force-pushed the fix/replace-trailing-characters-during-code-completion branch from 0eeee52 to c025651 Compare May 27, 2025 02:55
@xterao xterao force-pushed the fix/replace-trailing-characters-during-code-completion branch from c025651 to 42c3907 Compare May 27, 2025 04:07
@xterao xterao merged commit 51430c8 into main May 27, 2025
3 checks passed
@xterao xterao deleted the fix/replace-trailing-characters-during-code-completion branch May 27, 2025 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace Trailing Characters During Code Completion

2 participants