Skip to content
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 scrambled up a huge script file #34

Open
halcwb opened this issue Jul 18, 2022 · 8 comments
Open

Fantomas scrambled up a huge script file #34

halcwb opened this issue Jul 18, 2022 · 8 comments

Comments

@halcwb
Copy link

halcwb commented Jul 18, 2022

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!

@dsyme
Copy link

dsyme commented Jul 18, 2022

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

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

@halcwb
Copy link
Author

halcwb commented Jul 18, 2022

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
Copy link
Author

halcwb commented Jul 18, 2022

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.

@baronfel
Copy link

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?

@deviousasti
Copy link
Member

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

@halcwb
Copy link
Author

halcwb commented Jul 18, 2022

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

@deviousasti
Copy link
Member

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

@nojaf
Copy link
Contributor

nojaf commented Dec 7, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants