ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.58k stars 737 forks source link

[New Feature]: `Extract to transformation function` code action for record to record mappings #42144

Closed YasithD closed 6 months ago

YasithD commented 7 months ago

Description

The feature mentioned in the $title is an useful feature for the Data Mapper. It is helpful when there are lengthy input and output records to be mapped.

Please refer to the following issue: https://github.com/wso2/ballerina-vscode/issues/527

Describe your problem(s)

No response

Describe your solution(s)

No response

Related area

-> Editor

Related issue(s) (optional)

https://github.com/wso2/ballerina-vscode/issues/527

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

LakshanWeerasinghe commented 7 months ago

Below are two possible user flows for suggesting the code action:

Using above two approaches we can identify source and target record types. Once identified, we can generate an arrow function for transformation. However, if we leaving the body empty would trigger a set of 'missing non-defaultable required record field' diagnostics. This is something we should avoid.

We can write an algorithm to populate the body with dummy mappings by default. However, for data mappings involving large record types, this could lead to erroneous mappings (functional errors).

@YasithD @madushajg Is the above mentioned user flow is that you intended? What is your thoughts on populating the body of the arrow function?

YasithD commented 7 months ago

Hi @LakshanWeerasinghe,

Using above two approaches we can identify source and target record types. Once identified, we can generate an arrow function for transformation.

For the approach can we have something similar to the currently available Extract to function code action?

https://github.com/ballerina-platform/ballerina-lang/assets/59837420/a36d3b29-896f-4e4f-b788-1bed4dec95f4

We can write an algorithm to populate the body with dummy mappings by default. However, for data mappings involving large record types, this could lead to erroneous mappings (functional errors).

For the default behaviour the default value mapping would work in the Data Mapper.

LakshanWeerasinghe commented 7 months ago

This will be the flow of actions.