fantomas-for-vs icon indicating copy to clipboard operation
fantomas-for-vs copied to clipboard

Fantomas scrambled up a huge script file

Open halcwb opened this issue 3 years ago • 8 comments

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!

halcwb avatar Jul 18 '22 18:07 halcwb

Does your OS or editor keep intermediate copies or history? Undo in the editor?

3000 lines of work, you must have been taking snapshots??

dsyme avatar Jul 18 '22 18:07 dsyme

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.

halcwb avatar Jul 18 '22 18:07 halcwb

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.

halcwb avatar Jul 18 '22 18:07 halcwb

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?

baronfel avatar Jul 18 '22 18:07 baronfel

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

deviousasti avatar Jul 18 '22 18:07 deviousasti

I tried to undo, but that didn't result in a recovery. I did this before giving up and closing the file.

halcwb avatar Jul 18 '22 19:07 halcwb

@nojaf Do we check after formatting if the CodeFormatter produced a valid output?

deviousasti avatar Dec 07 '22 18:12 deviousasti

I don't think so for Fantomas.Client, we do this for the command line tool though.

nojaf avatar Dec 07 '22 18:12 nojaf