interactive icon indicating copy to clipboard operation
interactive copied to clipboard

F# values displaying strangely in notebooks

Open bmitc opened this issue 3 years ago • 1 comments

Describe the bug

In general, I have found that F# is now displaying values strangely in VS Code. I feel that it didn't used to be this way, so maybe I missed a feature change or it's possible that this is a regression.

For example, see the following screenshot:

image

For the most part, I am now usually defining a helper function let print value = printfn "%A" value and piping any output into print to get reasonable and readable displays of values.

Please complete the following:

Which version of .NET Interactive are you using? (In a notebook, run the #!about magic command. ):

  • OS
    • [x] Windows 11
    • [ ] Windows 10
    • [ ] macOS
    • [ ] Linux (Please specify distro)
    • [ ] iOS
    • [ ] Android
  • Browser
    • [ ] Chrome
    • [ ] Edge
    • [ ] Firefox
    • [ ] Safari
  • Frontend
    • [ ] Jupyter Notebook
    • [ ] Jupyter Lab
    • [ ] nteract
    • [x] Visual Studio Code
    • [ ] Visual Studio Code Insiders
    • [ ] Visual Studio
    • [ ] Other (please specify)

Screenshots

See above. Also, here's version information:

image

bmitc avatar Sep 19 '22 07:09 bmitc

Just an FYI, rather than printfn "%A" you can change the default output to the FSI formatter using the trick from https://github.com/dotnet/interactive/issues/1282

Formatter.SetPreferredMimeTypeFor(typeof<obj>, "text/plain")
Formatter.Register(fun (x:obj) (writer: TextWriter) -> fprintfn writer "%120A" x )

A downside is that it will break any libraries with their own interactive printing, such as Plotly.NET, but you can fix those with for example

// Make plotly graphs work with interactive plaintext formatter
Formatter.SetPreferredMimeTypesFor(typeof<GenericChart.GenericChart>,"text/html")

nhirschey avatar Sep 21 '22 11:09 nhirschey