Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented May 16, 2025

Enable suggestion, inspection, and reference resolution for user-registered custom functions in function calls. Users register classes that define custom functions via the settings screen; during code completion, functions from those registered classes are offered as suggestions.

During code inspection, report an error if a function call refers to a method that is neither defined in any registered class nor declared in org.seasar.doma.expr.ExpressionFunctions.

For reference resolution, link each function call to the first class (among the registered ones) where the corresponding method is defined.

Setting

After this feature addition, the SQL formatting enable flag will be moved to the project-level settings. Since the configuration file has changed, please re-enable the flag in the settings screen (default: false).

@xterao xterao requested a review from Copilot May 16, 2025 10:17
@xterao xterao self-assigned this May 16, 2025
@xterao xterao added enhancement New feature or request feature labels May 16, 2025
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 adds support for custom functions, enabling suggestion, inspection, and reference resolution when users register custom functions via settings.

  • Introduces a new inspection processor for function call errors.
  • Updates code formatting and common path parameter imports to use helper classes.
  • Refactors function lookup and completion in SQL directives to use registered custom function settings.

Reviewed Changes

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

Show a summary per file
File Description
DaoPackageRenameListenerProcessor.kt Updated import to use the CommonPathParameterHelper for resolving META-INF paths.
SqlInspectionVisitor.kt Added support for visiting and processing SQL function calls via a new visitor method.
InspectionFunctionCallVisitorProcessor.kt Introduces a processor that checks custom function registrations and issues an error if the function is missing.
SqlPostProcessor.kt Modified SQL formatting logic to retrieve settings based on project context.
SqlFormattingModelBuilder.kt Updated to use an active project helper when fetching SQL format settings.
SqlFormatPreProcessor.kt Adjusted to pass the project instance when checking if SQL formatting is enabled.
PsiMethodExtension.kt Removed deprecated code for Doma annotations.
ModuleExtensions.kt, ProjectExtensions.kt, DaoMethodUtil.kt, JarFileSearch.kt, FileTypeCheck.kt Updated imports to use the CommonPathParameterHelper.
StaticBuildFunctionCollector.kt Refactored function completion to iterate over custom function settings and improved the construction of lookup elements.
DirectiveCompletion.kt Simplified by removing redundant project passing.
ExpressionFunctionsHelper.kt Established the ExpressionFunctions interface and inheritor check for custom function resolution.
ActiveProjectHelper.kt Added a utility to retrieve the active project based on focus.
CommonPathParameterHelper.kt Introduced as a replacement for static constants, supporting path resolution improvements.
Comments suppressed due to low confidence (1)

src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/collector/StaticBuildFunctionCollector.kt:70

  • [nitpick] The filtering logic relies on bind.substringAfter('@') assuming that the bind string always contains an '@' character. Consider adding inline documentation or a safeguard to clarify this assumption.
it.name.startsWith(bind.substringAfter("@"))

@xterao xterao added this to the 0.8.0 Release milestone May 16, 2025
@xterao xterao linked an issue May 16, 2025 that may be closed by this pull request
@xterao xterao force-pushed the feature/support-custom-functions branch from 7799579 to a9c1048 Compare May 19, 2025 05:14
@xterao xterao requested a review from Copilot May 19, 2025 06:23
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

Enable support for user-registered custom SQL functions across completion, inspection, and reference resolution, and migrate the SQL formatting flag to a project-level setting.

  • Add InspectionFunctionCallVisitorProcessor to validate calls against custom and built-in functions.
  • Introduce StaticBuildFunctionCollector for completion of custom and built-in functions.
  • Rename and centralize SQL formatting settings under DomaToolsFormatEnableSettings.
  • Update imports to use CommonPathParameterHelper and adjust README to document new feature.

Reviewed Changes

Copilot reviewed 50 out of 50 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/main/kotlin/.../InspectionFunctionCallVisitorProcessor.kt New visitor to inspect custom function calls
src/main/kotlin/.../formatter/SqlPostProcessor.kt Switched to project-level DomaToolsFormatEnableSettings
src/main/kotlin/.../formatter/SqlFormattingModelBuilder.kt Updated format‐enable check via ActiveProjectHelper
src/main/kotlin/.../formatter/SqlFormatPreProcessor.kt Added project parameter to enable check, removed old settings
src/main/kotlin/.../common/sql/directive/collector/StaticBuildFunctionCollector.kt New collector that indexes custom and built-in functions
src/main/kotlin/.../common/sql/validator/result/ValidationInvalidFunctionCallResult.kt New result class for invalid function call inspection
src/main/kotlin/.../common/helper/CommonPathParameterHelper.kt Introduce centralized path parameters helper
README.md Documented new custom-function features and setting migration
Comments suppressed due to low confidence (1)

src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/collector/StaticBuildFunctionCollector.kt:34

  • This new logic for collecting custom and built-in functions lacks unit tests; add tests to cover scenarios with registered custom classes and the fallback to built-in functions.
