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

Polyglot VSCode thinks F# notebooks generated by FSharp.Formatting are C# notebooks #2685

Closed
nhirschey opened this issue Feb 3, 2023 · 5 comments · Fixed by #2692
Closed

Comments

@nhirschey
Copy link
Contributor

nhirschey commented Feb 3, 2023

Describe the bug

  1. This is probably the same issue as Empty .ipnyb files modified by .NET Interactive are saved as C#, regardless of content #2289, and it breaks all documentation notebooks previously created by F# Formatting.
  2. For new F# notebooks, I can do a PR to update the F# Formatting library to generate F# notebooks with the metadata that the Polyglot notebooks extension wants. What metadata should we add?

Details follow:

The F# Formatting Library generates .NET interactive notebooks. The VSCode extension previously recognized the code cells as F#, but now the polyglot extension converts them to C#. As far as I can tell it's necessary to manually go through every cell and change it to F# (not practical). This breaks all documentation notebooks previously created by F# Formatting.

For example, the extension now thinks the F# code in this notebook from the F# Data Library is C# code:

image

Regarding metadata ... A simple notebook generated by the F# formatting tool looks like this below in json and is what used to work with the old VSCode extension.

        {
            "cells": [
          {
           "cell_type": "code",
           "metadata": {},
            "execution_count": 1, "outputs": [],
           "source": ["let x = 100\n"]
          }
,
          {
           "cell_type": "code",
           "metadata": {},
            "execution_count": 2, "outputs": [],
           "source": ["let y = 100\n"]
          }],
            "metadata": {
            "kernelspec": {"display_name": ".NET (F#)", "language": "F#", "name": ".net-fsharp"},
            "langauge_info": {
        "file_extension": ".fs",
        "mimetype": "text/x-fsharp",
        "name": "C#",
        "pygments_lexer": "fsharp",
        "version": "4.5"
        }
        },
            "nbformat": 4,
            "nbformat_minor": 1
        }

From experimentation, it looks like if we change "metadata": {} in code cells to what I have here then the cells are recognized as being F# code. Is this correct, is there anything else that you suggest?

 "metadata": {
    "dotnet_interactive": {
     "language": "fsharp"
    },
    "polyglot_notebook": {
     "kernelName": "fsharp"
    }
   }

Please complete the following:

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

.NET Interactive
Version: 1.0.360602+9bf026dabac44a6256a65168fa93dcb7e2edcca4
Library version: 1.0.0-beta.22606.2+9bf026dabac44a6256a65168fa93dcb7e2edcca4
Build date: 2023-01-31T11:33:36.0115292Z

Screenshots

If applicable, add screenshots to help explain your problem.

@brettfo
Copy link
Member

brettfo commented Feb 6, 2023

@nhirschey adding the polyglot_notebook metadata is the "correct" way to enable this, and the dotnet_interactive key is a fallback for back-compat.

This situation, however, is interesting and something that should probably work. The fix on our end will likely be to use the notebook's kernelspec language if the cell metadata isn't present.

@jonsequitur
Copy link
Contributor

On a related note, we provide a library for reading a writing the file formats we understand: https://www.nuget.org/packages/Microsoft.DotNet.Interactive.Documents

You can use this library to read and write .ipynb and .dib files currently, and it will include the correct metadata.

@nhirschey
Copy link
Contributor Author

@brettfo, thank you for making this fix so quickly! That's a real help to the F# community. Additionally, I will update the FSharp.Formatting tool so that it adds polyglot_notebook metadata to code cells in notebooks going forward.

@jonsequitur thank you, I was not aware. I'll keep that in mind. One of the F# formatting library's todo's is to allow generating documentation from a notebook, and your notebook parser could help with that.

Thanks!

@brettfo
Copy link
Member

brettfo commented Feb 9, 2023

@nhirschey we published a new extension to our insiders channel, can you give it a shot to see if it fixes this issue? You'll need to install VS Code - Insiders and then install the extension like normal, it should automatically pick up the correct version, which should be 1.0.4108061.

@nhirschey
Copy link
Contributor Author

@brettfo yes I checked docs from a few repos and it's fixed in the insiders version of VS Code. Thank you!

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