fantomas icon indicating copy to clipboard operation
fantomas copied to clipboard

Query Expresion Formatting - Joins

Open Eddonomochi opened this issue 10 months ago • 1 comments

Issue created from fantomas-online

Code

let exampleCode
    (database : dbContext)
    (id : int)
    : Async<ReturnType list> =
    async {
        return!
            query {
                for persons in database1 do
                    join items in database2 
                        on ((persons.LongIdName, persons.LongerIdName) = (items.LongIdName, items.LongerIdName)) 
                        into result
                    for i in result.DefaultIfEmpty() do 
                        select (a.LongIdName, a.AccountId)
                        distinct
            }
            |> AsyncExtensions.ToArrayAsync
            |> Async.AwaitTask
    }

Result

let exampleCode (database: dbContext) (id: int) : Async<ReturnType list> =
    async {
        return!
            query {
                for persons in database1 do
                    join items in database2
                                      on
                                      ((persons.LongIdName, persons.LongerIdName) = (items.LongIdName,
                                                                                     items.LongerIdName))
                                      into
                                      result

                    for i in result.DefaultIfEmpty() do
                        select (a.LongIdName, a.AccountId)
                        distinct
            }
            |> AsyncExtensions.ToArrayAsync
            |> Async.AwaitTask
    }

Problem description

Hey there! I am just curious what is going on here. I have an example query expression here and the formatting seems off. The example code is how I'd expect the formatter to handle the query expression. Yet, it always seems to want to add the extra indentations before the on and any following related clauses. This issue happens both locally and when I try the online tool; both while trying with default configurations and trying different settings to see if it would fix it. Not sure if query formatting is something being looked into or not, but I thought I would bring it up here and see if it's something I am missing or a possible point of improvement.

Extra information

  • [ ] The formatted result breaks my code.
  • [ ] The formatted result gives compiler warnings.
  • [ ] I or my company would be willing to help fix this.
  • [ ] I would like a release if this problem is solved.

Options

Fantomas main branch at 2025-02-28T11:18:04Z - 6108fc41cf9ff49c9bd0f0059fc6b5fd2bc7974d

Default Fantomas configuration

Did you know that you can ignore files when formatting by using a .fantomasignore file? PS: It's unlikely that someone else will solve your specific issue, as it's something that you have a personal stake in.

Eddonomochi avatar Mar 03 '25 23:03 Eddonomochi

Hello, thank your for brining this up. I saw that atCurrentColumn in https://github.com/fsprojects/fantomas/blob/6108fc41cf9ff49c9bd0f0059fc6b5fd2bc7974d/src/Fantomas.Core/CodePrinter.fs#L699 is the cause of this. I'm not sure if this is historically of required to have valid code elsewhere.

Someone should investigate this to be sure. Maybe we can improve this a bit. Are you interested in taking a stab at this?

nojaf avatar Mar 04 '25 07:03 nojaf