Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented Jun 2, 2025

When identifying code-completion targets, ignore argument-parameter elements and retrieve only the preceding element list.

Ensure that even if a field-access element isn’t fully constructed mid-typing, string-based parsing still triggers static field-access code completion.

  • Prevent entering class-name suggestion logic when completion is invoked immediately before @.
  • Ensure static properties are suggested even if another bind variable appears before the static field access.

@xterao xterao self-assigned this Jun 2, 2025
@xterao xterao added the bug Something isn't working label Jun 2, 2025
@github-actions github-actions bot added the fix Bug fixes label Jun 2, 2025
@xterao xterao requested a review from Copilot June 2, 2025 04:45
@xterao xterao added this to the 0.9.0 Release milestone Jun 2, 2025
@xterao xterao linked an issue Jun 2, 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 enhances SQL code-completion in the Doma IntelliJ plugin by improving static field-access detection and parsing, and adds test coverage for these scenarios.

  • Added new SQL test fixtures and DAO methods to cover static field completion before @ and after other elements
  • Refactored SqlParameterCompletionProvider and StaticDirectiveHandler to improve static field detection, unify comment parsing via StringUtil, and centralize directive symbols
  • Extracted directive symbols into DirectiveCompletion and introduced suffix constants in ForDirectiveUtil for cleaner for-directive handling

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/test/.../completeTopElementBeforeAtsign.sql New test fixture for completion immediately before @
src/test/.../completeStaticPropertyAfterOtherElement.sql New test fixture for completion after another bind element
src/test/.../completePropertyAfterStaticPropertyCallWithMethodParameter.sql Adjusted test fixture for static property call removal of suffix
SqlCompleteTestDao.java Added DAO methods to drive the new completion tests
SqlCompleteTest.kt Registered new SQL test files and updated expected suggestion lists
SqlParameterCompletionProvider.kt Unified block-comment parsing, updated element filtering, and adjusted static-access logic
StaticDirectiveHandler.kt Refined detection for class-name vs. static-field completions
StringUtil.kt Introduced utility for block-comment stripping and class-name extraction
ForDirectiveUtil.kt Added HAS_NEXT_PREFIX and INDEX_PREFIX constants
DirectiveCompletion.kt Centralized directiveSymbols list
CleanElementText.kt Delegated comment parsing to StringUtil
PsiStaticElement.kt Switched to StringUtil.getSqlElClassText for FQCN parsing
PsiPatternUtil.kt Updated to use DirectiveCompletion.directiveSymbols and improved comment matching logic
Comments suppressed due to low confidence (2)

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

  • [nitpick] The function name getElementTypeByPrevSqlElClassWords is quite long and may be hard to read. Consider renaming to something more concise like getStaticFieldTypeFromFqdn.
private fun getElementTypeByPrevSqlElClassWords(

src/main/kotlin/org/domaframework/doma/intellij/common/util/StringUtil.kt:19

  • Utility functions getSqlElClassText and replaceBlockCommentStartEnd are critical for parsing but have no dedicated unit tests. Consider adding tests to validate edge cases (e.g. missing delimiters, multiple @).
fun getSqlElClassText(text: String): String =

@xterao xterao force-pushed the fix/code-completion-suggestions-after-static-property-accesses branch from 44b2a80 to 690ad4e Compare June 2, 2025 06:59
@xterao xterao force-pushed the fix/code-completion-suggestions-after-static-property-accesses branch from 690ad4e to 4cfd2a7 Compare June 2, 2025 07:01
@xterao xterao requested a review from Copilot June 2, 2025 07:09
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 pull request refines code completion for static field access by narrowing the target elements during completion and ensuring that class-name suggestions are not mistakenly triggered. Key changes include adjustments to the SQL test files to support new completion scenarios, updates to the provider logic in Kotlin for improved element filtering and handling, and minor refactoring across utility and directive classes.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
completeTopElementBeforeAtsign.sql Added a test case for top element completion before an at-sign.
completeStaticPropertyAfterOtherElement.sql Added a test case to trigger static property completion after another element.
completePropertyAfterStaticPropertyCallWithMethodParameter.sql Updated completion test ensuring consistency after a static method call.
SqlCompleteTestDao.java Added new DAO methods for testing the static field access scenarios.
SqlCompleteTest.kt Extended the test suite to cover the new and refactored completion cases.
SqlParameterCompletionProvider.kt Refactored filtering and processing of completion candidates with additional parameter handling.
StringUtil.kt, ForDirectiveUtil.kt, StaticDirectiveHandler.kt, DirectiveCompletion.kt, CleanElementText.kt, PsiStaticElement.kt, PsiPatternUtil.kt Minor refactoring and usage of constants to improve code clarity and maintainability.
Comments suppressed due to low confidence (1)

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

  • [nitpick] Consider adding a comment explaining the regex pattern's intent for class package validation to aid future maintenance.
val elClassPattern = "^([a-zA-Z]*(\.)+)*$"

@xterao xterao merged commit 9b321c1 into main Jun 2, 2025
5 checks passed
@xterao xterao deleted the fix/code-completion-suggestions-after-static-property-accesses branch June 2, 2025 07: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.

Fix code completion suggestions after static property accesses

2 participants