ballerina-lang icon indicating copy to clipboard operation
ballerina-lang copied to clipboard

[Improvement]: Improve code modifier task to run syntax analysis task within itself

Open TharmiganK opened this issue 1 year ago • 1 comments
trafficstars

Description

Need to know, whether we can improve the code modifier tasks to address the issue described below

Describe your problem(s)

We would like to have two code modifier tasks within the code modifier:

  • ModifierTaskA
  • ModifierTaskB

Both of these modifiers are modifying a same parent node(for example: ServiceDeclarationNode)

For both of these modifiers, we need to run two syntax node analysis tasks to obtain two context maps which has the information for the code modifications:

  • AnalysisTaskA for ModifierTaskA
  • AnalysisTaskB for ModifierTaskB

The context information should be stored using a key which should be unique to the parent node we are modifying. Currently we use the hash code of the parent symbol.

Since the syntax node analysis tasks are running independent of the code modifier tasks, the context map is generated with the reference to the unmodified parent node. But when we run ModifierTaskB after ModifierTaskA, due to the modification done by ModifierTaskA the hash code is changed. Hence the ModifierTaskB is failing.

Describe your solution(s)

What we expect here is a dependency between code modifier task and code analysis task. I had a offline discussion with @gayaldassanayake and he said the syntax analysis tasks are running during a single syntax tree traversal. So if we need to have a dependency then we need to traverse the syntax tree again.

I wanted to know whether there is a better way to achieve this. Will a code modifier task for syntax node resolve this issue (in this case, we do not need to have the context map?

Related area

-> Other Area

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

TharmiganK avatar Jun 26 '24 06:06 TharmiganK