Skip to content

Comments

Fix data mapping function detection to exclude regular and natural expression functions in data_mappings.bal#380

Closed
Copilot wants to merge 6 commits intomainfrom
copilot/fix-data-mapping-functions
Closed

Fix data mapping function detection to exclude regular and natural expression functions in data_mappings.bal#380
Copilot wants to merge 6 commits intomainfrom
copilot/fix-data-mapping-functions

Conversation

Copy link

Copilot AI commented Oct 13, 2025

Fix: Functions in data_mappings.bal incorrectly marked as data mapping functions

  • Understand the issue - Functions in data_mappings.bal are incorrectly marked as data mapping functions
  • Review the current implementation in FunctionSearchCommand.java line 207
  • Modify FunctionSearchCommand.java to check if the function is an expression-bodied function (not a natural expression function) before marking it as a data mapping function
  • Add dataMappingsDoc parameter to FunctionSearchCommand constructor
  • Update SearchCommand.from() to accept and pass dataMappingsDoc
  • Update FlowModelGeneratorService to pass dataMappingsDoc when creating search command
  • Add isDataMappingFunction helper method to CommonUtils
  • Create test case with custom functions in data_mappings.bal
  • Handle natural expression functions in data_mappings.bal (skip them entirely)
  • Add test for NP function in data_mappings.bal
  • Verify all cases are covered
  • Fix checkstyle line length error

Summary

Fixed the issue where all functions in data_mappings.bal were incorrectly marked as data mapping functions. The fix ensures that only expression-bodied functions (excluding natural expression functions) are marked as data mapping functions.

All Cases Covered:

  1. Expression-bodied functions in data_mappings.bal (like transform, mapPersonToEmployee) → isDataMappedFunction: true
  2. Regular functions with block body in data_mappings.bal (like customHelper) → isDataMappedFunction: false
  3. Isolated functions in data_mappings.bal (like validateAge) → isDataMappedFunction: false
  4. Natural expression functions in data_mappings.bal (like generateGreeting) → Skipped entirely (not shown in results)
  5. Natural expression functions in functions.bal → Skipped entirely (existing behavior maintained)

Changes Made:

  1. CommonUtils.java: Added isDataMappingFunction() helper method (fixed checkstyle line length)
  2. FunctionSearchCommand.java: Updated detection logic to use proper checks + skip NP functions from data_mappings.bal
  3. SearchCommand.java: Added overloaded from() method for backward compatibility
  4. FlowModelGeneratorService.java: Pass data_mappings.bal document to search command
  5. Test case: Created custom_func_proj with all function types including NP function
Original prompt

This section details on the original issue you should resolve

<issue_title>Functions created within data-mappings.bal are marked as data mapping functions</issue_title>
<issue_description>### Description

Data mapper supports creating mappings using custom functions and those functions are created within the data-mappings.bal file. However those functions are marked as "isDataMappedFunction": true, in the response of flowDesignService/search

Steps to Reproduce

Create a mpping with a custom function and try to add a new data mapper invocation. The custom functions will also apear as data mapping functions.

Version

v0.9.6

Environment Details (with versions)

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

@dulajdilshan The reason for this is - In the LS, we check only whether a particular function is in within the `data_mapping.bal`. Check this line: https://github.com/ballerina-platform/ballerina-language-server/blob/632c9f910db19905586c76c76e52421eb5d0c282/flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/search/FunctionSearchCommand.java#L207 Image

We need to fix this.

@madushajg @pasindufernando1 What if a pro-code user has defined functions directly inside data-mappings.bal? In that case, those functions shouldn’t appear as data mapping functions in the visualizer. @dulajdilshan > [@pasindufernando1](https://github.com/pasindufernando1) What if a pro-code user has defined functions directly inside data-mappings.bal? In that case, those functions shouldn’t appear as data mapping functions in the visualizer.

@pasindufernando1 We can fix this with the solution I posted above.</comment_new>
<comment_new>@dulajdilshan
@pasindufernando1 Why can't we use a similar approach we used in natural-expression here?

https://github.com/ballerina-platform/ballerina-language-server/blob/85eda1f19d8cc963cdffac60c5d1926a51b1b11a/langserver-core/src/main/java/org/ballerinalang/langserver/version/BallerinaU130CompilerApi.java ?

And done in here too https://github.com/dulajdilshan/ballerina-language-server/blob/2401e46936de947e276d1c50ea0cdce42e94ee07/architecture-model-generator/modules/architecture-model-generator-core/src/main/java/io/ballerina/artifactsgenerator/ModuleNodeTransformer.java#L91

Fixes wso2/product-ballerina-integrator#26


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link

CLAassistant commented Oct 13, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ dulajdilshan
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI and others added 2 commits October 13, 2025 05:27
Co-authored-by: dulajdilshan <25485997+dulajdilshan@users.noreply.github.com>
Co-authored-by: dulajdilshan <25485997+dulajdilshan@users.noreply.github.com>
@dulajdilshan
Copy link
Contributor

@copilot Have we covered all the cases in the issue?

Copilot AI changed the title [WIP] Fix incorrect marking of custom functions in data mappings Fix data mapping function detection to exclude regular functions in data_mappings.bal Oct 13, 2025
Copilot AI requested a review from dulajdilshan October 13, 2025 05:36
Copy link
Author

Copilot AI commented Oct 13, 2025

@copilot Have we covered all the cases in the issue?

Yes, all cases are now covered. The fix handles:

  1. Expression-bodied functions → marked as data mapping functions
  2. Regular functions with block bodies → NOT marked as data mapping
  3. Isolated functions → NOT marked as data mapping
  4. Natural expression (NP) functions → skipped entirely (not shown in results)

Added an additional check (commit f7ec891) to skip NP functions from data_mappings.bal, ensuring consistent behavior with NP functions in functions.bal. The test case now includes a natural expression function to validate this scenario.

Co-authored-by: dulajdilshan <25485997+dulajdilshan@users.noreply.github.com>
Copilot AI changed the title Fix data mapping function detection to exclude regular functions in data_mappings.bal Fix data mapping function detection to exclude regular and natural expression functions in data_mappings.bal Oct 13, 2025
Co-authored-by: dulajdilshan <25485997+dulajdilshan@users.noreply.github.com>
@dulajdilshan
Copy link
Contributor

Created #382, since it is not allowed to merge changes from authors without signed contributors license agreement.

@dulajdilshan dulajdilshan deleted the copilot/fix-data-mapping-functions branch October 13, 2025 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Functions created within data-mappings.bal are marked as data mapping functions

3 participants