interactive icon indicating copy to clipboard operation
interactive copied to clipboard

Native Notebooks - Language set not maintained

Open claudiaregio opened this issue 4 years ago • 9 comments

Try opening notebook attached with the .NET interactive extension. The language for both cells is set to C# (Not C# .NET Interactive and F# .NET Interactive) .NETtest.zip

image

claudiaregio avatar Apr 27 '21 19:04 claudiaregio

@jonsequitur could this be a dupe of https://github.com/dotnet/interactive/issues/1038?

claudiaregio avatar Apr 28 '21 00:04 claudiaregio

@claudiaregio The symptom is the same but the cause is different. We do preserve the cell metadata now.

jonsequitur avatar Apr 28 '21 01:04 jonsequitur

Getting it here too: the v1.0.2227031 update did this to multiple notebooks, if I set the cells to the right type it fixes the problem - it seems to be failing to read types correctly from ipynbs created with earlier versions, but saves OK but I can't see what is changing in the underlying JSON.

jhoneill avatar Apr 28 '21 13:04 jhoneill

Is this also broken for you in VS Code non-Insiders?

jonsequitur avatar Apr 28 '21 15:04 jonsequitur

I've got quite the matrix here - one machine has the anaconda / Jupyter combo and one doesn't, and both machines have insiders and stable VS Code.
I'm on the no-Python machine at moment, and with code stable + plugin v1.0.2227030 #!about reporting

Version: 1.0.222703+320f05fcad9ac2e5360e649acf2cb49e56e731c8
Build date: 2021-04-28T11:39:58.1641221Z

Some of my notebooks were happy; others open and look like this
image

The "Happy" ones show C# initially and quickly change to the right cell type. (Some which were happy were triggered to remain on C# by using .Net interactive: Open notebook once on an "unhappy" one and then did this however they were opened, but they were happy again if I closed and re-opened code. This makes it difficult to know if the problem is the state VS code is in or something in the IPYNB file).

If I choose the .net interactive kernel with an "unhappy" one ...
image

  • it's the only choice - the cells change from C# to C# (.Net Interactive) things remain good if the file is saved and re-opened. It crossed my mind that the open process could select the kernel when there is only one, but there is no guarantee it would be right, so better not to!

image

Rolling back the ipynb causes things to go back to C# so it is a change in the file which is fixing it. I can't isolate that change but it looks like recognizing the kernel fails for some files and all their cells remain as C#. Others open as C# and after a moment become the correct cell types (presumably when the kernel is set)

re: Jupyter Server: local on the status bar: I don't get .net Interactive on View: Reopen notebook with or right-click file , open with image

Is this an intentional change - it works fine, it just looks like some work has been discarded.

jhoneill avatar Apr 28 '21 19:04 jhoneill

Additional My notebooks are in GIT so after getting everything working on the Python-less machine I've moved the Pythonated one. In the comment above select notebook kernal could only see the .Net Interactive kernel. This machine also sees all the kernels know to Jupyter server if I start it from anaconda.

image

A work book which was happy on the other machine goes to all C# cells here. But after selecting .net interactive from the list above it changes from c# to c# (.net interactive) image

From here, behaviour diverges from the other machine. If I save and reload, the selected kernel goes back to C#, and the cells label themselves as C# and the version reported by #!about changes from matching the Code extension to the stable version of .NET Interactive currently bound to Jupyter. image

image

If I set the kernel to the Jupyter-Style Net (PowerShell) then anything I set the cell to works as PowerShell - below I have set XML but C# would work image And when I save and re-open all the cells become PowerShell (Jupyter style). Now if I change the Kernel to .Net Interactive, close and reload instead of rolling back to C#, the cells become PowerShell. This defaulting-to-the-last-kernel behavior is very similar to #1315 except that it applies to the non-insiders build, and I don't get a prompt to change controller / kernel on opening.

jhoneill avatar Apr 29 '21 19:04 jhoneill

This may now be fixed in VSCode insiders as part of https://github.com/microsoft/vscode/issues/140673, although hopefully it's not causing a different issue by conflicting with the current metadata:

   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "vscode": {
     "languageId": "dotnet-interactive.csharp"
    }
   },

amunger avatar Mar 16 '22 15:03 amunger

This is currently still an issue with the latest stable releases. However, I noticed that if I open it the first time, I see C# both times. If I try one or two more times, then I see C# and F# in the language picker

claudiaregio avatar Jun 23 '22 20:06 claudiaregio

The behavior we're seeing currently is that the language settings are maintained but the file is opening by default using the Jupyter kernel, which doesn't have these languages registered. Switching to the .NET Interactive extension resolves the correct languages, so it appears the cell-specific language metadata was preserved correctly, but on first open for a given file, the wrong extension is handling the .ipynb.

jonsequitur avatar Jun 23 '22 23:06 jonsequitur