dotnet / interactive

.NET Interactive combines the power of .NET with many other languages to create notebooks, REPLs, and embedded coding experiences. Share code, explore data, write, and learn across your apps in ways you couldn't before.
MIT License
2.92k stars 389 forks source link

Opening locally saved notebook will grey out all syntax, auto-detect can find languages not relevant to cell's kernel #3785

Open Octanoz opened 5 days ago

Octanoz commented 5 days ago

Describe the bug

I changed folders in VS Code and the notebook that I had active there is now showing all syntax greyed out. They are all C# kernel - C# script cells. Changing the language mode of the cell from Code to Auto Detect has mixed results with the auto-detect finding TypeScript and JavaScript where there is only C#. It seems odd that it's a possibility at all to find these language in a C# cell.

This behaviour is maintained even when creating a new cell and writing some C# code there.

There are no issues with running any of the cells, just the syntax highlighting is not working correctly.

This seems to be related to https://github.com/dotnet/interactive/issues/2683 but for a local copy as some people had mentioned there as well.

[Edit] I just got a pop-up about the active document not being a part of the workspace. Perhaps that's relevant so I'll add the screenshot. If the C# logs are of interest I can provide those as well.

Please complete the following:

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

Version: 1.0.556801+2d9726b514498cd84403a1d5d13da3161c99eab2 Library version: 1.0.0-beta.24568.1+2d9726b514498cd84403a1d5d13da3161c99eab2 Build date: 2024-11-19T21:23:41.1573504Z

Screenshots

Image

Using Auto Detect Image

Image

jonsequitur commented 2 days ago

I was unable to reproduce the missing syntax highlighting.

I changed folders in VS Code and the notebook that I had active there is now showing all syntax greyed out.

Can you describe exactly how you did this? I tried File > Open folder and the notebook was closed in the process.

The Auto-detect feature in notebooks is a VS Code feature that's unaware of the .NET Interactive subkernels. It will really only change the VS Code-controlled syntax highlighting, but the cell might then not be properly associated with a subkernel that can actually run it. This is a known issue without a clear solution.

The warning The active document is not part of the open workspace is coming from the C# extension which is unaware of notebooks.

Octanoz commented 1 hour ago

Can you describe exactly how you did this? I tried File > Open folder and the notebook was closed in the process.

Sure, my usual setup is all my code windows on the left and I usually have a markdown preview as well as a notebook open in the right editor. I tend to keep the notebooks in their own Notes folder as well.

And then it's really just the following:

  1. File > Close Folder
  2. Work on another solution from the recent list
  3. Close that one
  4. Open original solution from recent
  5. Code files load in on the left, notebook on the right, language servers connect, etc.
  6. Notebook cells stay greyed out unless Code is manually switched to Auto Detect

I just kept the C# output window open while changing to Auto Detect and it seems that particularly for the cells with an #!import someScript.csx command that I'm getting about a dozen warnings like this one:

2024-12-05 02:06:15.916 [info] [Warn - 2:06:15 AM] [LanguageServerHost] Text for vscode-notebook-cell:/c:/Project/Notes.dib#W0sZmlsZQ== did not match document text (DocumentId, #33e1a221-b6cf-43c3-914a-77dc62b517a7 - vscode-notebook-cell:/c:/Project/Notes.dib#W1sZmlsZQ==) in workspace's MiscellaneousFiles current solution

Switching all cells back to Code will trigger the active document not part of workspace popup.

jonsequitur commented 1 hour ago

I'm still not able to reproduce the grayed out syntax, assuming that I followed the steps correctly. Are you able to send a video?