public override fun collect(): List<LookupElement>? {

@xterao xterao requested a review from Copilot May 19, 2025 06:46
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

Adds support for user-registered custom SQL functions in completion, inspection, and reference resolution, and moves the SQL formatting flag to project-level settings.

  • Enable inspection of function calls against custom-registered classes, with fallback to built-in functions
  • Offer custom functions in SQL completion and resolve their definitions for “Go To Declaration”
  • Refactor SQL formatter to use a project-level enable flag via new DomaToolsFormatEnableSettings

Reviewed Changes

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

Show a summary per file
File Description
src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/processor/InspectionFunctionCallVisitorProcessor.kt New visitor processor checks calls against custom and built-in functions
src/main/kotlin/org/domaframework/doma/intellij/formatter/SqlPostProcessor.kt Moved SQL format flag to project settings and extracted isEnableFormat
src/main/kotlin/org/domaframework/doma/intellij/formatter/SqlFormattingModelBuilder.kt Use ActiveProjectHelper to obtain project for formatting toggle
src/main/kotlin/org/domaframework/doma/intellij/formatter/SqlFormatPreProcessor.kt Updated isEnableFormat to accept Project and guard formatting
src/main/kotlin/org/domaframework/doma/intellij/extension/psi/PsiMethodExtension.kt Removed unused annotation helper
src/main/kotlin/org/domaframework/doma/intellij/extension/ProjectExtensions.kt Fallback to JavaPsiFacade when no project-scoped class is found
src/main/kotlin/org/domaframework/doma/intellij/extension/ModuleExtensions.kt Switched to CommonPathParameterHelper for META-INF path
src/main/kotlin/org/domaframework/doma/intellij/contributor/sql/provider/SqlParameterCompletionProvider.kt Drop unused Project and simplify directive handler instantiation
src/main/kotlin/org/domaframework/doma/intellij/common/sql/validator/result/ValidationInvalidFunctionCallResult.kt New result type to highlight invalid custom function calls
src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/collector/StaticBuildFunctionCollector.kt Rewritten collector to include custom functions with built-in fallback
src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/StaticDirectiveHandler.kt Updated handler to pass element.project instead of injected Project
src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/DirectiveCompletion.kt Removed unused Project constructor parameter
src/main/kotlin/org/domaframework/doma/intellij/common/psi/PsiDaoMethod.kt Switched to CommonPathParameterHelper for resource paths
src/main/kotlin/org/domaframework/doma/intellij/common/helper/ExpressionFunctionsHelper.kt New helper to locate and test against the ExpressionFunctions interface
src/main/kotlin/org/domaframework/doma/intellij/common/helper/ActiveProjectHelper.kt Utility to retrieve the active IDE project
src/main/kotlin/org/domaframework/doma/intellij/common/dao/DaoMethodUtil.kt Switched to CommonPathParameterHelper for resource constants
src/main/kotlin/org/domaframework/doma/intellij/common/JarFileSearch.kt Switched to CommonPathParameterHelper for META-INF path
src/main/kotlin/org/domaframework/doma/intellij/common/FileTypeCheck.kt Removed duplicate file-type check and switched to helper import
src/main/kotlin/org/domaframework/doma/intellij/common/CommonPathParameterHelper.kt New helper object for common path constants
README.md Documented custom-function inspection, completion, and reference features
Comments suppressed due to low confidence (3)

src/main/kotlin/org/domaframework/doma/intellij/formatter/SqlPostProcessor.kt:71

  • Missing import for Project. Add import com.intellij.openapi.project.Project above this function to ensure it compiles.
fun isEnableFormat(project: Project): Boolean {

src/main/kotlin/org/domaframework/doma/intellij/common/sql/validator/result/ValidationInvalidFunctionCallResult.kt:39

  • This local project shadows the method parameter project. Consider renaming one or removing the unused parameter to avoid confusion.
val project = identify.project

src/main/kotlin/org/domaframework/doma/intellij/common/helper/ExpressionFunctionsHelper.kt:25

  • [nitpick] Holding a mutable static expressionFunction can lead to stale or cross-project state. Consider returning the found class directly or scoping it per invocation.
var expressionFunction: PsiClass? = null

@xterao xterao force-pushed the feature/support-custom-functions branch from 34fcfe8 to a4a45a1 Compare May 19, 2025 06:55
@xterao xterao requested a review from Copilot May 19, 2025 06:56
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

Adds support for user-registered custom functions in SQL editing—completion, validation, and reference resolution—while cleaning up project parameter passing and centralizing utilities.

  • Remove explicit project parameters from ValidationResult subclasses and use identify.project
  • Implement dynamic collection of custom and built-in functions in StaticBuildFunctionCollector
  • Introduce ExpressionFunctionsHelper and ActiveProjectHelper; consolidate path constants and update README

Reviewed Changes

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

Show a summary per file
File Description
ValidationResult.kt & related Validation*Result.kt Removed unused project parameters and streamlined registration of problems
StaticBuildFunctionCollector.kt Refactored collection logic to load custom functions from settings and built-ins
ExpressionFunctionsHelper.kt New helper for locating and checking ExpressionFunctions implementations
ActiveProjectHelper.kt New helper for determining the currently active IDE project
CommonPathParameterHelper.kt & imports Consolidated path constants into a single helper object
README.md Updated documentation to describe new custom-function features

@xterao xterao force-pushed the feature/support-custom-functions branch from a4a45a1 to 1b6db0b Compare May 19, 2025 07:10
@xterao xterao merged commit 06e51b2 into main May 19, 2025
3 checks passed
@xterao xterao deleted the feature/support-custom-functions branch May 19, 2025 08:09
@xterao xterao linked an issue May 21, 2025 that may be closed by this pull request
@xterao xterao added the skip-changelog Fixes not included in the update log label May 21, 2025
@xterao xterao linked an issue May 26, 2025 that may be closed by this pull request
@xterao xterao removed the skip-changelog Fixes not included in the update log label May 27, 2025
@xterao xterao linked an issue May 27, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request feature

Projects

None yet

2 participants