-
-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fantomas is unable to format valid F# (.net 6.0) program #1969
Comments
Hello Karol, thank you for reporting this issue. The short version, without a lot of context, is that Fantomas will format your code snippet twice (once with If you format the code only using the try
try
()
#if FOO
()
#endif
with
| _ -> ()
#endif
with
| _ -> () That second Are you interested in submitting a fix for this? |
It would be cool if I could fix that bug! :) But I'm not sure If I'll be able to, since it's a totally new source base for me and in some places, it's quite complicated. But I want to try. It would be a great opportunity to learn something new! I started looking into that bug and I found a couple of questions about fantomas source code and design (I found one case in which I cannot fully understand why AST was generated in such a way). I'm not sure if this thread is the right place for asking for help/discussion? Or is there some separate 'dev' channel or some other way where I can ask questions? EDIT: |
Wonderful, I really recommend the YouTube series and feel free to poke me on our gitter channel. |
One other thing I believe is relevant here is: fantomas/src/Fantomas/CodePrinter.fs Line 975 in 8d864c3
used in fantomas/src/Fantomas/CodePrinter.fs Lines 2026 to 2038 in 8d864c3
A better range would be from the end of the And as the problem is a trivia one, you can replace the try
try
()
// #if FOO
()
// #endif
with
| _ -> ()
with
| _ -> () A similar thing was done in https://github.com/fsprojects/fantomas/pull/1914/files. I hope this helps. |
Thank you! That helps a lot! Yes, something weird is happening with trivia (comments in that case) in combination with nested
But what is surprising me the most is why on typed AST we get For now, I don't have an answer for that but definitely, I'll investigate it. |
Hmm, I don't really know what is happening there. Fantomas does not use the Typed AST, so who knows. |
In the future, I actually envision adding the range of the with keyword to the untyped tree. |
Hi.
I ran into some issue while formatting one of my programs. Below are details:
Issue created from fantomas-online
Code
Error
Problem description
Fantomas is unable to format valid F# (.net 6.0) program. I was able to reduce the case to the pasted code. I tried to reduce it even more but I was not able to find smaller code.
Extra information
The used program compile just fine with F# compiler so I think the issue is in Fantomas tool.
Options
Fantomas 4.6 branch at 11/10/2021 15:04:59 - 8d864c3
Default Fantomas configuration
The text was updated successfully, but these errors were encountered: