Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upadd command for new blank notebook #739
Merged
Conversation
8efa118
into
dotnet:main
8 checks passed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
brettfo commentedSep 1, 2020
The new command's display name is ".NET Interactive: Create new blank notebook" for two reasons:
I've added a keybinding of
Ctrl+Alt+Shift+Nto invoke this. It's extremely verbose, but I don't want to steal any existing keybinding, and unfortunately that means we can't use the chordCtrl+N, Dbecause that causes the defaultCtrl+Nto be unbound because it's waiting for a chord to continue, and that's bad. An alternative is to not have a default keybinding and let users add their own that simply invokes the commanddotnet-interactive.newNotebook. I'm open to either approach.As for changes to code, there were really only 3 of note:
To create a new untitled notebook, I avoided calling
workbench.action.files.newUntitledFile { viewType: 'dotnet-interactive' }because that creates a new notebook with the nameUntitled-1(note, no file extension) and when the user hitsCtrl+S, the save dialog defaults to the.txtextension, and that can cause a whole bunch of problems because the file format is chosen depending on the extension, and if the user chooses.txt(or.my-notebook, etc.) we have no idea how to serialize the notebook. Instead, I manually create a URI with the.dibfile extension pre-applied. This means when the user finally saves their notebook, it'll have the correct extension. It's still possible for them to manually override this, but that's on them; if they're mangling the file extensions we can't help them. To enable multiple unsaved notebooks, I look through the existing notebooks until I can find a numeric suffix that's unused, e.g.,Untitled-9.dib.Add the method
ClientMapper.reassociateClient. This is necessary because the notebook's runtime is associated with the notebook's URI. In normal scenarios, this will be something likeC:\Users\brettfo\Desktop\my-notebook.dib. In the case of a new unsaved notebook, the URI isUntitled-1.dib. Initially this is fine, but as soon as the user saves the notebook, the URI will suddenly be a file path like above and since we don't want them to loose their current runtime values and leave around a stale kernel, the reassociate method does exactly that: reassociates the kernel process with the new URI.VS Code will call
openNotebookwhen creating a new notebook viewer, but if it's an unsaved notebook created through the new command, nothing exists on disk. The fix for this was simple; if it's a new unsaved file, short-circuit everything and create an empty notebook.