fsprojects / fantomas

FSharp source code formatter
https://fsprojects.github.io/fantomas
Other
758 stars 189 forks source link

cannot determine if Expr AppSingleParenArg Fantomas.Core.SyntaxOak+ExprAppSingleParenArgNode is uppercase or lowercase #3086

Closed mattgallagher92 closed 1 month ago

mattgallagher92 commented 1 month ago

I reproduced the error using https://fsprojects.github.io/fantomas-tools/#/fantomas/preview, but got an error from GitHub about the URL being too long when using the create issue link at the bottom. Hence a manual bug report.

Fantomas is not able to parse some (very dynamic!) code in Feliz.AgGrid:

    static member inline onRangeSelectionChanged callback = agGridProp<'row>("onRangeSelectionChanged", fun x ->
            let selectedRange = x?api?getCellRanges()?at(0)
            let startRow = selectedRange?startRow?rowIndex
            let startColumn = selectedRange?columns?at(0)?colId
            let endRow = selectedRange?endRow?rowIndex
            let endColumn = selectedRange?columns?at(selectedRange?columns?length-1)?colId

            callback startRow startColumn endRow endColumn)

https://github.com/CompositionalIT/feliz-ag-grid/blob/3127eec7a815eb3abf8750b87ba48e8c9f6ed273/src/AgGrid.fs#L171-L178

This results in the following error from Fantomas (v6.3.4):

matt@matt-framework:~/dev-cit/cit/feliz-ag-grid$ dotnet fantomas --verbosity detailed .
[11:55:35 DBG] Processing ./src/AgGrid.fs
[11:55:35 DBG] Processing ./demo/src/Extensions.fs
[11:55:35 DBG] Processing ./demo/src/Main.fs
[11:55:35 DBG] Processing ./demo/src/Components.fs
[11:55:35 DBG] './demo/src/Main.fs' was unchanged
[11:55:35 DBG] './demo/src/Extensions.fs' was unchanged
[11:55:35 DBG] './demo/src/Components.fs' was unchanged

  Formatted │ 0 │ Ignored │ 0 │ Unchanged │ 3 │ Errored │ 1  

[11:55:35 ERR] Failed to format file: ./src/AgGrid.fs : System.Exception: cannot determine if Expr AppSingleParenArg Fantomas.Core.SyntaxOak+ExprAppSingleParenArgNode is uppercase or lowercase
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1439.Invoke(String message) in D:\a\_work\1\s\src\fsharp\FSharp.Core\printf.fs:line 1439
   at Fantomas.Core.CodePrinter.sepSpaceBeforeParenInFuncInvocation(Expr functionExpr, Expr argExpr, Context ctx) in /_//src/Fantomas.Core/CodePrinter.fs:line 2522
   at Fantomas.Core.CodePrinter.genExpr@1028-197.Invoke(Context ctx)
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.shortExpressionWithFallback(FSharpFunc`2 shortExpression, FSharpFunc`2 fallbackExpression, Int32 maxWidth, FSharpOption`1 startColumn, Context ctx) in /_//src/Fantomas.Core/Context.fs:line 616
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.shortExpressionWithFallback(FSharpFunc`2 shortExpression, FSharpFunc`2 fallbackExpression, Int32 maxWidth, FSharpOption`1 startColumn, Context ctx) in /_//src/Fantomas.Core/Context.fs:line 616
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.isMultilineItem(FSharpFunc`2 expr, Context ctx) in /_//src/Fantomas.Core/Context.fs:line 993
   at Fantomas.Core.Context.colWithNlnWhenItemIsMultiline(FSharpList`1 items, Context ctx) in /_//src/Fantomas.Core/Context.fs:line 1078
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.CodePrinter.genLambdaAux@1954-4.Invoke(Context ctx) in /_//src/Fantomas.Core/CodePrinter.fs:line 1973
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.col[T](FSharpFunc`2 f', IEnumerable`1 c, FSharpFunc`2 f, Context ctx) in /_//src/Fantomas.Core/Context.fs:line 463
   at Fantomas.Core.CodePrinter.shortExpression@1869-8.Invoke(Context ctx)
   at Fantomas.Core.Context.shortExpressionWithFallback(FSharpFunc`2 shortExpression, FSharpFunc`2 fallbackExpression, Int32 maxWidth, FSharpOption`1 startColumn, Context ctx) in /_//src/Fantomas.Core/Context.fs:line 616
   at Fantomas.Core.Context.atIndentLevel@403-6.Invoke(Context x)
   at Fantomas.Core.Context.atIndentLevel(Boolean alsoSetIndent, Int32 level, FSharpFunc`2 f, Context ctx) in /_//src/Fantomas.Core/Context.fs:line 404
   at Fantomas.Core.CodePrinter.genTupleExpr@1878-1.Invoke(Context ctx)
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.shortExpressionWithFallback(FSharpFunc`2 shortExpression, FSharpFunc`2 fallbackExpression, Int32 maxWidth, FSharpOption`1 startColumn, Context ctx) in /_//src/Fantomas.Core/Context.fs:line 616
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.isMultilineItem(FSharpFunc`2 expr, Context ctx) in /_//src/Fantomas.Core/Context.fs:line 993
   at Fantomas.Core.Context.loop@1048(ColMultilineItemsState acc, FSharpList`1 items) in /_//src/Fantomas.Core/Context.fs:line 1073
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.isMultilineItem(FSharpFunc`2 expr, Context ctx) in /_//src/Fantomas.Core/Context.fs:line 993
   at Fantomas.Core.Context.loop@1048(ColMultilineItemsState acc, FSharpList`1 items) in /_//src/Fantomas.Core/Context.fs:line 1073
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.col[T](FSharpFunc`2 f', IEnumerable`1 c, FSharpFunc`2 f, Context ctx) in /_//src/Fantomas.Core/Context.fs:line 463
   at Fantomas.Core.CodePrinter.genFile@4000-4.Invoke(Context ctx)
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.Context.op_PlusGreater(FSharpFunc`2 ctx, FSharpFunc`2 f, Context x) in /_//src/Fantomas.Core/Context.fs:line 430
   at Fantomas.Core.CodeFormatterImpl.formatAST(ParsedInput ast, FSharpOption`1 sourceText, FormatConfig config, FSharpOption`1 cursor) in /_//src/Fantomas.Core/CodeFormatterImpl.fs:line 74
   at Fantomas.Core.CodeFormatterImpl.formatDocument@89-3.Invoke(Unit unitVar) in /_//src/Fantomas.Core/CodeFormatterImpl.fs:line 89
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 446
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104
nojaf commented 1 month ago

Please create a smaller sample in the online tool when you are facing the URL too long problem:

https://fsprojects.github.io/fantomas-tools/#/fantomas/main?data=N4KABGBEDGD2AmBTSAuKAPA-AQwA4EtMBzRAFwGFEAbKgJWwDsSBnACgEodTWAGdgHQBO-BpAA04KMzKl8TZqjABtSRFAQNUACSkAnrmRpIc0uNUbIWgG7YqAV0PLzmnhM2bIASQZIGpAMr4AF7Ibu4QACzOYAC65gC%2BYWrRlnoGisZ%2BZuGWNvaOKuEQAIxJ7pAAstjoADJyiDWITKQAFtlFxQBMPNFxmonm6uU6%2Bo6QTfAA8gBmdQyI-npUoSnWtg6KhUWdZR4Aoj4zcytFUFTTkL0JZUMeI%2BlGAEawsFTtd3kbaFvhAMy7Fm80kEpAAYnJbAA5RAAdyo9Xe7lIggcV36N1WaTGz1eiIguXWBWikQB%2BP8uGw0EQACFENNYIJEAAFbCCbAAWzIiEEeI0yNR4T6GgGmluFnu2JebwBBPym2JYAArKSoOTKTS6QyGrAYdzoNhpN4rLB9bJYKIVfzEGjhRichKMjjpatPkTTgA2FWQNVU2n0xkAVVwBkE%2BsNDGNpvw5t5EGmtmkNogIo0YvxDqeUt5sq%2BTlOAHYvT6Nf7EOQqAbmORzcx%2BdBSAzY2B41RE4LroNMaNHVmZWs5d8FQAOIsU32axkVRD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