jonsequitur / dotnet-repl

A polyglot REPL built on .NET Interactive
MIT License
713 stars 35 forks source link

Repl --run Output Notebook Crashes VS Code C# Language Server #88

Open andy-merrick opened 1 year ago

andy-merrick commented 1 year ago

Issue Type: Bug

Description: Using --run with inputs causes the ipynb output file to crash the C# Language Server in VS Code when opening with Polyglot Notebooks v1.0.4403010 resulting in the notebook's Output cells being cleared. Possible fix below.

Command

dotnet-repl --run input.ipynb --exit-after-run --input id=1 --output-path output.ipynb

Repro Files

VS Code C# Terminal Output Error

[LanguageServerHost]System.InvalidOperationException: didOpen received for vscode-notebook-cell:/c:/Users/xxxxxxxxxxx/repos/polyglot/playground/dotnet-repl-error/dotnet-repl-output.ipynb#W1sZmlsZQ== which is already open. - line 106
   at Roslyn.Utilities.Contract.Fail(String message, Int32 lineNumber) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/Contract.cs:line 154
...
...

Cause

dotnet-repl writes the following json key into the output file:

"language_info": {
   "file_extension": ".cs",
   "mimetype": "text/x-csharp",
   "name": "C#",
   "pygments_lexer": "csharp",
   "version": "10.0"
},

Fix

Replacing this key with how VS Code writes it results in the dotnet-repl file successfully loading in VS Code:

"language_info": {
    "name": "polyglot-notebook"
},
jonsequitur commented 11 months ago

This sounds like a bug in the language server. The language_info node you pasted under Cause is the more correct one, per the .ipynb spec.

Do you know which extension is running this language server? (It's not Polyglot Notebooks.)