-
-
Notifications
You must be signed in to change notification settings - Fork 190
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
Idempotency problem when no space between getter and parameter #2291
Comments
Hello Florian, thanks for the prompt reply! :) I have unfortunately no fix for this problem. I'm currently working on a code generating project and I thought I was missing important part in my generated AST, and came to the conclusion after some comparative tests that Ranges are involved and would be necessary (not only dummy range0) to generate the appropriate code. After 2-3 days fighting this problem, I finally thought about a simple workaround, and blame myself under a huge pile of rocks of shame for not having thought about it earlier : parenthesis around the list! doh! Once I have finished with my code generation project, I might be able to push some improvement on the FsAst project though, but I have to figure out first if my workplace would allow it. |
One thing comes to mind here: fantomas/src/Fantomas.Core/SourceParser.fs Lines 1673 to 1685 in 5e92752
Where I'm wondering what fantomas/src/Fantomas.Core/RangeHelpers.fs Lines 29 to 32 in 5e92752
would return if both ranges are range0. Maybe faking one of the ranges, so that it is further away might resolve your problem. |
Yep, it crossed my mind to fake a +1 range just to see if it could work. But I thought it might been more contrived than this, in fact I was a bit surprised and discouraged at first to realize that ranges could be an important part of the AST tree, but when you think about it 2 seconds, I guess we could say that F# code have part of its semantic based on spaces, and relying on ranges might be unavoidable. But yes, in deed, thanks for the code excerpt, it was on my TODO list eventually to look at Fantomas's interns, and I agree, it might do the trick! :) |
Yes, a part of me also wished that we had a separate When it comes to code generation in general, you really need to follow as closely as possible what the parser produces. That is the tree that Fantomas can format, any deviation might not end well. |
Hello nojaf,
Yup, that did the trick, as you expected with a simple range of +1 : let range0 = Range.range0
let pos1 = Position.mkPos 0 1
let range1 = Range.mkRange range0.FileName pos1 pos1 Thanks! |
Alright, I'll close this issue as there are many duplicates of this one already. |
Issue created from fantomas-online
Formatted code
Reformatted code
Problem description
Fantomas was not able to produce the same code after reformatting the result.
Extra information
I stumble upon this problem when trying to generate code with FsAst, I simplified the code to show the problem.
Now I don't know if Visual Studio is too permissive, but it accepts when the code is specified without the space :
"this.bar().get[idx1; idx2]"
after Fantomas reformat, the list is split in two lines without the appropriate indentation, and it seems the first parameter is inferred as a ('a -> int) type...
Options
Fantomas master branch at 2022-05-30T18:11:41Z - 5e92752
Default Fantomas configuration
Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?
The text was updated successfully, but these errors were encountered: