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 < 5.0 breaks nested lists #46

Open
mbacarella opened this issue Feb 18, 2023 · 16 comments
Open

Fantomas < 5.0 breaks nested lists #46

mbacarella opened this issue Feb 18, 2023 · 16 comments

Comments

@mbacarella
Copy link

mbacarella commented Feb 18, 2023

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

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

@majocha
Copy link

majocha commented Feb 19, 2023

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.

@mbacarella
Copy link
Author

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

@majocha
Copy link

majocha commented Feb 19, 2023

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

@majocha
Copy link

majocha commented Feb 19, 2023

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

@mbacarella
Copy link
Author

mbacarella commented Feb 20, 2023

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.

@nojaf
Copy link
Contributor

nojaf commented Feb 21, 2023

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?

@mbacarella
Copy link
Author

mbacarella commented Feb 21, 2023

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.

@nojaf
Copy link
Contributor

nojaf commented Feb 21, 2023

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?

@mbacarella
Copy link
Author

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.

@nojaf
Copy link
Contributor

nojaf commented Feb 21, 2023

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

@mbacarella
Copy link
Author

Yup.

Running from CLI

minimal_good

Running from VS2022

Before format

minimal_bad_before

After format

minimal_bad_after

🤔

@nojaf
Copy link
Contributor

nojaf commented Feb 22, 2023

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.

@mbacarella
Copy link
Author

mbacarella commented Feb 22, 2023

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

Thank you, btw.

@nojaf
Copy link
Contributor

nojaf commented Feb 22, 2023

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?

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

3 participants