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

Fantomas < 5.0 breaks nested lists

Open mbacarella opened this issue 2 years ago • 16 comments

On latest F# Formatter extension for VS2022, formatting this

let webApp =
    choose
        [ GET
          >=> choose [
              route "/" >=> indexHandler "world"
              routef "/hello/%s" indexHandler ]
          setStatusCode 404 >=> text "Not Found" ]

becomes this

let webApp =
    choose
        [ GET
          >=> choose [ route "/" >=> indexHandler "world"; routef "/hello/%s" indexHandler ]

note the setStatusCode ... item and closing ] is dropped.

This appears to be fixed by 5.0

mbacarella avatar Feb 18 '23 16:02 mbacarella

To be clear, I mean this is fixed by upstream fantomas but fantomas-for-vs still ships 4.5.1.

mbacarella avatar Feb 19 '23 15:02 mbacarella

To be clear, I mean this is fixed by upstream fantomas but fantomas-for-vs still ships 4.5.1.

I think you can upgrade Fantomas tool and the extension will pick it up.

majocha avatar Feb 19 '23 18:02 majocha

Hmm. I updated to 5.2.1 locally but it doesn't seem to get picked up by the VS2022 extension. :/

mbacarella avatar Feb 19 '23 19:02 mbacarella

Hmm... I would check you have the latest extension version. I think it doesn't get autoupdates.

majocha avatar Feb 19 '23 20:02 majocha

You can see the detected version if you induce the formatting to fail, (for example format selection on a empty line) image

majocha avatar Feb 19 '23 20:02 majocha

I actually can't induce my version to fail on a blank line. It never shows an error message. F# Formatting is not even available in the dropdown.

I did notice that when I tried to update using dotnet commands in my project (the giraffe example) it complained that fantomas 5.2.1 can't be installed with net5.0, it requires net6.0. Then I changed the framework to net6.0 and rebuilt and it complains again that it can't work with net6.0, and that it needs net6.0 (😕 )

Sorry, this is all pretty new stuff to me coming from Linux-land.

mbacarella avatar Feb 20 '23 21:02 mbacarella

Hello,

There might be some confusion between the framework and SDK versions. What do you get when you run dotnet --version? And do you have a global.json file?

nojaf avatar Feb 21 '23 07:02 nojaf

dotnet --version yields 7.0.200.

Which is interesting because NET7.0 is not available as an option in the VS2022 project settings dropdown.

My project does not have a global.json file.

mbacarella avatar Feb 21 '23 15:02 mbacarella

Ok, and to be clear you've installed Fantomas in your local folder via:

dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local fantomas --version 5.2.1

?

What does dotnet tool list give you?

nojaf avatar Feb 21 '23 15:02 nojaf

Just did those. Now shows this:

dotnet tool list
Package Id      Version      Commands      Manifest
------------------------------------------------------------------------------------------------------------
fantomas        5.2.1        fantomas      C:\Users\mbac3\projects\giraffe-example\.config\dotnet-tools.json

So, closing and restarting VS2022 and reformatting the code above still shows the buggy behavior.

Either this is still using an old version somehow (not sure how to diagnose further), or perhaps the problem above is not actually fixed, or there is a different issue.

Let me dig further.

mbacarella avatar Feb 21 '23 15:02 mbacarella

Ok, thanks. And to double-check, formatting the file using the command line does not give the problem right? dotnet fantomas ./folder/file.fs

nojaf avatar Feb 21 '23 16:02 nojaf

Yup.

Running from CLI

minimal_good

Running from VS2022

Before format

minimal_bad_before

After format

minimal_bad_after

🤔

mbacarella avatar Feb 21 '23 16:02 mbacarella

Hmm, weird. Could you create a script (f.ex script.fsx) (next to minimal.fs) with:

#r "nuget: Fantomas.Client, 0.8.0"

open System
open System.IO
open Fantomas.Client.Contracts
open Fantomas.Client.LSPFantomasService

let service : FantomasService = new LSPFantomasService()
// this path needs to be absolute and exist
let filePath = Path.Combine(__SOURCE_DIRECTORY__, "minimal.fs")

service.VersionAsync(filePath).Result
|> printfn "%A"

And execute that by running dotnet fsi script.fsx? This will run the same mechanic that is used inside the IDE plugin to detect your Fantomas version. I'm wondering what kind of response you will get.

nojaf avatar Feb 22 '23 07:02 nojaf

Sure.

cat .\script.fsx
#r "nuget: Fantomas.Client, 0.8.0"

open System
open System.IO
open Fantomas.Client.Contracts
open Fantomas.Client.LSPFantomasService

let service : FantomasService = new LSPFantomasService()
// this path needs to be absolute and exist
let filePath = Path.Combine(__SOURCE_DIRECTORY__, "minimal.fs")

service.VersionAsync(filePath).Result
|> printfn "%A"
dotnet fsi .\script.fsx
{ Code = 5
  FilePath = "C:\Users\mbac3\projects\giraffe-example\minimal.fs"
  Content = Some "5.2.1+9f769d838c9cb1a07dc0c6616871f5bebe91bb40"
  SelectedRange = None
  Cursor = None }

mbacarella avatar Feb 22 '23 13:02 mbacarella

Thank you, btw.

mbacarella avatar Feb 22 '23 13:02 mbacarella

Thanks, good to see that this part is working out. @deviousasti I believe this might be a problem in the plugin. Is there any way @mbacarella can get some logs of what happens in the plugin?

nojaf avatar Feb 22 '23 13:02 nojaf