Fable's JsInterop ? dynamic access operator causes formatting error
Issue created from fantomas-online
Code
Jest.expect(json)?oMatchSnapshot ()
Error
System.Exception: cannot determine if Expr AppLongIdentAndSingleParenArg
Fantomas.Core.SyntaxOak+ExprAppLongIdentAndSingleParenArgNode is uppercase or lowercase
at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1448.Invoke(String message)
at Fantomas.Core.CodePrinter.sepSpaceBeforeParenInFuncInvocation(Expr functionExpr, Expr argExpr, Context ctx) in /_//src/Fantomas.Core/CodePrinter.fs:line 2549
at [email protected](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.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 [email protected](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 [email protected](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.Core\async.fs:line 508
at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 112
Problem description
When using the ? operator on the result of a tupled function call, a parse error is hit. A workaround is to call the first function without parens: (Jest.expect json)?oMatchSnapshot ()
Extra information
- [ ] The formatted result breaks my code.
- [ ] The formatted result gives compiler warnings.
- [x] 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 11/04/2024
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.
Hello,
Thanks for reporting this problem!
You would need to extend https://github.com/fsprojects/fantomas/blob/b7dca797317471654fc693ed5a056cfb90bd73d4/src/Fantomas.Core/CodePrinter.fs#L44-L63
with Expr.AppLongIdentAndSingleParenArg where you want to check the FunctionName I think.
Would you be interested in sending a PR for this?