Fantomas scrambled up a huge script file
Unfortunately fantomas set up to run on save, scrambled a huge script file of mine. This has caused literally days of work loss.
Is there a way to recover from this?
Well, actually, I am quite distressed by all of this. This is causing me big problems!
Does your OS or editor keep intermediate copies or history? Undo in the editor?
3000 lines of work, you must have been taking snapshots??
Unfortunately, I set fantomas to format on save. And normally I do a lot of intermediate commits. Only, as bad luck has it, working on a recoding of my project putting everything in the huge script file, at almost the finish, the problem occurred. So, I am afraid, I have to do it all over.
P.S. Normally, you "save" to save your work. In this case it destroyed my work.
The least fantomas should do is check whether the formatted code is still syntactically correct. If it isn't syntactically correct do not format the code but leave it as it is. This could prevent the mess that happened to me.
A couple questions that need to be answered:
- does standalone fantomas (i.e. the fantomas dotnet tool) have the same issue
- if so, then yes this is a fantomas issue and needs to be solved there
- if not, then is the issue in this repo, inside the code that gets the fantomas response and issues edits to the editor? or is it inside the editor itself after the edit has been issued by this extension?
This applies the minimal changes to the edit buffer. You should be able to hit undo unless you closed the file. But the diffs are line diffs. It looks like expressions were repeated:
let bigRGen (n, d) =
let bigRGen (n, d) =
let bigRGen (n, d) =
let d = if d = 0 then 1 else d
let n' = abs (n) |> BigRational.FromInt
let d' = abs (d) |> BigRational.FromInt
n' / d'
I say expression, because it doesn't appear to be on a line-by-line basis
let maxInclMultipleOf =
calcMinOrMaxToMultiple true true
else
mult
...17 lines
let maxInclMultipleOf =
calcMinOrMaxToMultiple true true
else
I tried to undo, but that didn't result in a recovery. I did this before giving up and closing the file.
@nojaf Do we check after formatting if the CodeFormatter produced a valid output?
I don't think so for Fantomas.Client, we do this for the command line tool though.