microsoft / microsoft/Power-Fx

Public PrettyPrint (similar to TexlParser.Format)

Open
#2,582 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
3.4k
Forks
358
Avg merge
10h 34m
Merged PRs (30d)
3

Description

I'm looking at integrating PowerFx.Core into my application so that I can format code snippets to a more user-friendly format.

I can see that https://github.com/microsoft/Power-Fx/blob/main/src/tests/Microsoft.PowerFx.Core.Tests.Shared/FormatterTests.cs#L259 has got a test that covers what I would need, however the TexlParser.Format (https://github.com/microsoft/Power-Fx/blob/main/src/libraries/Microsoft.PowerFx.Core/Parser/TexlParser.cs#L1964) function is internal only.

I also saw that TexlNode.ToString() prettifies the output, but not in the same way (https://github.com/microsoft/Power-Fx/blob/main/src/libraries/Microsoft.PowerFx.Core/Syntax/Nodes/TexlNode.cs#L278)

For example, using the following code snippet
If(CountRows(Filter('Time Off Requests','Created On'>=Today()&&Owner=LookUp(Users_1,'User Name'=User().Email,User)))>0,Navigate([@'Attendance Already Submitted'],ScreenTransition.Cover),NewForm(AttendanceForm))

Running the above through TexlNode.ToString() (via Engine.Parse("...").Root.ToString()) gives me
If(CountRows(Filter('Time Off Requests', 'Created On' >= Today() && Owner = LookUp(Users_1, 'User Name' = User().Email, User))) > 0, Navigate([@'Attendance Already Submitted'], ScreenTransition.Cover), NewForm(AttendanceForm))
(so some spacing has been added)

However, TexlParser.Format would return

If(
    CountRows(
        Filter(
            'Time Off Requests',
            'Created On' >= Today() && Owner = LookUp(
                Users_1,
                'User Name' = User().Email,
                User
            )
        )
    ) > 0,
    Navigate(
        [@'Attendance Already Submitted'],
        ScreenTransition.Cover
    ),
    NewForm(AttendanceForm)
)

Is there a possibility to get a public PrettyPrint function somewhere (TexlNode.PrettyPrint(), for example)?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with FormatterTests.cs around the referenced test, then read the internal TexlParser.Format method in Parser/TexlParser.cs and compare it with TexlNode.ToString() in Syntax/Nodes/TexlNode.cs. Check how Engine.Parse exposes the syntax tree. Done means a public formatting entry point produces the multiline pretty-printed form demonstrated in the issue, with test coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.